alterschema
Version:
Convert between schema specifications
188 lines (187 loc) • 4.36 kB
JSON
[
{
"name": "draft6 $schema",
"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": {
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "#tag"
},
"expected": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$anchor": "tag"
}
},
{
"name": "draft6 definitions",
"schema": {
"$schema": "http://json-schema.org/draft-06/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-06/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-06/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-06/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-06/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-06/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-06/schema#",
"properties": {
"foo": {
"not": {}
}
}
},
"expected": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": false
}
}
},
{
"name": "items to prefixItems within $ref",
"schema": {
"$schema": "http://json-schema.org/draft-06/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-06/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" }
}
}
}
]