diff --git a/annotations/tests/core.json b/annotations/tests/core.json index 1d8dee55..1b0d1238 100644 --- a/annotations/tests/core.json +++ b/annotations/tests/core.json @@ -25,6 +25,108 @@ ] } ] + }, + { + "description": "`$dynamicRef` resolves to `$dynamicAnchor`", + "compatibility": "2020", + "schema": { + "$dynamicRef": "#foo", + "$defs": { + "foo": { + "$dynamicAnchor": "foo", + "title": "Foo" + } + } + }, + "tests": [ + { + "instance": "bar", + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/$defs/foo": "Foo" + } + } + ] + } + ] + }, + { + "description": "`$dynamicRef` resolves to different `$dynamicAnchor`s depending on dynamic path", + "compatibility": "2020", + "schema": { + "$id": "https://test.json-schema.org/dynamic-ref-annotation/main", + "if": { + "properties": { "kindOfList": { "const": "numbers" } }, + "required": ["kindOfList"] + }, + "then": { "$ref": "numberList" }, + "else": { "$ref": "stringList" }, + "$defs": { + "genericList": { + "$id": "genericList", + "properties": { + "list": { + "items": { "$dynamicRef": "#itemType" } + } + }, + "$defs": { + "defaultItemType": { + "$dynamicAnchor": "itemType" + } + } + }, + "numberList": { + "$id": "numberList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "title": "Number Item" + } + }, + "$ref": "genericList" + }, + "stringList": { + "$id": "stringList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "title": "String Item" + } + }, + "$ref": "genericList" + } + } + }, + "tests": [ + { + "instance": { "kindOfList": "numbers", "list": [1] }, + "assertions": [ + { + "location": "/list/0", + "keyword": "title", + "expected": { + "#/$defs/numberList/$defs/itemType": "Number Item" + } + } + ] + }, + { + "instance": { "kindOfList": "strings", "list": ["foo"] }, + "assertions": [ + { + "location": "/list/0", + "keyword": "title", + "expected": { + "#/$defs/stringList/$defs/itemType": "String Item" + } + } + ] + } + ] } + ] -} +}