UNPKG

alterschema

Version:

Convert between schema specifications

222 lines (221 loc) 5.14 kB
[ { "name": "draft7 $schema", "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": { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "#tag" }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$anchor": "tag" } }, { "name": "draft7 definitions", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "foo": { "type": "string" } } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "foo": { "type": "string" } } } }, { "name": "draft7 definitions", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "foo": { "$ref": "#/definitions/foo" } }, "definitions": { "foo": { "type": "string" } } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": { "$ref": "#/$defs/foo" } }, "$defs": { "foo": { "type": "string" } } } }, { "name": "true no metaschema", "schema": {}, "expected": true }, { "name": "true no metaschema", "schema": { "not": {} }, "expected": false }, { "name": "enum with one value", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "enum": [ "single-value" ] }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "const": "single-value" } }, { "name": "dependencies to dependentRequired and dependentSchemas", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "dependencies": { "foo": { "type": "string" }, "bar": false, "baz": true, "qux": [ "foo" ] } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "dependentSchemas": { "foo": { "type": "string" }, "bar": false, "baz": true }, "dependentRequired": { "qux": [ "foo" ] } } }, { "name": "dependencies to dependentSchemas only", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "dependencies": { "foo": { "type": "string" }, "bar": false, "baz": true } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "dependentSchemas": { "foo": { "type": "string" }, "bar": false, "baz": true } } }, { "name": "dependencies to dependentRequired only", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "dependencies": { "qux": [ "foo" ] } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "dependentRequired": { "qux": [ "foo" ] } } }, { "name": "enum with multiple elements is preserved", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "enum": [ "foo", "bar" ] }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "enum": [ "foo", "bar" ] } }, { "name": "properties with a not: {} schema", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "foo": { "not": {} } } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": false } } }, { "name": "array items within definitions", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "item": { "items": [ { "type": "string" } ] } } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "item": { "prefixItems": [ { "type": "string" } ] } } } }, { "name": "items to prefixItems within $ref", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "items": [ { "type": "integer" }, { "$ref": "#/items/0" } ] }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "prefixItems": [ { "type": "integer" }, { "$ref": "#/prefixItems/0" } ] } }, { "name": "items not to prefixItems within $ref", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "items": { "type": "integer" }, "properties": { "foo": { "$ref": "#/items" } } }, "expected": { "$schema": "https://json-schema.org/draft/2020-12/schema", "items": { "type": "integer" }, "properties": { "foo": { "$ref": "#/items" } } } } ]