Skip to content

Commit 587507d

Browse files
authored
Simplify JSON Schemas (#1998)
* Define `$schema` property in regular `properties` rather than in `patternProperties` * Simplify plugin schema with `default` instead of an enum + allowed free text * Simplify wheel-slot and capability schemas with `discriminator` and `oneOf` * Fix required and additional properties * Define `type` and `pattern` in the same object * Simplify `oneOf` * Replace some `$comment`s with `description`s → will be shown in VS Code
1 parent 82f5450 commit 587507d

18 files changed

Lines changed: 1179 additions & 1565 deletions

lib/ajv-validator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ajv = new Ajv({
99
verbose: true,
1010
strict: false,
1111
allErrors: true,
12+
discriminator: true,
1213
});
1314
addFormats(ajv);
1415
ajv.addKeyword(`version`);

lib/schema-properties.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
export const fixtureProperties = fixtureSchema.properties;
1212
export const physicalProperties = fixtureProperties.physical.properties;
1313

14-
export const capabilityTypes = Object.fromEntries(capabilitySchema.allOf.map(
15-
({ if: ifClause, then: thenClause }) => [ifClause.properties.type.const, thenClause],
14+
export const capabilityTypes = Object.fromEntries(capabilitySchema.oneOf.map(
15+
schema => [schema.properties.type.const, schema],
1616
));
1717

18-
export const wheelSlotTypes = Object.fromEntries(wheelSlotSchema.allOf.map(
19-
({ if: ifClause, then: thenClause }) => [ifClause.properties.type.const, thenClause],
18+
export const wheelSlotTypes = Object.fromEntries(wheelSlotSchema.oneOf.map(
19+
schema => [schema.properties.type.const, schema],
2020
));
2121

2222
export const manufacturerProperties = manufacturersSchema.additionalProperties.properties;
@@ -26,8 +26,7 @@ export const physicalBulbProperties = physicalProperties.bulb.properties;
2626
export const physicalLensProperties = physicalProperties.lens.properties;
2727
export const modeProperties = fixtureProperties.modes.items.properties;
2828
export const channelProperties = channelSchema.properties;
29-
export const capabilityProperties = capabilitySchema.properties;
30-
export const wheelSlotProperties = wheelSlotSchema.properties;
29+
export const capabilityDmxRange = capabilitySchema.definitions.dmxRange;
3130
export const schemaDefinitions = definitionsSchema;
3231
export const unitsSchema = definitionsSchema.units;
3332
export const entitiesSchema = definitionsSchema.entities;

plugins/dragonframe/exportTests/json-schema-conformity.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ async function getSchemas() {
7575
definitionsSchema.goboResourceString = { type: `object` };
7676

7777
// allow changed schema property
78-
fixtureSchema.patternProperties[`^\\$schema$`].const = `${SCHEMA_BASE_URL}fixture.json`;
79-
fixtureSchema.patternProperties[`^\\$schema$`].enum = undefined;
80-
manufacturersSchema.patternProperties[`^\\$schema$`].const = `${SCHEMA_BASE_URL}manufacturers.json`;
81-
manufacturersSchema.patternProperties[`^\\$schema$`].enum = undefined;
78+
fixtureSchema.properties.$schema = { const: `${SCHEMA_BASE_URL}fixture.json` };
79+
fixtureSchema.patternProperties = undefined;
80+
manufacturersSchema.properties = { $schema: { const: `${SCHEMA_BASE_URL}manufacturers.json` } };
81+
manufacturersSchema.patternProperties = undefined;
8282

8383
return schemasJson;
8484
}

plugins/millumin/exportTests/json-schema-conformity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ async function getSchemas() {
5959
fixtureSchema.properties.oflURL = true;
6060

6161
// allow changed schema property
62-
fixtureSchema.patternProperties[`^\\$schema$`].const = `${SCHEMA_BASE_URL}fixture.json`;
63-
fixtureSchema.patternProperties[`^\\$schema$`].enum = undefined;
62+
fixtureSchema.properties.$schema = { const: `${SCHEMA_BASE_URL}fixture.json` };
63+
fixtureSchema.patternProperties = undefined;
6464

6565
// allow new colors from schema version 11.1.0
6666
// see https://github.com/OpenLightingProject/open-fixture-library/pull/763

plugins/plugins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"ofl": {
6161
"name": "Open Fixture Library JSON",
62-
"exportPluginVersion": "12.2.1",
62+
"exportPluginVersion": "12.2.2",
6363
"exportTests": []
6464
},
6565
"op-z": {

0 commit comments

Comments
 (0)