cuelang.org/go@v0.13.0/encoding/jsonschema/testdata/external/tests/draft4/ref.json (about) 1 [ 2 { 3 "description": "root pointer ref", 4 "schema": { 5 "properties": { 6 "foo": { 7 "$ref": "#" 8 } 9 }, 10 "additionalProperties": false 11 }, 12 "tests": [ 13 { 14 "description": "match", 15 "data": { 16 "foo": false 17 }, 18 "valid": true 19 }, 20 { 21 "description": "recursive match", 22 "data": { 23 "foo": { 24 "foo": false 25 } 26 }, 27 "valid": true 28 }, 29 { 30 "description": "mismatch", 31 "data": { 32 "bar": false 33 }, 34 "valid": false 35 }, 36 { 37 "description": "recursive mismatch", 38 "data": { 39 "foo": { 40 "bar": false 41 } 42 }, 43 "valid": false 44 } 45 ] 46 }, 47 { 48 "description": "relative pointer ref to object", 49 "schema": { 50 "properties": { 51 "foo": { 52 "type": "integer" 53 }, 54 "bar": { 55 "$ref": "#/properties/foo" 56 } 57 } 58 }, 59 "tests": [ 60 { 61 "description": "match", 62 "data": { 63 "bar": 3 64 }, 65 "valid": true 66 }, 67 { 68 "description": "mismatch", 69 "data": { 70 "bar": true 71 }, 72 "valid": false 73 } 74 ] 75 }, 76 { 77 "description": "relative pointer ref to array", 78 "schema": { 79 "items": [ 80 { 81 "type": "integer" 82 }, 83 { 84 "$ref": "#/items/0" 85 } 86 ] 87 }, 88 "tests": [ 89 { 90 "description": "match array", 91 "data": [ 92 1, 93 2 94 ], 95 "valid": true 96 }, 97 { 98 "description": "mismatch array", 99 "data": [ 100 1, 101 "foo" 102 ], 103 "valid": false 104 } 105 ] 106 }, 107 { 108 "description": "escaped pointer ref", 109 "schema": { 110 "definitions": { 111 "tilde~field": { 112 "type": "integer" 113 }, 114 "slash/field": { 115 "type": "integer" 116 }, 117 "percent%field": { 118 "type": "integer" 119 } 120 }, 121 "properties": { 122 "tilde": { 123 "$ref": "#/definitions/tilde~0field" 124 }, 125 "slash": { 126 "$ref": "#/definitions/slash~1field" 127 }, 128 "percent": { 129 "$ref": "#/definitions/percent%25field" 130 } 131 } 132 }, 133 "tests": [ 134 { 135 "description": "slash invalid", 136 "data": { 137 "slash": "aoeu" 138 }, 139 "valid": false 140 }, 141 { 142 "description": "tilde invalid", 143 "data": { 144 "tilde": "aoeu" 145 }, 146 "valid": false 147 }, 148 { 149 "description": "percent invalid", 150 "data": { 151 "percent": "aoeu" 152 }, 153 "valid": false 154 }, 155 { 156 "description": "slash valid", 157 "data": { 158 "slash": 123 159 }, 160 "valid": true 161 }, 162 { 163 "description": "tilde valid", 164 "data": { 165 "tilde": 123 166 }, 167 "valid": true 168 }, 169 { 170 "description": "percent valid", 171 "data": { 172 "percent": 123 173 }, 174 "valid": true 175 } 176 ] 177 }, 178 { 179 "description": "nested refs", 180 "schema": { 181 "definitions": { 182 "a": { 183 "type": "integer" 184 }, 185 "b": { 186 "$ref": "#/definitions/a" 187 }, 188 "c": { 189 "$ref": "#/definitions/b" 190 } 191 }, 192 "allOf": [ 193 { 194 "$ref": "#/definitions/c" 195 } 196 ] 197 }, 198 "tests": [ 199 { 200 "description": "nested ref valid", 201 "data": 5, 202 "valid": true 203 }, 204 { 205 "description": "nested ref invalid", 206 "data": "a", 207 "valid": false 208 } 209 ] 210 }, 211 { 212 "description": "ref overrides any sibling keywords", 213 "schema": { 214 "definitions": { 215 "reffed": { 216 "type": "array" 217 } 218 }, 219 "properties": { 220 "foo": { 221 "$ref": "#/definitions/reffed", 222 "maxItems": 2 223 } 224 } 225 }, 226 "tests": [ 227 { 228 "description": "ref valid", 229 "data": { 230 "foo": [] 231 }, 232 "valid": true 233 }, 234 { 235 "description": "ref valid, maxItems ignored", 236 "data": { 237 "foo": [ 238 1, 239 2, 240 3 241 ] 242 }, 243 "valid": true 244 }, 245 { 246 "description": "ref invalid", 247 "data": { 248 "foo": "string" 249 }, 250 "valid": false 251 } 252 ] 253 }, 254 { 255 "description": "$ref prevents a sibling id from changing the base uri", 256 "schema": { 257 "id": "http://localhost:1234/sibling_id/base/", 258 "definitions": { 259 "foo": { 260 "id": "http://localhost:1234/sibling_id/foo.json", 261 "type": "string" 262 }, 263 "base_foo": { 264 "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", 265 "id": "foo.json", 266 "type": "number" 267 } 268 }, 269 "allOf": [ 270 { 271 "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", 272 "id": "http://localhost:1234/sibling_id/", 273 "$ref": "foo.json" 274 } 275 ] 276 }, 277 "tests": [ 278 { 279 "description": "$ref resolves to /definitions/base_foo, data does not validate", 280 "data": "a", 281 "valid": false 282 }, 283 { 284 "description": "$ref resolves to /definitions/base_foo, data validates", 285 "data": 1, 286 "valid": true 287 } 288 ] 289 }, 290 { 291 "description": "remote ref, containing refs itself", 292 "schema": { 293 "$ref": "http://json-schema.org/draft-04/schema#" 294 }, 295 "skip": { 296 "v2": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-04/schema\" imported but not defined in :\n generated.cue:1:8\n", 297 "v3": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-04/schema\" imported but not defined in :\n generated.cue:1:8\n" 298 }, 299 "tests": [ 300 { 301 "description": "remote ref valid", 302 "data": { 303 "minLength": 1 304 }, 305 "valid": true, 306 "skip": { 307 "v2": "could not compile schema", 308 "v3": "could not compile schema" 309 } 310 }, 311 { 312 "description": "remote ref invalid", 313 "data": { 314 "minLength": -1 315 }, 316 "valid": false, 317 "skip": { 318 "v2": "could not compile schema", 319 "v3": "could not compile schema" 320 } 321 } 322 ] 323 }, 324 { 325 "description": "property named $ref that is not a reference", 326 "schema": { 327 "properties": { 328 "$ref": { 329 "type": "string" 330 } 331 } 332 }, 333 "tests": [ 334 { 335 "description": "property named $ref valid", 336 "data": { 337 "$ref": "a" 338 }, 339 "valid": true 340 }, 341 { 342 "description": "property named $ref invalid", 343 "data": { 344 "$ref": 2 345 }, 346 "valid": false 347 } 348 ] 349 }, 350 { 351 "description": "property named $ref, containing an actual $ref", 352 "schema": { 353 "properties": { 354 "$ref": { 355 "$ref": "#/definitions/is-string" 356 } 357 }, 358 "definitions": { 359 "is-string": { 360 "type": "string" 361 } 362 } 363 }, 364 "tests": [ 365 { 366 "description": "property named $ref valid", 367 "data": { 368 "$ref": "a" 369 }, 370 "valid": true 371 }, 372 { 373 "description": "property named $ref invalid", 374 "data": { 375 "$ref": 2 376 }, 377 "valid": false 378 } 379 ] 380 }, 381 { 382 "description": "Recursive references between schemas", 383 "schema": { 384 "id": "http://localhost:1234/tree", 385 "description": "tree of nodes", 386 "type": "object", 387 "properties": { 388 "meta": { 389 "type": "string" 390 }, 391 "nodes": { 392 "type": "array", 393 "items": { 394 "$ref": "node" 395 } 396 } 397 }, 398 "required": [ 399 "meta", 400 "nodes" 401 ], 402 "definitions": { 403 "node": { 404 "id": "http://localhost:1234/node", 405 "description": "node", 406 "type": "object", 407 "properties": { 408 "value": { 409 "type": "number" 410 }, 411 "subtree": { 412 "$ref": "tree" 413 } 414 }, 415 "required": [ 416 "value" 417 ] 418 } 419 } 420 }, 421 "tests": [ 422 { 423 "description": "valid tree", 424 "data": { 425 "meta": "root", 426 "nodes": [ 427 { 428 "value": 1, 429 "subtree": { 430 "meta": "child", 431 "nodes": [ 432 { 433 "value": 1.1 434 }, 435 { 436 "value": 1.2 437 } 438 ] 439 } 440 }, 441 { 442 "value": 2, 443 "subtree": { 444 "meta": "child", 445 "nodes": [ 446 { 447 "value": 2.1 448 }, 449 { 450 "value": 2.2 451 } 452 ] 453 } 454 } 455 ] 456 }, 457 "valid": true 458 }, 459 { 460 "description": "invalid tree", 461 "data": { 462 "meta": "root", 463 "nodes": [ 464 { 465 "value": 1, 466 "subtree": { 467 "meta": "child", 468 "nodes": [ 469 { 470 "value": "string is invalid" 471 }, 472 { 473 "value": 1.2 474 } 475 ] 476 } 477 }, 478 { 479 "value": 2, 480 "subtree": { 481 "meta": "child", 482 "nodes": [ 483 { 484 "value": 2.1 485 }, 486 { 487 "value": 2.2 488 } 489 ] 490 } 491 } 492 ] 493 }, 494 "valid": false 495 } 496 ] 497 }, 498 { 499 "description": "refs with quote", 500 "schema": { 501 "properties": { 502 "foo\"bar": { 503 "$ref": "#/definitions/foo%22bar" 504 } 505 }, 506 "definitions": { 507 "foo\"bar": { 508 "type": "number" 509 } 510 } 511 }, 512 "tests": [ 513 { 514 "description": "object with numbers is valid", 515 "data": { 516 "foo\"bar": 1 517 }, 518 "valid": true 519 }, 520 { 521 "description": "object with strings is invalid", 522 "data": { 523 "foo\"bar": "1" 524 }, 525 "valid": false 526 } 527 ] 528 }, 529 { 530 "description": "Location-independent identifier", 531 "schema": { 532 "allOf": [ 533 { 534 "$ref": "#foo" 535 } 536 ], 537 "definitions": { 538 "A": { 539 "id": "#foo", 540 "type": "integer" 541 } 542 } 543 }, 544 "skip": { 545 "v2": "extract error: $id URI may not contain a fragment (and 3 more errors)", 546 "v3": "extract error: $id URI may not contain a fragment (and 3 more errors)" 547 }, 548 "tests": [ 549 { 550 "description": "match", 551 "data": 1, 552 "valid": true, 553 "skip": { 554 "v2": "could not compile schema", 555 "v3": "could not compile schema" 556 } 557 }, 558 { 559 "description": "mismatch", 560 "data": "a", 561 "valid": false, 562 "skip": { 563 "v2": "could not compile schema", 564 "v3": "could not compile schema" 565 } 566 } 567 ] 568 }, 569 { 570 "description": "Location-independent identifier with base URI change in subschema", 571 "schema": { 572 "id": "http://localhost:1234/root", 573 "allOf": [ 574 { 575 "$ref": "http://localhost:1234/nested.json#foo" 576 } 577 ], 578 "definitions": { 579 "A": { 580 "id": "nested.json", 581 "definitions": { 582 "B": { 583 "id": "#foo", 584 "type": "integer" 585 } 586 } 587 } 588 } 589 }, 590 "skip": { 591 "v2": "extract error: $id URI may not contain a fragment (and 3 more errors)", 592 "v3": "extract error: $id URI may not contain a fragment (and 3 more errors)" 593 }, 594 "tests": [ 595 { 596 "description": "match", 597 "data": 1, 598 "valid": true, 599 "skip": { 600 "v2": "could not compile schema", 601 "v3": "could not compile schema" 602 } 603 }, 604 { 605 "description": "mismatch", 606 "data": "a", 607 "valid": false, 608 "skip": { 609 "v2": "could not compile schema", 610 "v3": "could not compile schema" 611 } 612 } 613 ] 614 }, 615 { 616 "description": "naive replacement of $ref with its destination is not correct", 617 "schema": { 618 "definitions": { 619 "a_string": { 620 "type": "string" 621 } 622 }, 623 "enum": [ 624 { 625 "$ref": "#/definitions/a_string" 626 } 627 ] 628 }, 629 "tests": [ 630 { 631 "description": "do not evaluate the $ref inside the enum, matching any string", 632 "data": "this is a string", 633 "valid": false 634 }, 635 { 636 "description": "match the enum exactly", 637 "data": { 638 "$ref": "#/definitions/a_string" 639 }, 640 "valid": true 641 } 642 ] 643 }, 644 { 645 "description": "id must be resolved against nearest parent, not just immediate parent", 646 "schema": { 647 "id": "http://example.com/a.json", 648 "definitions": { 649 "x": { 650 "id": "http://example.com/b/c.json", 651 "not": { 652 "definitions": { 653 "y": { 654 "id": "d.json", 655 "type": "number" 656 } 657 } 658 } 659 } 660 }, 661 "allOf": [ 662 { 663 "$ref": "http://example.com/b/d.json" 664 } 665 ] 666 }, 667 "tests": [ 668 { 669 "description": "number is valid", 670 "data": 1, 671 "valid": true 672 }, 673 { 674 "description": "non-number is invalid", 675 "data": "a", 676 "valid": false 677 } 678 ] 679 }, 680 { 681 "description": "id with file URI still resolves pointers - *nix", 682 "schema": { 683 "id": "file:///folder/file.json", 684 "definitions": { 685 "foo": { 686 "type": "number" 687 } 688 }, 689 "allOf": [ 690 { 691 "$ref": "#/definitions/foo" 692 } 693 ] 694 }, 695 "tests": [ 696 { 697 "description": "number is valid", 698 "data": 1, 699 "valid": true 700 }, 701 { 702 "description": "non-number is invalid", 703 "data": "a", 704 "valid": false 705 } 706 ] 707 }, 708 { 709 "description": "id with file URI still resolves pointers - windows", 710 "schema": { 711 "id": "file:///c:/folder/file.json", 712 "definitions": { 713 "foo": { 714 "type": "number" 715 } 716 }, 717 "allOf": [ 718 { 719 "$ref": "#/definitions/foo" 720 } 721 ] 722 }, 723 "tests": [ 724 { 725 "description": "number is valid", 726 "data": 1, 727 "valid": true 728 }, 729 { 730 "description": "non-number is invalid", 731 "data": "a", 732 "valid": false 733 } 734 ] 735 }, 736 { 737 "description": "empty tokens in $ref json-pointer", 738 "schema": { 739 "definitions": { 740 "": { 741 "definitions": { 742 "": { 743 "type": "number" 744 } 745 } 746 } 747 }, 748 "allOf": [ 749 { 750 "$ref": "#/definitions//definitions/" 751 } 752 ] 753 }, 754 "tests": [ 755 { 756 "description": "number is valid", 757 "data": 1, 758 "valid": true 759 }, 760 { 761 "description": "non-number is invalid", 762 "data": "a", 763 "valid": false 764 } 765 ] 766 } 767 ]