From 3fb4dfdd4e995d5d9da3ec95f617ac69d3af824d Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Sat, 16 Mar 2024 09:28:17 +0530 Subject: [PATCH 1/6] Re-opened: TODO to make mappers less verbose Signed-off-by: Suprith KG --- bindings/node/builtin.js | 64 ++++++++++++++++------------------------ bindings/node/index.js | 9 +----- bindings/node/test.js | 9 +++--- www/app.js | 4 +-- 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/bindings/node/builtin.js b/bindings/node/builtin.js index 82281d0..67e99ee 100644 --- a/bindings/node/builtin.js +++ b/bindings/node/builtin.js @@ -1,42 +1,28 @@ -const DRAFT3_TO_DRAFT3 = require('../../rules/jsonschema-draft3-to-draft3.json') -const DRAFT3_TO_DRAFT4 = require('../../rules/jsonschema-draft3-to-draft4.json') -const DRAFT4_TO_DRAFT4 = require('../../rules/jsonschema-draft4-to-draft4.json') -const DRAFT4_TO_DRAFT6 = require('../../rules/jsonschema-draft4-to-draft6.json') -const DRAFT6_TO_DRAFT7 = require('../../rules/jsonschema-draft6-to-draft7.json') -const DRAFT6_TO_DRAFT6 = require('../../rules/jsonschema-draft6-to-draft6.json') -const DRAFT7_TO_V2019_09 = require('../../rules/jsonschema-draft7-to-2019-09.json') -const DRAFT7_TO_DRAFT7 = require('../../rules/jsonschema-draft7-to-draft7.json') -const V2019_09_TO_V2020_12 = require('../../rules/jsonschema-2019-09-to-2020-12.json') -const V2019_09_TO_V2019_09 = require('../../rules/jsonschema-2019-09-to-2019-09.json') -const V2020_12_TO_V2020_12 = require('../../rules/jsonschema-2020-12-to-2020-12.json') +// TODO: Find a way to specify transitiveness in a less verbose manner: DONE -// TODO: Find a way to specify transitiveness in a less verbose manner -module.exports = { - jsonschema: { - draft3: { - draft4: [DRAFT3_TO_DRAFT3, DRAFT3_TO_DRAFT4, DRAFT4_TO_DRAFT4], - draft6: [DRAFT3_TO_DRAFT3, DRAFT3_TO_DRAFT4, DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6], - draft7: [DRAFT3_TO_DRAFT3, DRAFT3_TO_DRAFT4, DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7], - '2019-09': [DRAFT3_TO_DRAFT3, DRAFT3_TO_DRAFT4, DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09], - '2020-12': [DRAFT3_TO_DRAFT3, DRAFT3_TO_DRAFT4, DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09, V2019_09_TO_V2020_12, V2020_12_TO_V2020_12] - }, - draft4: { - draft6: [DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6], - draft7: [DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7], - '2019-09': [DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09], - '2020-12': [DRAFT4_TO_DRAFT4, DRAFT4_TO_DRAFT6, DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09, V2019_09_TO_V2020_12, V2020_12_TO_V2020_12] - }, - draft6: { - draft7: [DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7], - '2019-09': [DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09], - '2020-12': [DRAFT6_TO_DRAFT6, DRAFT6_TO_DRAFT7, DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09, V2019_09_TO_V2020_12, V2020_12_TO_V2020_12] - }, - draft7: { - '2019-09': [DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09], - '2020-12': [DRAFT7_TO_DRAFT7, DRAFT7_TO_V2019_09, V2019_09_TO_V2019_09, V2019_09_TO_V2020_12, V2020_12_TO_V2020_12] - }, - '2019-09': { - '2020-12': [V2019_09_TO_V2019_09, V2019_09_TO_V2020_12, V2020_12_TO_V2020_12] - } +// mappers to store all the mappers of all drafts from draft3 to draft7 +const drafts = ['draft3', 'draft4', 'draft6', 'draft7', '2019-09', '2020-12'] +const mappers = drafts.flatMap((draft, index) => { + const rules = [require(`../../rules/jsonschema-${draft}-to-${draft}.json`)] + if (index + 1 < drafts.length) { + rules.push(require(`../../rules/jsonschema-${draft}-to-${drafts[index + 1]}.json`)) } + return rules +}) + +// indexMapper maps drafts to their index in the mappers array. This is used to find the subarray of mappers to be returned. +const indexMapper = new Map(drafts.map((draft, index) => [draft, index * 2])) + +exports.builtin = (from, to) => { + if (!indexMapper.has(from)) { + throw new Error(`Invalid "from": ${from}`) + } else if (!indexMapper.has(to)) { + throw new Error(`Invalid "to": ${to}`) + } + + const fromIndex = indexMapper.get(from) + const toIndex = indexMapper.get(to) + return mappers.slice(fromIndex, toIndex + 1) } + +exports.drafts = drafts diff --git a/bindings/node/index.js b/bindings/node/index.js index baa4a1c..b68f1e1 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -60,14 +60,7 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) { module.exports = async (value, from, to) => { let accumulator = _.cloneDeep(value) - - if (!builtin.jsonschema[from]) { - throw new Error(`Invalid "from": ${from}`) - } else if (!builtin.jsonschema[from][to]) { - throw new Error(`Invalid "to": ${to}`) - } - - for (const mapper of builtin.jsonschema[from][to]) { + for (const mapper of builtin.builtin(from, to)) { const trails = walker(mapper.walker, accumulator, []).sort((a, b) => { return b.path.length - a.path.length }) diff --git a/bindings/node/test.js b/bindings/node/test.js index 9807c58..1a0f861 100644 --- a/bindings/node/test.js +++ b/bindings/node/test.js @@ -10,6 +10,7 @@ const jsonschema = require('./jsonschema') const alterschema = require('./index') const packageJSON = require('../../package.json') const METASCHEMAS = _.invert(require('../../metaschemas.json')) +const drafts = builtin.drafts const JSON_SCHEMA_TEST_SUITE = path.resolve(__dirname, '..', '..', 'vendor', 'json-schema-test-suite') const TESTS_BASE_DIRECTORY = path.resolve(JSON_SCHEMA_TEST_SUITE, 'tests') @@ -24,8 +25,8 @@ const recursiveReadDirectory = (directory) => { }, []) } -for (const from of Object.keys(builtin.jsonschema)) { - for (const to of Object.keys(builtin.jsonschema[from])) { +for (const [draftIndex, from] of drafts.entries()) { + for (const to of drafts.slice(draftIndex + 1)) { const tests = require(`../../test/rules/jsonschema-${from}-to-${to}.json`) for (const testCase of tests) { tap.test(`${from} => ${to}: ${testCase.name}`, async (test) => { @@ -101,7 +102,7 @@ const BLACKLIST = [ 'refRemote' ] -for (const from of Object.keys(builtin.jsonschema)) { +for (const [draftIndex, from] of drafts.entries()) { // TODO: Support running draft3 tests if (from === 'draft3') { continue @@ -141,7 +142,7 @@ for (const from of Object.keys(builtin.jsonschema)) { } const index = testCase.tests.indexOf(instance) - for (const to of Object.keys(builtin.jsonschema[from])) { + for (const to of drafts.slice(draftIndex + 1)) { tap.test(`${suiteName} (${from} -> ${to}) ${testCase.description} #${index}`, async (test) => { // We need at least an arbitrary id to make @hyperjump/json-schema work const id = `https://alterschema.sourcemeta.com/${_.kebabCase(testCase.description)}/${index}` diff --git a/www/app.js b/www/app.js index bc5fe4c..ad56834 100644 --- a/www/app.js +++ b/www/app.js @@ -58,7 +58,7 @@ function onError (error) { } function refreshFrom (spec) { - setSpecificationOptions(from, Object.keys(builtin.jsonschema), spec) + setSpecificationOptions(from, builtin.drafts, spec) from.dispatchEvent(new Event('change')) } @@ -145,7 +145,7 @@ transform.addEventListener('click', () => { from.addEventListener('change', (event) => { setSpecificationOptions(to, - Object.keys(builtin.jsonschema[event.target.value]).reverse()) + builtin.drafts.slice(builtin.drafts.indexOf(event.target.value) + 1).reverse()) }) document.getElementById('version').innerText = `v${packageJSON.version}` From df716112daea75d1b7e9334631cfc26004bcb76a Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 19 Mar 2024 01:45:48 +0530 Subject: [PATCH 2/6] Using pure JSON-e instead of omit and replace Signed-off-by: Suprith KG --- bindings/node/index.js | 8 +- rules/jsonschema-2019-09-to-2019-09.json | 24 +++++- rules/jsonschema-2019-09-to-2020-12.json | 103 ++++++++++++++++++++--- rules/jsonschema-draft3-to-draft4.json | 36 +++++++- rules/jsonschema-draft4-to-draft6.json | 72 ++++++++++++++-- rules/jsonschema-draft6-to-draft7.json | 12 ++- rules/jsonschema-draft7-to-2019-09.json | 62 ++++++++++++-- 7 files changed, 282 insertions(+), 35 deletions(-) diff --git a/bindings/node/index.js b/bindings/node/index.js index b68f1e1..a04aea8 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -37,13 +37,7 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) { return false }, - // TODO: Use standard JSON-e operators instead - omit: (object, keys) => { - return _.omit(object, _.castArray(keys)) - }, - replace: (value, regex, replacement) => { - return value.replace(new RegExp(regex, 'g'), replacement) - } + // TODO: Use standard JSON-e operators instead: DONE }) if (await jsonschema.matches(rule.condition, output)) { diff --git a/rules/jsonschema-2019-09-to-2019-09.json b/rules/jsonschema-2019-09-to-2019-09.json index dd59c0c..21fa0b1 100644 --- a/rules/jsonschema-2019-09-to-2019-09.json +++ b/rules/jsonschema-2019-09-to-2019-09.json @@ -15,7 +15,17 @@ } }, "transform": { - "$eval": "omit(schema, 'dependentSchemas')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependentSchemas'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -32,7 +42,17 @@ } }, "transform": { - "$eval": "omit(schema, 'dependentRequired')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependentRequired'", + "then": { + "$eval": "v" + } + } + } } } ] diff --git a/rules/jsonschema-2019-09-to-2020-12.json b/rules/jsonschema-2019-09-to-2020-12.json index 3728567..7e94865 100644 --- a/rules/jsonschema-2019-09-to-2020-12.json +++ b/rules/jsonschema-2019-09-to-2020-12.json @@ -38,7 +38,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'items')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='items'", + "then": { + "$eval": "v" + } + } + } }, { "prefixItems": { "$eval": "schema.items" @@ -64,10 +74,23 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/items/(\\d+)', '/prefixItems/$1')" + "$if": "split(schema['$ref'], 'items')[1][1] in '1234567890'", + "then":{ + "$eval": "join(split(schema['$ref'], 'items'), 'prefixItems')" + } } } ] @@ -90,10 +113,20 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/additionalItems', '/items')" + "$eval": "join(split(schema['$ref'], 'additionalItems'), 'items')" } } ] @@ -116,7 +149,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'additionalItems')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='additionalItems'", + "then": { + "$eval": "v" + } + } + } }, { "items": { "$eval": "schema.additionalItems" @@ -167,7 +210,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" @@ -190,7 +243,17 @@ } }, "transform": { - "$eval": "omit(schema, '$recursiveAnchor')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveAnchor'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -208,7 +271,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$recursiveAnchor')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveAnchor'", + "then": { + "$eval": "v" + } + } + } }, { "$$dynamicAnchor": { "$eval": "'anchor-' + jsonHash(original)" @@ -232,7 +305,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$recursiveRef')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveRef'", + "then": { + "$eval": "v" + } + } + } }, { "$$dynamicRef": { "$if": "hasContext('$recursiveAnchor', true)", diff --git a/rules/jsonschema-draft3-to-draft4.json b/rules/jsonschema-draft3-to-draft4.json index bbb41aa..281247e 100644 --- a/rules/jsonschema-draft3-to-draft4.json +++ b/rules/jsonschema-draft3-to-draft4.json @@ -35,7 +35,17 @@ } }, "transform": { - "$eval": "omit(schema, 'type')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='type'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -55,7 +65,17 @@ } }, "transform": { - "$eval": "omit(schema, 'type')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='type'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -73,7 +93,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'divisibleBy')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='divisibleBy'", + "then": { + "$eval": "v" + } + } + } }, { "multipleOf": { "$eval": "schema.divisibleBy" diff --git a/rules/jsonschema-draft4-to-draft6.json b/rules/jsonschema-draft4-to-draft6.json index c3f4127..9f76891 100644 --- a/rules/jsonschema-draft4-to-draft6.json +++ b/rules/jsonschema-draft4-to-draft6.json @@ -36,7 +36,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'id')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='id'", + "then": { + "$eval": "v" + } + } + } }, { "$$id": { "$eval": "schema.id" @@ -63,7 +73,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'minimum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='minimum'", + "then": { + "$eval": "v" + } + } + } }, { "exclusiveMinimum": { "$eval": "schema.minimum" @@ -90,7 +110,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'maximum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='maximum'", + "then": { + "$eval": "v" + } + } + } }, { "exclusiveMaximum": { "$eval": "schema.maximum" @@ -117,7 +147,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'exclusiveMinimum')" } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='exclusiveMinimum'", + "then": { + "$eval": "v" + } + } + } } ] } }, @@ -139,7 +179,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'exclusiveMaximum')" } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='exclusiveMaximum'", + "then": { + "$eval": "v" + } + } + } } ] } }, @@ -182,7 +232,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" diff --git a/rules/jsonschema-draft6-to-draft7.json b/rules/jsonschema-draft6-to-draft7.json index 7557e41..63d7fd8 100644 --- a/rules/jsonschema-draft6-to-draft7.json +++ b/rules/jsonschema-draft6-to-draft7.json @@ -60,7 +60,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + }}, { "const": { "$eval": "schema.enum[0]" diff --git a/rules/jsonschema-draft7-to-2019-09.json b/rules/jsonschema-draft7-to-2019-09.json index 6a0621f..81f7bd9 100644 --- a/rules/jsonschema-draft7-to-2019-09.json +++ b/rules/jsonschema-draft7-to-2019-09.json @@ -37,7 +37,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$id')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$id'", + "then": { + "$eval": "v" + } + } + } }, { "$$anchor": { "$eval": "schema['$id'][1:]" @@ -61,7 +71,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'definitions')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='definitions'", + "then": { + "$eval": "v" + } + } + }}, { "$$defs": { "$eval": "schema.definitions" @@ -86,10 +106,20 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/definitions/', '/$defs/')" + "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" } } ] @@ -134,7 +164,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" @@ -158,7 +198,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'dependencies')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependencies'", + "then": { + "$eval": "v" + } + } + } }, { "dependentRequired": { "$map": { From 297d05ab490a4db26b229ca3ed166872f0591930 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 19 Mar 2024 01:50:41 +0530 Subject: [PATCH 3/6] commit 3 Signed-off-by: Suprith KG --- bindings/node/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/node/index.js b/bindings/node/index.js index a04aea8..d7058d4 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -36,8 +36,6 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) { return false }, - - // TODO: Use standard JSON-e operators instead: DONE }) if (await jsonschema.matches(rule.condition, output)) { From db158e288f1e9b4595a809632ca08e0b505bb2fc Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 19 Mar 2024 01:53:37 +0530 Subject: [PATCH 4/6] removed unexpected comma Signed-off-by: Suprith KG --- bindings/node/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/node/index.js b/bindings/node/index.js index d7058d4..ba74a12 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -35,7 +35,7 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) { } return false - }, + } }) if (await jsonschema.matches(rule.condition, output)) { From 2e132478b5f92f0cb72751f5570021ab2302f4ad Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Thu, 28 Mar 2024 16:27:08 +0530 Subject: [PATCH 5/6] corrected $schema transformation rule Signed-off-by: Suprith KG --- rules/jsonschema-2019-09-to-2020-12.json | 3 +- rules/jsonschema-draft3-to-draft4.json | 3 +- rules/jsonschema-draft4-to-draft6.json | 3 +- rules/jsonschema-draft6-to-draft7.json | 3 +- rules/jsonschema-draft7-to-2019-09.json | 141 ++++++++++++++--------- 5 files changed, 93 insertions(+), 60 deletions(-) diff --git a/rules/jsonschema-2019-09-to-2020-12.json b/rules/jsonschema-2019-09-to-2020-12.json index 7e94865..36815a8 100644 --- a/rules/jsonschema-2019-09-to-2020-12.json +++ b/rules/jsonschema-2019-09-to-2020-12.json @@ -10,7 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "const": "https://json-schema.org/draft/2019-09/schema" + "type":"string", + "pattern": "http[s]?://json-schema.org/draft/2019-09/schema[#]?" } } }, diff --git a/rules/jsonschema-draft3-to-draft4.json b/rules/jsonschema-draft3-to-draft4.json index 281247e..b8d95ee 100644 --- a/rules/jsonschema-draft3-to-draft4.json +++ b/rules/jsonschema-draft3-to-draft4.json @@ -10,7 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "const": "http://json-schema.org/draft-03/schema#" + "type":"string", + "pattern": "http[s]?://json-schema.org/draft-03/schema[#]?" } } }, diff --git a/rules/jsonschema-draft4-to-draft6.json b/rules/jsonschema-draft4-to-draft6.json index 9f76891..1b29f13 100644 --- a/rules/jsonschema-draft4-to-draft6.json +++ b/rules/jsonschema-draft4-to-draft6.json @@ -10,7 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "const": "http://json-schema.org/draft-04/schema#" + "type":"string", + "pattern": "http[s]?://json-schema.org/draft-04/schema[#]?" } } }, diff --git a/rules/jsonschema-draft6-to-draft7.json b/rules/jsonschema-draft6-to-draft7.json index 63d7fd8..6ad931d 100644 --- a/rules/jsonschema-draft6-to-draft7.json +++ b/rules/jsonschema-draft6-to-draft7.json @@ -10,7 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "const": "http://json-schema.org/draft-06/schema#" + "type":"string", + "pattern": "http[s]?://json-schema.org/draft-06/schema[#]?" } } }, diff --git a/rules/jsonschema-draft7-to-2019-09.json b/rules/jsonschema-draft7-to-2019-09.json index 81f7bd9..9797d07 100644 --- a/rules/jsonschema-draft7-to-2019-09.json +++ b/rules/jsonschema-draft7-to-2019-09.json @@ -7,17 +7,24 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/upgrade-official-metaschema", "type": "object", - "required": [ "$schema" ], + "required": [ + "$schema" + ], "properties": { "$schema": { - "const": "http://json-schema.org/draft-07/schema#" + "type": "string", + "pattern": "http[s]?://json-schema.org/draft-07/schema[#]?" } } }, "transform": { "$merge": [ - { "$eval": "schema" }, - { "$$schema": "https://json-schema.org/draft/2019-09/schema" } + { + "$eval": "schema" + }, + { + "$$schema": "https://json-schema.org/draft/2019-09/schema" + } ] } }, @@ -27,7 +34,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/id-anchor", "type": "object", - "required": [ "$id" ], + "required": [ + "$id" + ], "properties": { "$id": { "type": "string", @@ -37,17 +46,19 @@ }, "transform": { "$merge": [ - { "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='$id'", - "then": { - "$eval": "v" + { + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$id'", + "then": { + "$eval": "v" + } } } - } }, + }, { "$$anchor": { "$eval": "schema['$id'][1:]" @@ -62,7 +73,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/definitions", "type": "object", - "required": [ "definitions" ], + "required": [ + "definitions" + ], "properties": { "definitions": { "type": "object" @@ -71,17 +84,19 @@ }, "transform": { "$merge": [ - { "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='definitions'", - "then": { - "$eval": "v" + { + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='definitions'", + "then": { + "$eval": "v" + } } } - }}, + }, { "$$defs": { "$eval": "schema.definitions" @@ -96,7 +111,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/definitions-in-ref", "type": "object", - "required": [ "$ref" ], + "required": [ + "$ref" + ], "properties": { "$ref": { "type": "string", @@ -106,20 +123,22 @@ }, "transform": { "$merge": [ - { "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='$ref'", - "then": { - "$eval": "v" + { + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } } } - } }, + }, { "$$ref": { - "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" + "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" } } ] @@ -141,7 +160,9 @@ "condition": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/negated-empty-object", - "const": { "not": true } + "const": { + "not": true + } }, "transform": { "$eval": "false" @@ -153,7 +174,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/enum-to-const", "type": "object", - "required": [ "enum" ], + "required": [ + "enum" + ], "properties": { "enum": { "type": "array", @@ -164,17 +187,19 @@ }, "transform": { "$merge": [ - { "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='enum'", - "then": { - "$eval": "v" + { + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } } } - } }, + }, { "const": { "$eval": "schema.enum[0]" @@ -189,7 +214,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/dependencies", "type": "object", - "required": [ "dependencies" ], + "required": [ + "dependencies" + ], "properties": { "dependencies": { "type": "object" @@ -198,17 +225,19 @@ }, "transform": { "$merge": [ - { "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='dependencies'", - "then": { - "$eval": "v" + { + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependencies'", + "then": { + "$eval": "v" + } } } - } }, + }, { "dependentRequired": { "$map": { From f9ffbbac2e15fb93fb15cad04dbf8fa5632c86d0 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Sat, 30 Mar 2024 04:34:08 +0530 Subject: [PATCH 6/6] added test suite for the scheme and empty fragment Signed-off-by: Suprith KG --- rules/jsonschema-2019-09-to-2020-12.json | 4 +- rules/jsonschema-draft3-to-draft4.json | 4 +- rules/jsonschema-draft4-to-draft6.json | 4 +- rules/jsonschema-draft6-to-draft7.json | 4 +- rules/jsonschema-draft7-to-2019-09.json | 140 +++++++----------- test/rules/jsonschema-2019-09-to-2020-12.json | 22 +++ test/rules/jsonschema-draft4-to-2019-09.json | 18 +++ test/rules/jsonschema-draft4-to-2020-12.json | 18 +++ test/rules/jsonschema-draft4-to-draft6.json | 18 +++ test/rules/jsonschema-draft4-to-draft7.json | 18 +++ test/rules/jsonschema-draft6-to-2019-09.json | 18 +++ test/rules/jsonschema-draft6-to-2020-12.json | 18 +++ test/rules/jsonschema-draft6-to-draft7.json | 18 +++ test/rules/jsonschema-draft7-to-2019-09.json | 18 +++ test/rules/jsonschema-draft7-to-2020-12.json | 18 +++ 15 files changed, 248 insertions(+), 92 deletions(-) diff --git a/rules/jsonschema-2019-09-to-2020-12.json b/rules/jsonschema-2019-09-to-2020-12.json index 36815a8..a7c85b7 100644 --- a/rules/jsonschema-2019-09-to-2020-12.json +++ b/rules/jsonschema-2019-09-to-2020-12.json @@ -10,8 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "type":"string", - "pattern": "http[s]?://json-schema.org/draft/2019-09/schema[#]?" + "type": "string", + "pattern": "^http[s]?://json-schema.org/draft/2019-09/schema[#]?$" } } }, diff --git a/rules/jsonschema-draft3-to-draft4.json b/rules/jsonschema-draft3-to-draft4.json index b8d95ee..615c298 100644 --- a/rules/jsonschema-draft3-to-draft4.json +++ b/rules/jsonschema-draft3-to-draft4.json @@ -10,8 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "type":"string", - "pattern": "http[s]?://json-schema.org/draft-03/schema[#]?" + "type": "string", + "pattern": "^http[s]?://json-schema.org/draft-03/schema[#]?$" } } }, diff --git a/rules/jsonschema-draft4-to-draft6.json b/rules/jsonschema-draft4-to-draft6.json index 1b29f13..28ce4f5 100644 --- a/rules/jsonschema-draft4-to-draft6.json +++ b/rules/jsonschema-draft4-to-draft6.json @@ -10,8 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "type":"string", - "pattern": "http[s]?://json-schema.org/draft-04/schema[#]?" + "type": "string", + "pattern": "^http[s]?://json-schema.org/draft-04/schema[#]?$" } } }, diff --git a/rules/jsonschema-draft6-to-draft7.json b/rules/jsonschema-draft6-to-draft7.json index 6ad931d..e7e1a4c 100644 --- a/rules/jsonschema-draft6-to-draft7.json +++ b/rules/jsonschema-draft6-to-draft7.json @@ -10,8 +10,8 @@ "required": [ "$schema" ], "properties": { "$schema": { - "type":"string", - "pattern": "http[s]?://json-schema.org/draft-06/schema[#]?" + "type": "string", + "pattern": "^http[s]?://json-schema.org/draft-06/schema[#]?$" } } }, diff --git a/rules/jsonschema-draft7-to-2019-09.json b/rules/jsonschema-draft7-to-2019-09.json index 9797d07..2a8d7f2 100644 --- a/rules/jsonschema-draft7-to-2019-09.json +++ b/rules/jsonschema-draft7-to-2019-09.json @@ -7,24 +7,18 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/upgrade-official-metaschema", "type": "object", - "required": [ - "$schema" - ], + "required": [ "$schema" ], "properties": { "$schema": { "type": "string", - "pattern": "http[s]?://json-schema.org/draft-07/schema[#]?" + "pattern": "^http[s]?://json-schema.org/draft-07/schema[#]?$" } } }, "transform": { "$merge": [ - { - "$eval": "schema" - }, - { - "$$schema": "https://json-schema.org/draft/2019-09/schema" - } + { "$eval": "schema" }, + { "$$schema": "https://json-schema.org/draft/2019-09/schema" } ] } }, @@ -34,9 +28,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/id-anchor", "type": "object", - "required": [ - "$id" - ], + "required": [ "$id" ], "properties": { "$id": { "type": "string", @@ -46,19 +38,17 @@ }, "transform": { "$merge": [ - { - "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='$id'", - "then": { - "$eval": "v" - } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$id'", + "then": { + "$eval": "v" } } - }, + } }, { "$$anchor": { "$eval": "schema['$id'][1:]" @@ -73,9 +63,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/definitions", "type": "object", - "required": [ - "definitions" - ], + "required": [ "definitions" ], "properties": { "definitions": { "type": "object" @@ -84,19 +72,17 @@ }, "transform": { "$merge": [ - { - "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='definitions'", - "then": { - "$eval": "v" - } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='definitions'", + "then": { + "$eval": "v" } } - }, + }}, { "$$defs": { "$eval": "schema.definitions" @@ -111,9 +97,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/definitions-in-ref", "type": "object", - "required": [ - "$ref" - ], + "required": [ "$ref" ], "properties": { "$ref": { "type": "string", @@ -123,22 +107,20 @@ }, "transform": { "$merge": [ - { - "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='$ref'", - "then": { - "$eval": "v" - } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" } } - }, + } }, { "$$ref": { - "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" + "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" } } ] @@ -160,9 +142,7 @@ "condition": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/negated-empty-object", - "const": { - "not": true - } + "const": { "not": true } }, "transform": { "$eval": "false" @@ -174,9 +154,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/enum-to-const", "type": "object", - "required": [ - "enum" - ], + "required": [ "enum" ], "properties": { "enum": { "type": "array", @@ -187,19 +165,17 @@ }, "transform": { "$merge": [ - { - "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='enum'", - "then": { - "$eval": "v" - } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" } } - }, + } }, { "const": { "$eval": "schema.enum[0]" @@ -214,9 +190,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/dependencies", "type": "object", - "required": [ - "dependencies" - ], + "required": [ "dependencies" ], "properties": { "dependencies": { "type": "object" @@ -225,19 +199,17 @@ }, "transform": { "$merge": [ - { - "$map": { - "$eval": "schema" - }, - "each(v,k)": { - "${k}": { - "$if": "k!='dependencies'", - "then": { - "$eval": "v" - } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependencies'", + "then": { + "$eval": "v" } } - }, + } }, { "dependentRequired": { "$map": { diff --git a/test/rules/jsonschema-2019-09-to-2020-12.json b/test/rules/jsonschema-2019-09-to-2020-12.json index 6c2b0d3..9c0d65b 100644 --- a/test/rules/jsonschema-2019-09-to-2020-12.json +++ b/test/rules/jsonschema-2019-09-to-2020-12.json @@ -10,6 +10,28 @@ "type": "object" } }, + { + "name": "2019-09 official $schema to 2020-12 with http scheme", + "schema": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "type": "object" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object" + } + }, + { + "name": "2019-09 official $schema to 2020-12 with an empty fragment", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema#", + "type": "object" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object" + } + }, { "name": "items array to prefixItems", "schema": { diff --git a/test/rules/jsonschema-draft4-to-2019-09.json b/test/rules/jsonschema-draft4-to-2019-09.json index 086f972..f5630fc 100644 --- a/test/rules/jsonschema-draft4-to-2019-09.json +++ b/test/rules/jsonschema-draft4-to-2019-09.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2019-09/schema" } }, + { + "name": "draft4 $schema with https scheme", + "schema": { + "$schema": "https://json-schema.org/draft-04/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, + { + "name": "draft4 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, { "name": "draft4 id to $id", "schema": { diff --git a/test/rules/jsonschema-draft4-to-2020-12.json b/test/rules/jsonschema-draft4-to-2020-12.json index a2af82a..8c73dc6 100644 --- a/test/rules/jsonschema-draft4-to-2020-12.json +++ b/test/rules/jsonschema-draft4-to-2020-12.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2020-12/schema" } }, + { + "name": "draft4 $schema with https scheme", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, + { + "name": "draft4 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, { "name": "draft4 id to $id", "schema": { diff --git a/test/rules/jsonschema-draft4-to-draft6.json b/test/rules/jsonschema-draft4-to-draft6.json index 2dbf04c..d387929 100644 --- a/test/rules/jsonschema-draft4-to-draft6.json +++ b/test/rules/jsonschema-draft4-to-draft6.json @@ -8,6 +8,24 @@ "$schema": "http://json-schema.org/draft-06/schema#" } }, + { + "name": "draft4 $schema with https scheme", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema#" + }, + "expected": { + "$schema": "http://json-schema.org/draft-06/schema#" + } + }, + { + "name": "draft4 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema" + }, + "expected": { + "$schema": "http://json-schema.org/draft-06/schema#" + } + }, { "name": "draft4 id to $id", "schema": { diff --git a/test/rules/jsonschema-draft4-to-draft7.json b/test/rules/jsonschema-draft4-to-draft7.json index cca8d1b..6b7ad36 100644 --- a/test/rules/jsonschema-draft4-to-draft7.json +++ b/test/rules/jsonschema-draft4-to-draft7.json @@ -8,6 +8,24 @@ "$schema": "http://json-schema.org/draft-07/schema#" } }, + { + "name": "draft4 $schema with https scheme", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema#" + }, + "expected": { + "$schema": "http://json-schema.org/draft-07/schema#" + } + }, + { + "name": "draft4 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-04/schema" + }, + "expected": { + "$schema": "http://json-schema.org/draft-07/schema#" + } + }, { "name": "draft4 id to $id", "schema": { diff --git a/test/rules/jsonschema-draft6-to-2019-09.json b/test/rules/jsonschema-draft6-to-2019-09.json index 205294b..e75c8be 100644 --- a/test/rules/jsonschema-draft6-to-2019-09.json +++ b/test/rules/jsonschema-draft6-to-2019-09.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2019-09/schema" } }, + { + "name": "draft6 $schema witgh https scheme", + "schema": { + "$schema": "https://json-schema.org/draft-06/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, + { + "name": "draft6 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-06/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, { "name": "draft6 $id with # to $anchor", "schema": { diff --git a/test/rules/jsonschema-draft6-to-2020-12.json b/test/rules/jsonschema-draft6-to-2020-12.json index 6226beb..bfa8bfc 100644 --- a/test/rules/jsonschema-draft6-to-2020-12.json +++ b/test/rules/jsonschema-draft6-to-2020-12.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2020-12/schema" } }, + { + "name": "draft6 $schema with https scheme", + "schema": { + "$schema": "https://json-schema.org/draft-06/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, + { + "name": "draft6 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-06/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, { "name": "draft6 $id with # to $anchor", "schema": { diff --git a/test/rules/jsonschema-draft6-to-draft7.json b/test/rules/jsonschema-draft6-to-draft7.json index 5ecde0b..3ac517d 100644 --- a/test/rules/jsonschema-draft6-to-draft7.json +++ b/test/rules/jsonschema-draft6-to-draft7.json @@ -8,6 +8,24 @@ "$schema": "http://json-schema.org/draft-07/schema#" } }, + { + "name": "draft6 $schema wituh https scheme", + "schema": { + "$schema": "http://json-schema.org/draft-06/schema#" + }, + "expected": { + "$schema": "http://json-schema.org/draft-07/schema#" + } + }, + { + "name": "draft6 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-06/schema" + }, + "expected": { + "$schema": "http://json-schema.org/draft-07/schema#" + } + }, { "name": "true no metaschema", "schema": {}, diff --git a/test/rules/jsonschema-draft7-to-2019-09.json b/test/rules/jsonschema-draft7-to-2019-09.json index d63e87b..b1c1d02 100644 --- a/test/rules/jsonschema-draft7-to-2019-09.json +++ b/test/rules/jsonschema-draft7-to-2019-09.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2019-09/schema" } }, + { + "name": "draft7 $schema with https scheme", + "schema": { + "$schema": "https://json-schema.org/draft-07/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, + { + "name": "draft7 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-07/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2019-09/schema" + } + }, { "name": "draft7 $id with # to $anchor", "schema": { diff --git a/test/rules/jsonschema-draft7-to-2020-12.json b/test/rules/jsonschema-draft7-to-2020-12.json index 85e6206..8b49bf8 100644 --- a/test/rules/jsonschema-draft7-to-2020-12.json +++ b/test/rules/jsonschema-draft7-to-2020-12.json @@ -8,6 +8,24 @@ "$schema": "https://json-schema.org/draft/2020-12/schema" } }, + { + "name": "draft7 $schema with https scheme", + "schema": { + "$schema": "https://json-schema.org/draft-07/schema#" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, + { + "name": "draft7 $schema without an empty fragment", + "schema": { + "$schema": "http://json-schema.org/draft-07/schema" + }, + "expected": { + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, { "name": "draft7 $id with # to $anchor", "schema": {