Skip to content

Commit

Permalink
Simplify JSON Schemas (#1998)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
FloEdelmann committed Jun 20, 2021
1 parent 82f5450 commit 587507d
Show file tree
Hide file tree
Showing 18 changed files with 1,179 additions and 1,565 deletions.
1 change: 1 addition & 0 deletions lib/ajv-validator.js
Expand Up @@ -9,6 +9,7 @@ const ajv = new Ajv({
verbose: true,
strict: false,
allErrors: true,
discriminator: true,
});
addFormats(ajv);
ajv.addKeyword(`version`);
Expand Down
11 changes: 5 additions & 6 deletions lib/schema-properties.js
Expand Up @@ -11,12 +11,12 @@ import {
export const fixtureProperties = fixtureSchema.properties;
export const physicalProperties = fixtureProperties.physical.properties;

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

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

export const manufacturerProperties = manufacturersSchema.additionalProperties.properties;
Expand All @@ -26,8 +26,7 @@ export const physicalBulbProperties = physicalProperties.bulb.properties;
export const physicalLensProperties = physicalProperties.lens.properties;
export const modeProperties = fixtureProperties.modes.items.properties;
export const channelProperties = channelSchema.properties;
export const capabilityProperties = capabilitySchema.properties;
export const wheelSlotProperties = wheelSlotSchema.properties;
export const capabilityDmxRange = capabilitySchema.definitions.dmxRange;
export const schemaDefinitions = definitionsSchema;
export const unitsSchema = definitionsSchema.units;
export const entitiesSchema = definitionsSchema.entities;
8 changes: 4 additions & 4 deletions plugins/dragonframe/exportTests/json-schema-conformity.js
Expand Up @@ -75,10 +75,10 @@ async function getSchemas() {
definitionsSchema.goboResourceString = { type: `object` };

// allow changed schema property
fixtureSchema.patternProperties[`^\\$schema$`].const = `${SCHEMA_BASE_URL}fixture.json`;
fixtureSchema.patternProperties[`^\\$schema$`].enum = undefined;
manufacturersSchema.patternProperties[`^\\$schema$`].const = `${SCHEMA_BASE_URL}manufacturers.json`;
manufacturersSchema.patternProperties[`^\\$schema$`].enum = undefined;
fixtureSchema.properties.$schema = { const: `${SCHEMA_BASE_URL}fixture.json` };
fixtureSchema.patternProperties = undefined;
manufacturersSchema.properties = { $schema: { const: `${SCHEMA_BASE_URL}manufacturers.json` } };
manufacturersSchema.patternProperties = undefined;

return schemasJson;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/millumin/exportTests/json-schema-conformity.js
Expand Up @@ -59,8 +59,8 @@ async function getSchemas() {
fixtureSchema.properties.oflURL = true;

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

// allow new colors from schema version 11.1.0
// see https://github.com/OpenLightingProject/open-fixture-library/pull/763
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugins.json
Expand Up @@ -59,7 +59,7 @@
},
"ofl": {
"name": "Open Fixture Library JSON",
"exportPluginVersion": "12.2.1",
"exportPluginVersion": "12.2.2",
"exportTests": []
},
"op-z": {
Expand Down

0 comments on commit 587507d

Please sign in to comment.