Debian Codegraph @

share/tests/v1/dynamicRef.json

raw
1 [
2 {
3 "description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
4 "schema": {
5 "$schema": "https://json-schema.org/v1",
6 "$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root",
7 "type": "array",
8 "items": { "$dynamicRef": "#items" },
9 "$defs": {
10 "foo": {
11 "$dynamicAnchor": "items",
12 "type": "string"
13 }
14 }
15 },
16 "tests": [
17 {
18 "description": "An array of strings is valid",
19 "data": ["foo", "bar"],
20 "valid": true
21 },
22 {
23 "description": "An array containing non-strings is invalid",
24 "data": ["foo", 42],
25 "valid": false
26 }
27 ]
28 },
29 {
30 "description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
31 "schema": {
32 "$schema": "https://json-schema.org/v1",
33 "$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
34 "$ref": "list",
35 "$defs": {
36 "foo": {
37 "$dynamicAnchor": "items",
38 "type": "string"
39 },
40 "list": {
41 "$id": "list",
42 "type": "array",
43 "items": { "$dynamicRef": "#items" }
44 }
45 }
46 },
47 "tests": [
48 {
49 "description": "An array of strings is valid",
50 "data": ["foo", "bar"],
51 "valid": true
52 },
53 {
54 "description": "An array containing non-strings is invalid",
55 "data": ["foo", 42],
56 "valid": false
57 }
58 ]
59 },
60 {
61 "description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution",
62 "schema": {
63 "$schema": "https://json-schema.org/v1",
64 "$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root",
65 "$ref": "intermediate-scope",
66 "$defs": {
67 "foo": {
68 "$dynamicAnchor": "items",
69 "type": "string"
70 },
71 "intermediate-scope": {
72 "$id": "intermediate-scope",
73 "$ref": "list"
74 },
75 "list": {
76 "$id": "list",
77 "type": "array",
78 "items": { "$dynamicRef": "#items" }
79 }
80 }
81 },
82 "tests": [
83 {
84 "description": "An array of strings is valid",
85 "data": ["foo", "bar"],
86 "valid": true
87 },
88 {
89 "description": "An array containing non-strings is invalid",
90 "data": ["foo", 42],
91 "valid": false
92 }
93 ]
94 },
95 {
96 "description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution",
97 "schema": {
98 "$schema": "https://json-schema.org/v1",
99 "$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root",
100 "$ref": "list",
101 "$defs": {
102 "foo": {
103 "$anchor": "items",
104 "type": "string"
105 },
106 "list": {
107 "$id": "list",
108 "type": "array",
109 "items": { "$dynamicRef": "#items" },
110 "$defs": {
111 "items": {
112 "$dynamicAnchor": "items"
113 }
114 }
115 }
116 }
117 },
118 "tests": [
119 {
120 "description": "Any array is valid",
121 "data": ["foo", 42],
122 "valid": true
123 }
124 ]
125 },
126 {
127 "description": "after leaving a dynamic scope, it is not used by a $dynamicRef",
128 "schema": {
129 "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main",
130 "if": {
131 "$id": "first_scope",
132 "$defs": {
133 "thingy": {
134 "$comment": "this is first_scope#thingy",
135 "$dynamicAnchor": "thingy",
136 "type": "number"
137 }
138 }
139 },
140 "then": {
141 "$id": "second_scope",
142 "$ref": "start",
143 "$defs": {
144 "thingy": {
145 "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef",
146 "$dynamicAnchor": "thingy",
147 "type": "null"
148 }
149 }
150 },
151 "$defs": {
152 "start": {
153 "$comment": "this is the landing spot from $ref",
154 "$id": "start",
155 "$ref": "inner_scope"
156 },
157 "thingy": {
158 "$id": "inner_scope",
159 "$dynamicRef": "#thingy",
160 "$defs": {
161 "": {
162 "$comment": "this is the first stop for the $dynamicRef",
163 "$dynamicAnchor": "thingy",
164 "type": "string"
165 }
166 }
167 }
168 }
169 },
170 "tests": [
171 {
172 "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here",
173 "data": "a string",
174 "valid": false
175 },
176 {
177 "description": "first_scope is not in dynamic scope for the $dynamicRef",
178 "data": 42,
179 "valid": false
180 },
181 {
182 "description": "/then/$defs/thingy is the final stop for the $dynamicRef",
183 "data": null,
184 "valid": true
185 }
186 ]
187 },
188 {
189 "description": "strict-tree schema, guards against misspelled properties",
190 "schema": {
191 "$schema": "https://json-schema.org/v1",
192 "$id": "http://localhost:1234/v1/strict-tree.json",
193 "$dynamicAnchor": "node",
194
195 "$ref": "tree.json",
196 "unevaluatedProperties": false
197 },
198 "tests": [
199 {
200 "description": "instance with misspelled field",
201 "data": {
202 "children": [{
203 "daat": 1
204 }]
205 },
206 "valid": false
207 },
208 {
209 "description": "instance with correct field",
210 "data": {
211 "children": [{
212 "data": 1
213 }]
214 },
215 "valid": true
216 }
217 ]
218 },
219 {
220 "description": "tests for implementation dynamic anchor and reference link",
221 "schema": {
222 "$schema": "https://json-schema.org/v1",
223 "$id": "http://localhost:1234/v1/strict-extendible.json",
224 "$ref": "extendible-dynamic-ref.json",
225 "$defs": {
226 "elements": {
227 "$dynamicAnchor": "elements",
228 "properties": {
229 "a": true
230 },
231 "required": ["a"],
232 "additionalProperties": false
233 }
234 }
235 },
236 "tests": [
237 {
238 "description": "incorrect parent schema",
239 "data": {
240 "a": true
241 },
242 "valid": false
243 },
244 {
245 "description": "incorrect extended schema",
246 "data": {
247 "elements": [
248 { "b": 1 }
249 ]
250 },
251 "valid": false
252 },
253 {
254 "description": "correct extended schema",
255 "data": {
256 "elements": [
257 { "a": 1 }
258 ]
259 },
260 "valid": true
261 }
262 ]
263 },
264 {
265 "description": "$ref and $dynamicAnchor are independent of order - $defs first",
266 "schema": {
267 "$schema": "https://json-schema.org/v1",
268 "$id": "http://localhost:1234/v1/strict-extendible-allof-defs-first.json",
269 "allOf": [
270 {
271 "$ref": "extendible-dynamic-ref.json"
272 },
273 {
274 "$defs": {
275 "elements": {
276 "$dynamicAnchor": "elements",
277 "properties": {
278 "a": true
279 },
280 "required": ["a"],
281 "additionalProperties": false
282 }
283 }
284 }
285 ]
286 },
287 "tests": [
288 {
289 "description": "incorrect parent schema",
290 "data": {
291 "a": true
292 },
293 "valid": false
294 },
295 {
296 "description": "incorrect extended schema",
297 "data": {
298 "elements": [
299 { "b": 1 }
300 ]
301 },
302 "valid": false
303 },
304 {
305 "description": "correct extended schema",
306 "data": {
307 "elements": [
308 { "a": 1 }
309 ]
310 },
311 "valid": true
312 }
313 ]
314 },
315 {
316 "description": "$ref and $dynamicAnchor are independent of order - $ref first",
317 "schema": {
318 "$schema": "https://json-schema.org/v1",
319 "$id": "http://localhost:1234/v1/strict-extendible-allof-ref-first.json",
320 "allOf": [
321 {
322 "$defs": {
323 "elements": {
324 "$dynamicAnchor": "elements",
325 "properties": {
326 "a": true
327 },
328 "required": ["a"],
329 "additionalProperties": false
330 }
331 }
332 },
333 {
334 "$ref": "extendible-dynamic-ref.json"
335 }
336 ]
337 },
338 "tests": [
339 {
340 "description": "incorrect parent schema",
341 "data": {
342 "a": true
343 },
344 "valid": false
345 },
346 {
347 "description": "incorrect extended schema",
348 "data": {
349 "elements": [
350 { "b": 1 }
351 ]
352 },
353 "valid": false
354 },
355 {
356 "description": "correct extended schema",
357 "data": {
358 "elements": [
359 { "a": 1 }
360 ]
361 },
362 "valid": true
363 }
364 ]
365 },
366 {
367 "description": "$ref to $dynamicRef finds detached $dynamicAnchor",
368 "schema": {
369 "$ref": "http://localhost:1234/v1/detached-dynamicref.json#/$defs/foo"
370 },
371 "tests": [
372 {
373 "description": "number is valid",
374 "data": 1,
375 "valid": true
376 },
377 {
378 "description": "non-number is invalid",
379 "data": "a",
380 "valid": false
381 }
382 ]
383 },
384 {
385 "description": "$dynamicRef skips over intermediate resources - direct reference",
386 "schema": {
387 "$schema": "https://json-schema.org/v1",
388 "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main",
389 "type": "object",
390 "properties": {
391 "bar-item": {
392 "$ref": "item"
393 }
394 },
395 "$defs": {
396 "bar": {
397 "$id": "bar",
398 "type": "array",
399 "items": {
400 "$ref": "item"
401 },
402 "$defs": {
403 "item": {
404 "$id": "item",
405 "type": "object",
406 "properties": {
407 "content": {
408 "$dynamicRef": "#content"
409 }
410 },
411 "$defs": {
412 "defaultContent": {
413 "$dynamicAnchor": "content",
414 "type": "integer"
415 }
416 }
417 },
418 "content": {
419 "$dynamicAnchor": "content",
420 "type": "string"
421 }
422 }
423 }
424 }
425 },
426 "tests": [
427 {
428 "description": "integer property passes",
429 "data": { "bar-item": { "content": 42 } },
430 "valid": true
431 },
432 {
433 "description": "string property fails",
434 "data": { "bar-item": { "content": "value" } },
435 "valid": false
436 }
437 ]
438 },
439 {
440 "description": "$dynamicRef avoids the root of each schema, but scopes are still registered",
441 "schema": {
442 "$schema": "https://json-schema.org/v1",
443 "$id": "https://test.json-schema.org/dynamic-ref-avoids-root-of-each-schema/base",
444 "$ref": "first#/$defs/stuff",
445 "$defs": {
446 "first": {
447 "$id": "first",
448 "$defs": {
449 "stuff": {
450 "$ref": "second#/$defs/stuff"
451 },
452 "length": {
453 "$comment": "unused, because there is no $dynamicAnchor here",
454 "maxLength": 1
455 }
456 }
457 },
458 "second": {
459 "$id": "second",
460 "$defs": {
461 "stuff": {
462 "$ref": "third#/$defs/stuff"
463 },
464 "length": {
465 "$dynamicAnchor": "length",
466 "maxLength": 2
467 }
468 }
469 },
470 "third": {
471 "$id": "third",
472 "$defs": {
473 "stuff": {
474 "$dynamicRef": "#length"
475 },
476 "length": {
477 "$dynamicAnchor": "length",
478 "maxLength": 3
479 }
480 }
481 }
482 }
483 },
484 "tests": [
485 {
486 "description": "data is sufficient for schema at second#/$defs/length",
487 "data": "hi",
488 "valid": true
489 },
490 {
491 "description": "data is not sufficient for schema at second#/$defs/length",
492 "data": "hey",
493 "valid": false
494 }
495 ]
496 }
497 ]