JSON-Schema-Test-Suite
JSON-Schema-Test-Suite copied to clipboard
Test for jumping over a resource
trafficstars
Inspired by an example in @jviotti's blog post on dynamic scope, I wondered how different implementations would handle a reference that targeted a resource embedded in another resource and dynamic references were involved.
Example:
{
"$id": "https://example.com/foo",
"type": "object",
"properties": {
"bar-item": { "$ref": "item" }
},
"$defs": {
"bar": {
"$id": "https://example.com/bar",
"type": "array",
"items": { "$ref": "item" },
"$defs": {
"item": {
"$id": "item",
"type": "object",
"properties": {
"content": { "$dynamicRef": "#content" }
},
"$defs": {
"defaultContent": {
"$dynamicAnchor": "content",
"type": "integer"
}
}
},
"content": {
"$dynamicAnchor": "content",
"type": "string"
}
}
}
}
}
I see two possibilities here:
- an implementation includes
barin the dynamic scope and resolves the$dynamicRefto/$defs/bar/$defs/content. - an implementation excludes
barfrom the dynamic scope and resolves the$dynamicRefto/$defs/bar/$defs/item/$defs/defaultContent.
Visually analyzing it, I think the latter is the correct approach, meaning that
{ "bar-item": { "content": 42 } }
is valid, and
{ "bar-item": { "content": "value" } }
is invalid.
This is also how my implementation behaves. I'd like to see how others handle it.