Skip to content

Commit eb01855

Browse files
Add annotation tests for $dynamicRef and $dynamicAnchor (#862)
* Add annotation tests for resolving to * Cleanup whitespace --------- Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
1 parent 0a1dc5e commit eb01855

1 file changed

Lines changed: 103 additions & 1 deletion

File tree

annotations/tests/core.json

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,108 @@
2525
]
2626
}
2727
]
28+
},
29+
{
30+
"description": "`$dynamicRef` resolves to `$dynamicAnchor`",
31+
"compatibility": "2020",
32+
"schema": {
33+
"$dynamicRef": "#foo",
34+
"$defs": {
35+
"foo": {
36+
"$dynamicAnchor": "foo",
37+
"title": "Foo"
38+
}
39+
}
40+
},
41+
"tests": [
42+
{
43+
"instance": "bar",
44+
"assertions": [
45+
{
46+
"location": "",
47+
"keyword": "title",
48+
"expected": {
49+
"#/$defs/foo": "Foo"
50+
}
51+
}
52+
]
53+
}
54+
]
55+
},
56+
{
57+
"description": "`$dynamicRef` resolves to different `$dynamicAnchor`s depending on dynamic path",
58+
"compatibility": "2020",
59+
"schema": {
60+
"$id": "https://test.json-schema.org/dynamic-ref-annotation/main",
61+
"if": {
62+
"properties": { "kindOfList": { "const": "numbers" } },
63+
"required": ["kindOfList"]
64+
},
65+
"then": { "$ref": "numberList" },
66+
"else": { "$ref": "stringList" },
67+
"$defs": {
68+
"genericList": {
69+
"$id": "genericList",
70+
"properties": {
71+
"list": {
72+
"items": { "$dynamicRef": "#itemType" }
73+
}
74+
},
75+
"$defs": {
76+
"defaultItemType": {
77+
"$dynamicAnchor": "itemType"
78+
}
79+
}
80+
},
81+
"numberList": {
82+
"$id": "numberList",
83+
"$defs": {
84+
"itemType": {
85+
"$dynamicAnchor": "itemType",
86+
"title": "Number Item"
87+
}
88+
},
89+
"$ref": "genericList"
90+
},
91+
"stringList": {
92+
"$id": "stringList",
93+
"$defs": {
94+
"itemType": {
95+
"$dynamicAnchor": "itemType",
96+
"title": "String Item"
97+
}
98+
},
99+
"$ref": "genericList"
100+
}
101+
}
102+
},
103+
"tests": [
104+
{
105+
"instance": { "kindOfList": "numbers", "list": [1] },
106+
"assertions": [
107+
{
108+
"location": "/list/0",
109+
"keyword": "title",
110+
"expected": {
111+
"#/$defs/numberList/$defs/itemType": "Number Item"
112+
}
113+
}
114+
]
115+
},
116+
{
117+
"instance": { "kindOfList": "strings", "list": ["foo"] },
118+
"assertions": [
119+
{
120+
"location": "/list/0",
121+
"keyword": "title",
122+
"expected": {
123+
"#/$defs/stringList/$defs/itemType": "String Item"
124+
}
125+
}
126+
]
127+
}
128+
]
28129
}
130+
29131
]
30-
}
132+
}

0 commit comments

Comments
 (0)