-
Hello. The way the spec describes usage of the Are these cases valid according to the spec? New draft references old draft{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "#/$defs/old",
"$defs": {
"old": {
"$schema": "https://json-schema.org/draft/2019-09",
"type": "string"
}
}
} Will something change if I add Old draft references new draft{
"$schema": "https://json-schema.org/draft/2019-09",
"$ref": "#/$defs/new",
"$defs": {
"new": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
}
}
} New draft references side loaded old draft{
"$schema": "https://json-schema.org/draft/2019-09",
"$id": "https://example.com/old"
"type": "string"
} {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "https://example.com/old"
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
It's pretty confusing, TBH. You can always As of 2020-12, you can have an embedded resource within a document ( So to answer your cases:
|
Beta Was this translation helpful? Give feedback.
-
The Understanding JSON Schema documentation covers this concept in a more approachable way than the spec, https://json-schema.org/understanding-json-schema/structuring.html#bundling. |
Beta Was this translation helpful? Give feedback.
It's pretty confusing, TBH.
You can always
$ref
a separate document that is of a different draft. Each document (file or complete HTTP response, for example) is processed independently, so each is processed by its own$schema
.As of 2020-12, you can have an embedded resource within a document (
$id
in a subschema) with a different$schema
from the root. This is a tricky case to handle, so you need to test the implementations you're using to see if they handle it correctly.So to answer your cases:
$schema
in a random subschema without$id
: Not valid (I think not in any draft, although there might be one where it was a "SHOULD NOT" and the behavior was undefined)$schema
in a subschema with…