| •1 |
[ |
| 2 |
{ |
| 3 |
"description": "A $dynamicRef to a $dynamicAnchor in the same schema resource should behave like a normal $ref to an $anchor", |
| 4 |
"schema": { |
| 5 |
"$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root", |
| 6 |
"type": "array", |
| 7 |
"items": { "$dynamicRef": "#items" }, |
| 8 |
"$defs": { |
| 9 |
"foo": { |
| 10 |
"$dynamicAnchor": "items", |
| 11 |
"type": "string" |
| 12 |
} |
| 13 |
} |
| 14 |
}, |
| 15 |
"tests": [ |
| 16 |
{ |
| 17 |
"description": "An array of strings is valid", |
| 18 |
"data": ["foo", "bar"], |
| 19 |
"valid": true |
| 20 |
}, |
| 21 |
{ |
| 22 |
"description": "An array containing non-strings is invalid", |
| 23 |
"data": ["foo", 42], |
| 24 |
"valid": false |
| 25 |
} |
| 26 |
] |
| 27 |
}, |
| 28 |
{ |
| 29 |
"description": "A $dynamicRef to an $anchor in the same schema resource should behave like a normal $ref to an $anchor", |
| 30 |
"schema": { |
| 31 |
"$id": "https://test.json-schema.org/dynamicRef-anchor-same-schema/root", |
| 32 |
"type": "array", |
| 33 |
"items": { "$dynamicRef": "#items" }, |
| 34 |
"$defs": { |
| 35 |
"foo": { |
| 36 |
"$anchor": "items", |
| 37 |
"type": "string" |
| 38 |
} |
| 39 |
} |
| 40 |
}, |
| 41 |
"tests": [ |
| 42 |
{ |
| 43 |
"description": "An array of strings is valid", |
| 44 |
"data": ["foo", "bar"], |
| 45 |
"valid": true |
| 46 |
}, |
| 47 |
{ |
| 48 |
"description": "An array containing non-strings is invalid", |
| 49 |
"data": ["foo", 42], |
| 50 |
"valid": false |
| 51 |
} |
| 52 |
] |
| 53 |
}, |
| 54 |
{ |
| 55 |
"description": "A $ref to a $dynamicAnchor in the same schema resource should behave like a normal $ref to an $anchor", |
| 56 |
"schema": { |
| 57 |
"$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root", |
| 58 |
"type": "array", |
| 59 |
"items": { "$ref": "#items" }, |
| 60 |
"$defs": { |
| 61 |
"foo": { |
| 62 |
"$dynamicAnchor": "items", |
| 63 |
"type": "string" |
| 64 |
} |
| 65 |
} |
| 66 |
}, |
| 67 |
"tests": [ |
| 68 |
{ |
| 69 |
"description": "An array of strings is valid", |
| 70 |
"data": ["foo", "bar"], |
| 71 |
"valid": true |
| 72 |
}, |
| 73 |
{ |
| 74 |
"description": "An array containing non-strings is invalid", |
| 75 |
"data": ["foo", 42], |
| 76 |
"valid": false |
| 77 |
} |
| 78 |
] |
| 79 |
}, |
| 80 |
{ |
| 81 |
"description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated", |
| 82 |
"schema": { |
| 83 |
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root", |
| 84 |
"$ref": "list", |
| 85 |
"$defs": { |
| 86 |
"foo": { |
| 87 |
"$dynamicAnchor": "items", |
| 88 |
"type": "string" |
| 89 |
}, |
| 90 |
"list": { |
| 91 |
"$id": "list", |
| 92 |
"type": "array", |
| 93 |
"items": { "$dynamicRef": "#items" }, |
| 94 |
"$defs": { |
| 95 |
"items": { |
| 96 |
"$comment": "This is only needed to satisfy the bookending requirement", |
| 97 |
"$dynamicAnchor": "items" |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
}, |
| 103 |
"tests": [ |
| 104 |
{ |
| 105 |
"description": "An array of strings is valid", |
| 106 |
"data": ["foo", "bar"], |
| 107 |
"valid": true |
| 108 |
}, |
| 109 |
{ |
| 110 |
"description": "An array containing non-strings is invalid", |
| 111 |
"data": ["foo", 42], |
| 112 |
"valid": false |
| 113 |
} |
| 114 |
] |
| 115 |
}, |
| 116 |
{ |
| 117 |
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor should not affect dynamic scope resolution", |
| 118 |
"schema": { |
| 119 |
"$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root", |
| 120 |
"$ref": "intermediate-scope", |
| 121 |
"$defs": { |
| 122 |
"foo": { |
| 123 |
"$dynamicAnchor": "items", |
| 124 |
"type": "string" |
| 125 |
}, |
| 126 |
"intermediate-scope": { |
| 127 |
"$id": "intermediate-scope", |
| 128 |
"$ref": "list" |
| 129 |
}, |
| 130 |
"list": { |
| 131 |
"$id": "list", |
| 132 |
"type": "array", |
| 133 |
"items": { "$dynamicRef": "#items" }, |
| 134 |
"$defs": { |
| 135 |
"items": { |
| 136 |
"$comment": "This is only needed to satisfy the bookending requirement", |
| 137 |
"$dynamicAnchor": "items" |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
}, |
| 143 |
"tests": [ |
| 144 |
{ |
| 145 |
"description": "An array of strings is valid", |
| 146 |
"data": ["foo", "bar"], |
| 147 |
"valid": true |
| 148 |
}, |
| 149 |
{ |
| 150 |
"description": "An array containing non-strings is invalid", |
| 151 |
"data": ["foo", 42], |
| 152 |
"valid": false |
| 153 |
} |
| 154 |
] |
| 155 |
}, |
| 156 |
{ |
| 157 |
"description": "An $anchor with the same name as a $dynamicAnchor should not be used for dynamic scope resolution", |
| 158 |
"schema": { |
| 159 |
"$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root", |
| 160 |
"$ref": "list", |
| 161 |
"$defs": { |
| 162 |
"foo": { |
| 163 |
"$anchor": "items", |
| 164 |
"type": "string" |
| 165 |
}, |
| 166 |
"list": { |
| 167 |
"$id": "list", |
| 168 |
"type": "array", |
| 169 |
"items": { "$dynamicRef": "#items" }, |
| 170 |
"$defs": { |
| 171 |
"items": { |
| 172 |
"$comment": "This is only needed to satisfy the bookending requirement", |
| 173 |
"$dynamicAnchor": "items" |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
}, |
| 179 |
"tests": [ |
| 180 |
{ |
| 181 |
"description": "Any array is valid", |
| 182 |
"data": ["foo", 42], |
| 183 |
"valid": true |
| 184 |
} |
| 185 |
] |
| 186 |
}, |
| 187 |
{ |
| 188 |
"description": "A $dynamicRef without a matching $dynamicAnchor in the same schema resource should behave like a normal $ref to $anchor", |
| 189 |
"schema": { |
| 190 |
"$id": "https://test.json-schema.org/dynamic-resolution-without-bookend/root", |
| 191 |
"$ref": "list", |
| 192 |
"$defs": { |
| 193 |
"foo": { |
| 194 |
"$dynamicAnchor": "items", |
| 195 |
"type": "string" |
| 196 |
}, |
| 197 |
"list": { |
| 198 |
"$id": "list", |
| 199 |
"type": "array", |
| 200 |
"items": { "$dynamicRef": "#items" }, |
| 201 |
"$defs": { |
| 202 |
"items": { |
| 203 |
"$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", |
| 204 |
"$anchor": "items" |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
}, |
| 210 |
"tests": [ |
| 211 |
{ |
| 212 |
"description": "Any array is valid", |
| 213 |
"data": ["foo", 42], |
| 214 |
"valid": true |
| 215 |
} |
| 216 |
] |
| 217 |
}, |
| 218 |
{ |
| 219 |
"description": "A $dynamicRef with a non-matching $dynamicAnchor in the same schema resource should behave like a normal $ref to $anchor", |
| 220 |
"schema": { |
| 221 |
"$id": "https://test.json-schema.org/unmatched-dynamic-anchor/root", |
| 222 |
"$ref": "list", |
| 223 |
"$defs": { |
| 224 |
"foo": { |
| 225 |
"$dynamicAnchor": "items", |
| 226 |
"type": "string" |
| 227 |
}, |
| 228 |
"list": { |
| 229 |
"$id": "list", |
| 230 |
"type": "array", |
| 231 |
"items": { "$dynamicRef": "#items" }, |
| 232 |
"$defs": { |
| 233 |
"items": { |
| 234 |
"$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", |
| 235 |
"$anchor": "items", |
| 236 |
"$dynamicAnchor": "foo" |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
}, |
| 242 |
"tests": [ |
| 243 |
{ |
| 244 |
"description": "Any array is valid", |
| 245 |
"data": ["foo", 42], |
| 246 |
"valid": true |
| 247 |
} |
| 248 |
] |
| 249 |
}, |
| 250 |
{ |
| 251 |
"description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor should resolve to the first $dynamicAnchor in the dynamic scope", |
| 252 |
"schema": { |
| 253 |
"$id": "https://test.json-schema.org/relative-dynamic-reference/root", |
| 254 |
"$dynamicAnchor": "meta", |
| 255 |
"type": "object", |
| 256 |
"properties": { |
| 257 |
"foo": { "const": "pass" } |
| 258 |
}, |
| 259 |
"$ref": "extended", |
| 260 |
"$defs": { |
| 261 |
"extended": { |
| 262 |
"$id": "extended", |
| 263 |
"$dynamicAnchor": "meta", |
| 264 |
"type": "object", |
| 265 |
"properties": { |
| 266 |
"bar": { "$ref": "bar" } |
| 267 |
} |
| 268 |
}, |
| 269 |
"bar": { |
| 270 |
"$id": "bar", |
| 271 |
"type": "object", |
| 272 |
"properties": { |
| 273 |
"baz": { "$dynamicRef": "extended#meta" } |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
}, |
| 278 |
"tests": [ |
| 279 |
{ |
| 280 |
"description": "The recursive part is valid against the root", |
| 281 |
"data": { |
| 282 |
"foo": "pass", |
| 283 |
"bar": { |
| 284 |
"baz": { "foo": "pass" } |
| 285 |
} |
| 286 |
}, |
| 287 |
"valid": true |
| 288 |
}, |
| 289 |
{ |
| 290 |
"description": "The recursive part is not valid against the root", |
| 291 |
"data": { |
| 292 |
"foo": "pass", |
| 293 |
"bar": { |
| 294 |
"baz": { "foo": "fail" } |
| 295 |
} |
| 296 |
}, |
| 297 |
"valid": false |
| 298 |
} |
| 299 |
] |
| 300 |
}, |
| 301 |
{ |
| 302 |
"description": "A $dynamicRef that initially resolves to a schema without a matching $dynamicAnchor should behave like a normal $ref to $anchor", |
| 303 |
"schema": { |
| 304 |
"$id": "https://test.json-schema.org/relative-dynamic-reference-without-bookend/root", |
| 305 |
"$dynamicAnchor": "meta", |
| 306 |
"type": "object", |
| 307 |
"properties": { |
| 308 |
"foo": { "const": "pass" } |
| 309 |
}, |
| 310 |
"$ref": "extended", |
| 311 |
"$defs": { |
| 312 |
"extended": { |
| 313 |
"$id": "extended", |
| 314 |
"$anchor": "meta", |
| 315 |
"type": "object", |
| 316 |
"properties": { |
| 317 |
"bar": { "$ref": "bar" } |
| 318 |
} |
| 319 |
}, |
| 320 |
"bar": { |
| 321 |
"$id": "bar", |
| 322 |
"type": "object", |
| 323 |
"properties": { |
| 324 |
"baz": { "$dynamicRef": "extended#meta" } |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
}, |
| 329 |
"tests": [ |
| 330 |
{ |
| 331 |
"description": "The recursive part doesn't need to validate against the root", |
| 332 |
"data": { |
| 333 |
"foo": "pass", |
| 334 |
"bar": { |
| 335 |
"baz": { "foo": "fail" } |
| 336 |
} |
| 337 |
}, |
| 338 |
"valid": true |
| 339 |
} |
| 340 |
] |
| 341 |
}, |
| 342 |
{ |
| 343 |
"description": "multiple dynamic paths to the $dynamicRef keyword", |
| 344 |
"schema": { |
| 345 |
"$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", |
| 346 |
"$defs": { |
| 347 |
"inner": { |
| 348 |
"$id": "inner", |
| 349 |
"$dynamicAnchor": "foo", |
| 350 |
"title": "inner", |
| 351 |
"additionalProperties": { |
| 352 |
"$dynamicRef": "#foo" |
| 353 |
} |
| 354 |
} |
| 355 |
}, |
| 356 |
"if": { |
| 357 |
"propertyNames": { |
| 358 |
"pattern": "^[a-m]" |
| 359 |
} |
| 360 |
}, |
| 361 |
"then": { |
| 362 |
"title": "any type of node", |
| 363 |
"$id": "anyLeafNode", |
| 364 |
"$dynamicAnchor": "foo", |
| 365 |
"$ref": "main#/$defs/inner" |
| 366 |
}, |
| 367 |
"else": { |
| 368 |
"title": "integer node", |
| 369 |
"$id": "integerNode", |
| 370 |
"$dynamicAnchor": "foo", |
| 371 |
"type": [ "object", "integer" ], |
| 372 |
"$ref": "main#/$defs/inner" |
| 373 |
} |
| 374 |
}, |
| 375 |
"tests": [ |
| 376 |
{ |
| 377 |
"description": "recurse to anyLeafNode - floats are allowed", |
| 378 |
"data": { "alpha": 1.1 }, |
| 379 |
"valid": true |
| 380 |
}, |
| 381 |
{ |
| 382 |
"description": "recurse to integerNode - floats are not allowed", |
| 383 |
"data": { "november": 1.1 }, |
| 384 |
"valid": false |
| 385 |
} |
| 386 |
] |
| 387 |
}, |
| 388 |
{ |
| 389 |
"description": "after leaving a dynamic scope, it should not be used by a $dynamicRef", |
| 390 |
"schema": { |
| 391 |
"$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main", |
| 392 |
"if": { |
| 393 |
"$id": "first_scope", |
| 394 |
"$defs": { |
| 395 |
"thingy": { |
| 396 |
"$comment": "this is first_scope#thingy", |
| 397 |
"$dynamicAnchor": "thingy", |
| 398 |
"type": "number" |
| 399 |
} |
| 400 |
} |
| 401 |
}, |
| 402 |
"then": { |
| 403 |
"$id": "second_scope", |
| 404 |
"$ref": "start", |
| 405 |
"$defs": { |
| 406 |
"thingy": { |
| 407 |
"$comment": "this is second_scope#thingy, the final destination of the $dynamicRef", |
| 408 |
"$dynamicAnchor": "thingy", |
| 409 |
"type": "null" |
| 410 |
} |
| 411 |
} |
| 412 |
}, |
| 413 |
"$defs": { |
| 414 |
"start": { |
| 415 |
"$comment": "this is the landing spot from $ref", |
| 416 |
"$id": "start", |
| 417 |
"$dynamicRef": "inner_scope#thingy" |
| 418 |
}, |
| 419 |
"thingy": { |
| 420 |
"$comment": "this is the first stop for the $dynamicRef", |
| 421 |
"$id": "inner_scope", |
| 422 |
"$dynamicAnchor": "thingy", |
| 423 |
"type": "string" |
| 424 |
} |
| 425 |
} |
| 426 |
}, |
| 427 |
"tests": [ |
| 428 |
{ |
| 429 |
"description": "string matches /$defs/thingy, but the $dynamicRef does not stop here", |
| 430 |
"data": "a string", |
| 431 |
"valid": false |
| 432 |
}, |
| 433 |
{ |
| 434 |
"description": "first_scope is not in dynamic scope for the $dynamicRef", |
| 435 |
"data": 42, |
| 436 |
"valid": false |
| 437 |
}, |
| 438 |
{ |
| 439 |
"description": "/then/$defs/thingy is the final stop for the $dynamicRef", |
| 440 |
"data": null, |
| 441 |
"valid": true |
| 442 |
} |
| 443 |
] |
| 444 |
}, |
| 445 |
{ |
| 446 |
"description": "strict-tree schema, guards against misspelled properties", |
| 447 |
"schema": { |
| 448 |
"$id": "http://localhost:1234/strict-tree.json", |
| 449 |
"$dynamicAnchor": "node", |
| 450 |
|
| 451 |
"$ref": "tree.json", |
| 452 |
"unevaluatedProperties": false |
| 453 |
}, |
| 454 |
"tests": [ |
| 455 |
{ |
| 456 |
"description": "instance with misspelled field", |
| 457 |
"data": { |
| 458 |
"children": [{ |
| 459 |
"daat": 1 |
| 460 |
}] |
| 461 |
}, |
| 462 |
"valid": false |
| 463 |
}, |
| 464 |
{ |
| 465 |
"description": "instance with correct field", |
| 466 |
"data": { |
| 467 |
"children": [{ |
| 468 |
"data": 1 |
| 469 |
}] |
| 470 |
}, |
| 471 |
"valid": true |
| 472 |
} |
| 473 |
] |
| 474 |
}, |
| 475 |
{ |
| 476 |
"description": "tests for implementation dynamic anchor and reference link", |
| 477 |
"schema": { |
| 478 |
"$id": "http://localhost:1234/strict-extendible.json", |
| 479 |
"$ref": "extendible-dynamic-ref.json", |
| 480 |
"$defs": { |
| 481 |
"elements": { |
| 482 |
"$dynamicAnchor": "elements", |
| 483 |
"properties": { |
| 484 |
"a": true |
| 485 |
}, |
| 486 |
"required": ["a"], |
| 487 |
"additionalProperties": false |
| 488 |
} |
| 489 |
} |
| 490 |
}, |
| 491 |
"tests": [ |
| 492 |
{ |
| 493 |
"description": "incorrect parent schema", |
| 494 |
"data": { |
| 495 |
"a": true |
| 496 |
}, |
| 497 |
"valid": false |
| 498 |
}, |
| 499 |
{ |
| 500 |
"description": "incorrect extended schema", |
| 501 |
"data": { |
| 502 |
"elements": [ |
| 503 |
{ "b": 1 } |
| 504 |
] |
| 505 |
}, |
| 506 |
"valid": false |
| 507 |
}, |
| 508 |
{ |
| 509 |
"description": "correct extended schema", |
| 510 |
"data": { |
| 511 |
"elements": [ |
| 512 |
{ "a": 1 } |
| 513 |
] |
| 514 |
}, |
| 515 |
"valid": true |
| 516 |
} |
| 517 |
] |
| 518 |
}, |
| 519 |
{ |
| 520 |
"description": "Tests for implementation dynamic anchor and reference link. Reference should be independent of any possible ordering.", |
| 521 |
"schema": { |
| 522 |
"$id": "http://localhost:1234/strict-extendible-allof-defs-first.json", |
| 523 |
"allOf": [ |
| 524 |
{ |
| 525 |
"$ref": "extendible-dynamic-ref.json" |
| 526 |
}, |
| 527 |
{ |
| 528 |
"$defs": { |
| 529 |
"elements": { |
| 530 |
"$dynamicAnchor": "elements", |
| 531 |
"properties": { |
| 532 |
"a": true |
| 533 |
}, |
| 534 |
"required": ["a"], |
| 535 |
"additionalProperties": false |
| 536 |
} |
| 537 |
} |
| 538 |
} |
| 539 |
] |
| 540 |
}, |
| 541 |
"tests": [ |
| 542 |
{ |
| 543 |
"description": "incorrect parent schema", |
| 544 |
"data": { |
| 545 |
"a": true |
| 546 |
}, |
| 547 |
"valid": false |
| 548 |
}, |
| 549 |
{ |
| 550 |
"description": "incorrect extended schema", |
| 551 |
"data": { |
| 552 |
"elements": [ |
| 553 |
{ "b": 1 } |
| 554 |
] |
| 555 |
}, |
| 556 |
"valid": false |
| 557 |
}, |
| 558 |
{ |
| 559 |
"description": "correct extended schema", |
| 560 |
"data": { |
| 561 |
"elements": [ |
| 562 |
{ "a": 1 } |
| 563 |
] |
| 564 |
}, |
| 565 |
"valid": true |
| 566 |
} |
| 567 |
] |
| 568 |
}, |
| 569 |
{ |
| 570 |
"description": "Tests for implementation dynamic anchor and reference link. Reference should be independent of any possible ordering.", |
| 571 |
"schema": { |
| 572 |
"$id": "http://localhost:1234/strict-extendible-allof-ref-first.json", |
| 573 |
"allOf": [ |
| 574 |
{ |
| 575 |
"$defs": { |
| 576 |
"elements": { |
| 577 |
"$dynamicAnchor": "elements", |
| 578 |
"properties": { |
| 579 |
"a": true |
| 580 |
}, |
| 581 |
"required": ["a"], |
| 582 |
"additionalProperties": false |
| 583 |
} |
| 584 |
} |
| 585 |
}, |
| 586 |
{ |
| 587 |
"$ref": "extendible-dynamic-ref.json" |
| 588 |
} |
| 589 |
] |
| 590 |
}, |
| 591 |
"tests": [ |
| 592 |
{ |
| 593 |
"description": "incorrect parent schema", |
| 594 |
"data": { |
| 595 |
"a": true |
| 596 |
}, |
| 597 |
"valid": false |
| 598 |
}, |
| 599 |
{ |
| 600 |
"description": "incorrect extended schema", |
| 601 |
"data": { |
| 602 |
"elements": [ |
| 603 |
{ "b": 1 } |
| 604 |
] |
| 605 |
}, |
| 606 |
"valid": false |
| 607 |
}, |
| 608 |
{ |
| 609 |
"description": "correct extended schema", |
| 610 |
"data": { |
| 611 |
"elements": [ |
| 612 |
{ "a": 1 } |
| 613 |
] |
| 614 |
}, |
| 615 |
"valid": true |
| 616 |
} |
| 617 |
] |
| 618 |
} |
| 619 |
] |