Description
In #1434, @karenetheridge left a comment regarding special-casing meta-schema validations. This issue continues that conversation.
When validating a schema with a meta-schema that contains an subschema with a different $schema
value, the meta-schema cannot be expected to validate the entire document. Rather it must only apply to the appropriate portions of the schema.
An example to illustrate the problem:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "base",
"type": "object",
"properties": {
"foo": { "$ref": "foo" }
},
"$defs": {
"foo-def": {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "foo",
"type": "array",
"items": [
{ "type": "string" },
{ "type": "integer" }
]
}
}
}
This schema is valid, but it changes meta-schemas in the foo-def
definition. Validating this as an instance against draft 2020-12 would fail because foo#/items
is the array-form items
which is disallowed in 2020-12.
It's necessary for the validator to have special knowledge that it's processing a meta-schema so that when it encounters a new $schema
it can switch meta-schemas appropriately.
While Core 9.3.3 does address this, does it need to be clearer?
Given that a Compound Schema Document may have embedded resources which identify as using different dialects, these documents SHOULD NOT be validated by applying a meta-schema to the Compound Schema Document as an instance. It is RECOMMENDED that an alternate validation process be provided in order to validate Schema Documents. Each Schema Resource SHOULD be separately validated against its associated meta-schema.
This also ties in a little to Using $schema in JSON documents.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status