alterschema
Version:
Convert between schema specifications
197 lines (196 loc) • 5.28 kB
JSON
{
"walker": "jsonschema-draft7",
"rules": [
{
"vocabulary": "core",
"condition": {
"$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" ],
"properties": {
"$schema": {
"const": "http://json-schema.org/draft-07/schema#"
}
}
},
"transform": {
"$merge": [
{ "$eval": "schema" },
{ "$$schema": "https://json-schema.org/draft/2019-09/schema" }
]
}
},
{
"vocabulary": "core",
"condition": {
"$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" ],
"properties": {
"$id": {
"type": "string",
"pattern": "^#"
}
}
},
"transform": {
"$merge": [
{ "$eval": "omit(schema, '$id')" },
{
"$$anchor": {
"$eval": "schema['$id'][1:]"
}
}
]
}
},
{
"vocabulary": "core",
"condition": {
"$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" ],
"properties": {
"definitions": {
"type": "object"
}
}
},
"transform": {
"$merge": [
{ "$eval": "omit(schema, 'definitions')" },
{
"$$defs": {
"$eval": "schema.definitions"
}
}
]
}
},
{
"vocabulary": "core",
"condition": {
"$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" ],
"properties": {
"$ref": {
"type": "string",
"pattern": "/definitions/"
}
}
},
"transform": {
"$merge": [
{ "$eval": "omit(schema, '$ref')" },
{
"$$ref": {
"$eval": "replace(schema['$ref'], '/definitions/', '/$defs/')"
}
}
]
}
},
{
"vocabulary": "core",
"condition": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/sourcemeta/alterschema/rules/jsonschema-draft7-to-2019-09/empty-object",
"const": {}
},
"transform": {
"$eval": "true"
}
},
{
"vocabulary": "core",
"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 }
},
"transform": {
"$eval": "false"
}
},
{
"vocabulary": "validation",
"condition": {
"$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" ],
"properties": {
"enum": {
"type": "array",
"minItems": 1,
"maxItems": 1
}
}
},
"transform": {
"$merge": [
{ "$eval": "omit(schema, 'enum')" },
{
"const": {
"$eval": "schema.enum[0]"
}
}
]
}
},
{
"vocabulary": "validation",
"condition": {
"$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" ],
"properties": {
"dependencies": {
"type": "object"
}
}
},
"transform": {
"$merge": [
{ "$eval": "omit(schema, 'dependencies')" },
{
"dependentRequired": {
"$map": {
"$eval": "schema.dependencies"
},
"each(v,k)": {
"${k}": {
"$if": "typeof(v) == 'array'",
"then": {
"$eval": "v"
}
}
}
}
},
{
"dependentSchemas": {
"$map": {
"$eval": "schema.dependencies"
},
"each(v,k)": {
"${k}": {
"$if": "typeof(v) == 'object' || typeof(v) == 'boolean'",
"then": {
"$eval": "v"
}
}
}
}
}
]
}
}
]
}