A dynamic reference is like a dynamic variable in a programming language, with two twists: - There must be a dynamic anchor in lexical scope for the ref to resolve. (Think of it as declaring the dynamic variable.) - The ref resolves to the schema highest on the stack, not lowest. That feels odd, but it turns out to work for the intended purpose, which is to provide extension points for additional features. There is some distracting code motion and refactoring in this CL: resolveRefs was moved down in the file, and resolution of a single ref was split off. Change-Id: I17da6052e0782fc540d14b8a41b06a2645923872 Reviewed-on: https://go-review.googlesource.com/c/tools/+/674155 Auto-Submit: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
120 lines
3.4 KiB
JSON
120 lines
3.4 KiB
JSON
[
|
|
{
|
|
"description": "Location-independent identifier",
|
|
"schema": {
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$ref": "#foo",
|
|
"$defs": {
|
|
"A": {
|
|
"$anchor": "foo",
|
|
"type": "integer"
|
|
}
|
|
}
|
|
},
|
|
"tests": [
|
|
{
|
|
"data": 1,
|
|
"description": "match",
|
|
"valid": true
|
|
},
|
|
{
|
|
"data": "a",
|
|
"description": "mismatch",
|
|
"valid": false
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "Location-independent identifier with absolute URI",
|
|
"schema": {
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$ref": "http://localhost:1234/draft2020-12/bar#foo",
|
|
"$defs": {
|
|
"A": {
|
|
"$id": "http://localhost:1234/draft2020-12/bar",
|
|
"$anchor": "foo",
|
|
"type": "integer"
|
|
}
|
|
}
|
|
},
|
|
"tests": [
|
|
{
|
|
"data": 1,
|
|
"description": "match",
|
|
"valid": true
|
|
},
|
|
{
|
|
"data": "a",
|
|
"description": "mismatch",
|
|
"valid": false
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "Location-independent identifier with base URI change in subschema",
|
|
"schema": {
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$id": "http://localhost:1234/draft2020-12/root",
|
|
"$ref": "http://localhost:1234/draft2020-12/nested.json#foo",
|
|
"$defs": {
|
|
"A": {
|
|
"$id": "nested.json",
|
|
"$defs": {
|
|
"B": {
|
|
"$anchor": "foo",
|
|
"type": "integer"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"tests": [
|
|
{
|
|
"data": 1,
|
|
"description": "match",
|
|
"valid": true
|
|
},
|
|
{
|
|
"data": "a",
|
|
"description": "mismatch",
|
|
"valid": false
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "same $anchor with different base uri",
|
|
"schema": {
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$id": "http://localhost:1234/draft2020-12/foobar",
|
|
"$defs": {
|
|
"A": {
|
|
"$id": "child1",
|
|
"allOf": [
|
|
{
|
|
"$id": "child2",
|
|
"$anchor": "my_anchor",
|
|
"type": "number"
|
|
},
|
|
{
|
|
"$anchor": "my_anchor",
|
|
"type": "string"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"$ref": "child1#my_anchor"
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "$ref resolves to /$defs/A/allOf/1",
|
|
"data": "a",
|
|
"valid": true
|
|
},
|
|
{
|
|
"description": "$ref does not resolve to /$defs/A/allOf/0",
|
|
"data": 1,
|
|
"valid": false
|
|
}
|
|
]
|
|
}
|
|
]
|