Skip to content

Commit

Permalink
Add schemas for all JSON extracts
Browse files Browse the repository at this point in the history
This provides a first level of schema validation for curated data extracts,
see #657 for context.

Goal is to make it easier to detect and document (through a changelog, so also
useful for #704) situations where we change the structure of data extracts.

Schemas, notably those that deal with parsed IDL structures, could go deeper
into details.

Tests are run against the curated version of data. That is not necessary for
extracts that aren't actually curated (dfns, headings, ids, links, refs), just
more convenient not to have branching logic in the test code.
  • Loading branch information
tidoust committed Sep 14, 2022
1 parent 3a1b8e7 commit cd42d20
Show file tree
Hide file tree
Showing 16 changed files with 765 additions and 4 deletions.
124 changes: 120 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"@webref/elements": "file:packages/elements",
"@webref/events": "file:packages/events",
"@webref/idl": "file:packages/idl",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"css-tree": "2.2.1",
"flags": "0.1.3",
"mocha": "10.0.0",
Expand Down
134 changes: 134 additions & 0 deletions schemas/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"$schema": "http://json-schema.org/schema#",
"$id": "https://w3c.github.io/webref/schemas/common.json",

"$defs": {
"url": {
"type": "string",
"format": "uri"
},

"nullableurl": {
"oneOf": [
{ "$ref": "#/$defs/url" },
{ "type": "null" }
],
"$comment": "Extracts sometimes use null values for URLs, they should probably rather drop the property"
},

"title": {
"type": "string"
},

"shortname": {
"type": "string",
"pattern": "^[\\w\\-]+((?<=-\\d+)\\.\\d+)?$",
"$comment": "Same definition as in browser-specs"
},

"specInExtract": {
"type": "object",
"additionalProperties": false,
"properties": {
"title": { "$ref": "#/$defs/title" },
"url": { "$ref": "#/$defs/url" }
},
"required": ["title", "url"]
},

"cssPropertyName": {
"type": "string"
},

"cssValue": {
"type": "string"
},

"interface": {
"type": "string",
"pattern": "^[A-Z]([A-Za-z0-9_])*|console$",
"$comment": "console is the only interface name that starts with a lower-case character"
},

"global": {
"oneOf": [
{ "$ref": "#/$defs/interface" },
{ "type": "string", "const": "*" }
]
},

"id": {
"type": "string"
},

"headingNumber": {
"type": "string",
"pattern": "^(\\d+|[A-Z])(\\.\\d+)*$",
"$comment": "Note appendices start with an upper-case A-Z character"
},

"interfaces": {
"type": "array",
"items": { "$ref": "#/$defs/interface" }
},

"interfacesByGlobal": {
"type": "object",
"propertyNames": { "$ref": "#/$defs/global" },
"additionalProperties": { "$ref": "#/$defs/interfaces" }
},

"idlFragmentInSpec": {
"type": "object",
"additionalProperties": false,
"required": ["spec", "fragment"],
"properties": {
"spec": { "$ref": "#/$defs/specInExtract" },
"fragment": { "type": "string" },
"href": { "$ref": "#/$defs/url" }
}
},

"idlnameparsed": {
"type": "object",
"additionalProperties": false,
"required": ["name", "type", "defined", "extended", "includes"],
"properties": {
"name": { "$ref": "#/$defs/interface" },
"type": {
"type": "string",
"enum": ["dictionary", "interface", "interface mixin", "enum", "typedef",
"callback", "callback interface", "namespace"]
},
"defined": { "$ref": "#/$defs/idlFragmentInSpec" },
"extended": {
"type": "array",
"items": { "$ref": "#/$defs/idlFragmentInSpec" }
},
"inheritance": {
"oneOf": [
{ "type": "null" },
{ "$ref": "#/$defs/idlnameparsed" }
]
},
"includes": {
"type": "array",
"items": { "$ref": "#/$defs/idlnameparsed" }
}
}
},

"references": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["name"],
"properties": {
"name": { "type": "string" },
"url": { "$ref": "#/$defs/url" }
}
}
}
}
}
Loading

0 comments on commit cd42d20

Please sign in to comment.