From e89882e7ed7fa4a1db8d6230d49e657250344902 Mon Sep 17 00:00:00 2001 From: Francois Daoust Date: Mon, 26 Sep 2022 09:28:52 +0200 Subject: [PATCH] Use schemas from Reffy Linked to https://github.com/w3c/reffy/pull/1075 This will only work once a version of Reffy has been released that exposes the appropriate schema validation function. --- schemas/common.json | 138 ---------------------------- schemas/events.json | 52 ----------- schemas/extract-css.json | 73 --------------- schemas/extract-dfns.json | 59 ------------ schemas/extract-events.json | 39 -------- schemas/extract-headings.json | 27 ------ schemas/extract-idlnamesparsed.json | 5 - schemas/extract-idlparsed.json | 67 -------------- schemas/extract-ids.json | 16 ---- schemas/extract-links.json | 28 ------ schemas/extract-refs.json | 21 ----- schemas/idlnames.json | 16 ---- schemas/index.json | 40 -------- test/schemas.js | 88 +++++++----------- 14 files changed, 35 insertions(+), 634 deletions(-) delete mode 100644 schemas/common.json delete mode 100644 schemas/events.json delete mode 100644 schemas/extract-css.json delete mode 100644 schemas/extract-dfns.json delete mode 100644 schemas/extract-events.json delete mode 100644 schemas/extract-headings.json delete mode 100644 schemas/extract-idlnamesparsed.json delete mode 100644 schemas/extract-idlparsed.json delete mode 100644 schemas/extract-ids.json delete mode 100644 schemas/extract-links.json delete mode 100644 schemas/extract-refs.json delete mode 100644 schemas/idlnames.json delete mode 100644 schemas/index.json diff --git a/schemas/common.json b/schemas/common.json deleted file mode 100644 index 84636d555df1..000000000000 --- a/schemas/common.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/common.json", - - "$defs": { - "url": { - "type": "string", - "format": "url" - }, - - "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", - "minLength": 1 - }, - - "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", - "minLength": 1 - }, - - "cssValue": { - "type": "string", - "minLength": 1 - }, - - "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", - "minLength": 1 - }, - - "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", "minLength": 1 }, - "url": { "$ref": "#/$defs/url" } - } - } - } - } -} \ No newline at end of file diff --git a/schemas/events.json b/schemas/events.json deleted file mode 100644 index 5d6bfa6d2ad5..000000000000 --- a/schemas/events.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/events.json", - - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["type", "interface", "targets"], - "properties": { - "type": { "type": "string" }, - "interface": { "$ref": "common.json#/$defs/interface" }, - "targets": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["target"], - "properties": { - "target": { "$ref": "common.json#/$defs/interface" }, - "bubbles": { "type": "boolean" }, - "bubblingPath": { - "type": "array", - "items": { "$ref": "common.json#/$defs/interface" } - } - } - } - }, - "href": { "$ref": "common.json#/$defs/nullableurl" }, - "src": { - "type": "object", - "additionalProperties": false, - "properties": { - "format": { "type": "string" }, - "href": { "$ref": "common.json#/$defs/nullableurl" } - } - }, - "extendedIn": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["spec", "href"], - "properties": { - "spec": { "$ref": "common.json#/$defs/shortname" }, - "href": { "$ref": "common.json#/$defs/nullableurl" } - } - } - } - } - } -} diff --git a/schemas/extract-css.json b/schemas/extract-css.json deleted file mode 100644 index f556f85e2e3c..000000000000 --- a/schemas/extract-css.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-css.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "properties", "atrules", "valuespaces"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "properties": { - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/cssPropertyName" }, - "additionalProperties": { - "type": "object", - "additionalProperties": true, - "properties": { - "name": { "$ref": "common.json#/$defs/cssPropertyName" }, - "value": { "$ref": "common.json#/$defs/cssValue" }, - "styleDeclaration": { - "type": "array", - "items": { "type": "string" }, - "minItems": 1 - } - } - } - }, - - "atrules": { - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^@" - }, - "additionalProperties": { - "type": "object", - "additionalProperties": false, - "properties": { - "value": { "$ref": "common.json#/$defs/cssValue" }, - "descriptors": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": true, - "properties": { - "name": { "type": "string" }, - "for": { "type": "string" }, - "value": { "$ref": "common.json#/$defs/cssValue" } - } - } - } - } - } - }, - - "valuespaces": { - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^<[^>]+>$" - }, - "additionalProperties": { - "type": "object", - "additionalProperties": false, - "properties": { - "prose": { "type": "string" }, - "value": { "$ref": "common.json#/$defs/cssValue" }, - "legacyValue": { "$ref": "common.json#/$defs/cssValue" } - } - } - } - } -} diff --git a/schemas/extract-dfns.json b/schemas/extract-dfns.json deleted file mode 100644 index e8d1cccab402..000000000000 --- a/schemas/extract-dfns.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-dfns.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "dfns"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "dfns": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["id", "href", "linkingText", "localLinkingText", - "type", "for", "access", "informative", "heading", "definedIn"], - "properties": { - "id": { "$ref": "common.json#/$defs/id" }, - "href": { "$ref": "common.json#/$defs/url" }, - "linkingText": { - "type": "array", - "items": { "type": "string" } - }, - "localLinkingText": { - "type": "array", - "items": { "type": "string" } - }, - "type": { "type": "string" }, - "for": { - "type": "array", - "items": { "type": "string" } - }, - "access": { - "type": "string", - "enum": ["private", "public"] - }, - "informative": { - "type": "boolean" - }, - "heading": { - "type": "object", - "additionalProperties": false, - "required": ["href", "title"], - "properties": { - "id": { "$ref": "common.json#/$defs/id" }, - "href": { "$ref": "common.json#/$defs/url" }, - "title": { "type": "string" }, - "number": { "$ref": "common.json#/$defs/headingNumber" } - } - }, - "definedIn": { - "type": "string" - } - } - } - } - } -} diff --git a/schemas/extract-events.json b/schemas/extract-events.json deleted file mode 100644 index 9d0c57c93445..000000000000 --- a/schemas/extract-events.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-events.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "events"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "events": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["type", "interface"], - "properties": { - "type": { "type": "string" }, - "interface": { "$ref": "common.json#/$defs/interface" }, - "targets": { - "type": "array", - "items": { "$ref": "common.json#/$defs/interface" } - }, - "bubbles": { "type": "boolean" }, - "isExtension": { "type": "boolean" }, - "href": { "$ref": "common.json#/$defs/nullableurl" }, - "src": { - "type": "object", - "additionalProperties": false, - "properties": { - "format": { "type": "string" }, - "href": { "$ref": "common.json#/$defs/nullableurl" } - } - } - } - } - } - } -} diff --git a/schemas/extract-headings.json b/schemas/extract-headings.json deleted file mode 100644 index 86e77c774bea..000000000000 --- a/schemas/extract-headings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-headings.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "headings"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "headings": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "required": ["id", "href", "title", "level"], - "properties": { - "id": { "$ref": "common.json#/$defs/id" }, - "href": { "$ref": "common.json#/$defs/url" }, - "title": { "type": "string" }, - "level": { "type": "integer" }, - "number": { "$ref": "common.json#/$defs/headingNumber" } - } - } - } - } -} diff --git a/schemas/extract-idlnamesparsed.json b/schemas/extract-idlnamesparsed.json deleted file mode 100644 index 54d34580a98d..000000000000 --- a/schemas/extract-idlnamesparsed.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-idlnamesparsed.json", - "$ref": "common.json#/$defs/idlnameparsed" -} diff --git a/schemas/extract-idlparsed.json b/schemas/extract-idlparsed.json deleted file mode 100644 index ae8bd71da995..000000000000 --- a/schemas/extract-idlparsed.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-idlparsed.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "idlparsed"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "idlparsed": { - "type": "object", - "additionalProperties": false, - "required": ["jsNames", "idlNames", "idlExtendedNames", "globals", - "exposed", "dependencies", "externalDependencies", "hasObsoleteIdl"], - "properties": { - "jsNames": { - "type": "object", - "additionalProperties": false, - "required": ["constructors", "functions"], - "properties": { - "constructors": { "$ref": "common.json#/$defs/interfacesByGlobal" }, - "functions": { "$ref": "common.json#/$defs/interfacesByGlobal" } - } - }, - "idlNames": { - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/interface" }, - "additionalProperties": { - "type": "object", - "additionalProperties": true, - "required": ["fragment", "type"], - "properties": { - "fragment": { "type": "string" }, - "type": { "type": "string" } - } - } - }, - "idlExtendedNames": { - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/interface" }, - "additionalProperties": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": true, - "required": ["fragment", "type"], - "properties": { - "fragment": { "type": "string" }, - "type": { "type": "string" } - } - } - } - }, - "globals": { "$ref": "common.json#/$defs/interfacesByGlobal" }, - "exposed": { "$ref": "common.json#/$defs/interfacesByGlobal" }, - "dependencies": { - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/interface" }, - "additionalProperties": { "$ref": "common.json#/$defs/interfaces" } - }, - "externalDependencies": { "$ref": "common.json#/$defs/interfaces" }, - "hasObsoleteIdl": { "type": "boolean" } - } - } - } -} diff --git a/schemas/extract-ids.json b/schemas/extract-ids.json deleted file mode 100644 index 42613099d0b3..000000000000 --- a/schemas/extract-ids.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-ids.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "ids"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "ids": { - "type": "array", - "items": { "$ref": "common.json#/$defs/url" } - } - } -} diff --git a/schemas/extract-links.json b/schemas/extract-links.json deleted file mode 100644 index 5b9367cab70e..000000000000 --- a/schemas/extract-links.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-links.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "links"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "links": { - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/url" }, - "additionalProperties": { - "type": "object", - "additionalProperties": false, - "properties": { - "anchors": { - "type": "array", - "items": { "$ref": "common.json#/$defs/id" }, - "minItems": 1 - }, - "specShortname": { "$ref": "common.json#/$defs/shortname" } - } - } - } - } -} diff --git a/schemas/extract-refs.json b/schemas/extract-refs.json deleted file mode 100644 index 6df78a984cb4..000000000000 --- a/schemas/extract-refs.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/extract-refs.json", - - "type": "object", - "additionalProperties": false, - "required": ["spec", "refs"], - "properties": { - "spec": { "$ref": "common.json#/$defs/specInExtract" }, - - "refs": { - "type": "object", - "additionalProperties": false, - "required": ["normative", "informative"], - "properties": { - "normative": { "$ref": "common.json#/$defs/references" }, - "informative": { "$ref": "common.json#/$defs/references" } - } - } - } -} diff --git a/schemas/idlnames.json b/schemas/idlnames.json deleted file mode 100644 index 5fa35959ae85..000000000000 --- a/schemas/idlnames.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/idlnames.json", - - "type": "object", - "propertyNames": { "$ref": "common.json#/$defs/interface" }, - "additionalProperties": { - "type": "object", - "additionalProperties": false, - "required": ["fragment", "parsed"], - "properties": { - "fragment": { "type": "string" }, - "parsed": { "type": "string" } - } - } -} diff --git a/schemas/index.json b/schemas/index.json deleted file mode 100644 index 83a1111fdfe1..000000000000 --- a/schemas/index.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "$id": "https://w3c.github.io/webref/schemas/index.json", - - "type": "object", - "additionalProperties": false, - "required": ["type", "title", "date", "stats", "crawler", "results"], - "properties": { - "type": { "type": "string", "const": "crawl" }, - "title": { "type": "string" }, - "date": { - "type": "string", - "pattern": "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z" - }, - "crawler": { "type": "string" }, - - "options": { "type": "object" }, - - "stats": { - "type": "object", - "additionalProperties": false, - "required": ["crawled", "errors"], - "properties": { - "crawled": { - "type": "integer" - }, - "errors": { - "type": "integer" - } - } - }, - - "results": { - "type": "array", - "items": { - "type": "object" - } - } - } -} diff --git a/test/schemas.js b/test/schemas.js index a46681adac60..743d6b210507 100644 --- a/test/schemas.js +++ b/test/schemas.js @@ -6,61 +6,43 @@ const fs = require('fs'); const path = require('path'); -const Ajv = require('ajv'); -const addFormats = require('ajv-formats'); const assert = require('assert').strict; -const commonSchema = require('../schemas/common.json'); - -const schemaFiles = fs.readdirSync(path.join(__dirname, '..', 'schemas')); -for (const schemaFile of schemaFiles) { - if (schemaFile.endsWith('.json')) { - const schema = require(path.join('..', 'schemas', schemaFile)); - const ajv = new Ajv({ verbose: true, allErrors: true }); - addFormats(ajv); - - if (schemaFile.startsWith('extract-')) { - const dataFolder = schemaFile.replace(/^extract-(.*)\.json$/, '$1'); - - describe(`The ${dataFolder} folder`, function () { - it('is linked to a valid JSON schema', () => { - const isSchemaValid = ajv.validateSchema(schema); - assert.ok(isSchemaValid); - }); - - describe(`The ${dataFolder} folder`, function () { - const folder = path.join(__dirname, '..', 'curated', dataFolder); - const files = fs.readdirSync(folder); - const validate = ajv.addSchema(commonSchema).compile(schema); - - for (const file of files) { - if (file.endsWith('.json')) { - it(`has valid data in ${file}`, () => { - const data = require(path.join(folder, file)); - const isValid = validate(data); - assert.strictEqual(validate.errors, null); - assert.ok(isValid); - }); - } - } - }); - }); - } - - else if (fs.existsSync(path.join(__dirname, '..', 'curated', schemaFile))) { - describe(`The ${schemaFile} file`, function () { - it('is linked to a valid JSON schema', () => { - const isSchemaValid = ajv.validateSchema(schema); - assert.ok(isSchemaValid); - }); +const { getSchemaValidationFunction } = require('reffy'); + +const curatedFolder = path.join(__dirname, '..', 'curated'); +const files = fs.readdirSync(curatedFolder); +for (const file of files) { + const validate = getSchemaValidationFunction(file); + if (!validate) { + // No schema (typically normal for IDL extracts that are not JSON files) + continue; + } - it('has valid data', () => { - const validate = ajv.addSchema(commonSchema).compile(schema); - const data = require(path.join('..', 'curated', schemaFile)); - const isValid = validate(data); - assert.strictEqual(validate.errors, null); - assert.ok(isValid); - }); + if (file.endsWith('.json')) { + continue; + describe(`The ${file} file`, function () { + it('contains valid data', function () { + const data = require(path.join(curatedFolder, file)); + const errors = validate(data); + assert.strictEqual(errors, null, JSON.stringify(errors, null, 2)); }); - } + }); + } + else { + if (file !== 'idlnamesparsed') continue; + describe(`The ${file} folder`, function () { + const extractType = file; + const folder = path.join(curatedFolder, extractType); + const files = fs.readdirSync(folder); + for (const file of files) { + if (file.endsWith('.json')) { + it(`contains valid ${extractType} data in ${file}`, () => { + const data = require(path.join(folder, file)); + const errors = validate(data); + assert.strictEqual(errors, null, JSON.stringify(errors, null, 2)); + }); + } + } + }); } }