-
Hello! I'm trying to understand dynamic scope and references better. I want to be sure I understand it correctly using following official test case as an example: {
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/root",
"$ref": "intermediate-scope",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"intermediate-scope": {
"$id": "intermediate-scope",
"$ref": "list"
},
"list": {
"$id": "list",
"type": "array",
"items": {
"$dynamicRef": "#items"
},
"$defs": {
"items": {
"$comment": "This is only needed to satisfy the bookending requirement",
"$dynamicAnchor": "items"
}
}
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": [
"foo",
"bar"
],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": [
"foo",
42
],
"valid": false
}
]
} My implementation starts processing the document step-by-step, which produces following stack (inspired by "JSON Schema as a Framework" slides, part 2):
After that, it meets As I understand from the slides, my implementation should go back down the stack:
Stack is over. The last dynamic schema in the stack it found is |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, you want the outermost (first stack frame/dynamic scope encountered) match, and that is the |
Beta Was this translation helpful? Give feedback.
Yes, you want the outermost (first stack frame/dynamic scope encountered) match, and that is the
.../root#items