Skip to content

Commit d128f9d

Browse files
santhosh-tekurijdesrosiers
authored andcommitted
Add test to check that $id resolved against nearest parent, not just immediate parent
1 parent 72e31dd commit d128f9d

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed

tests/draft-future/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,5 +541,41 @@
541541
"valid": true
542542
}
543543
]
544+
},
545+
{
546+
"description": "$id must be resolved against nearest parent, not just immediate parent",
547+
"schema": {
548+
"$id": "http://example.com/a.json",
549+
"$defs": {
550+
"x": {
551+
"$id": "http://example.com/b/c.json",
552+
"not": {
553+
"$defs": {
554+
"y": {
555+
"$id": "d.json",
556+
"type": "number"
557+
}
558+
}
559+
}
560+
}
561+
},
562+
"allOf": [
563+
{
564+
"$ref": "http://example.com/b/d.json"
565+
}
566+
]
567+
},
568+
"tests": [
569+
{
570+
"description": "number should pass",
571+
"data": 1,
572+
"valid": true
573+
},
574+
{
575+
"description": "non-number should fail",
576+
"data": "a",
577+
"valid": false
578+
}
579+
]
544580
}
545581
]

tests/draft2019-09/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,5 +539,41 @@
539539
"valid": true
540540
}
541541
]
542+
},
543+
{
544+
"description": "$id must be resolved against nearest parent, not just immediate parent",
545+
"schema": {
546+
"$id": "http://example.com/a.json",
547+
"$defs": {
548+
"x": {
549+
"$id": "http://example.com/b/c.json",
550+
"not": {
551+
"$defs": {
552+
"y": {
553+
"$id": "d.json",
554+
"type": "number"
555+
}
556+
}
557+
}
558+
}
559+
},
560+
"allOf": [
561+
{
562+
"$ref": "http://example.com/b/d.json"
563+
}
564+
]
565+
},
566+
"tests": [
567+
{
568+
"description": "number should pass",
569+
"data": 1,
570+
"valid": true
571+
},
572+
{
573+
"description": "non-number should fail",
574+
"data": "a",
575+
"valid": false
576+
}
577+
]
542578
}
543579
]

tests/draft2020-12/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,5 +541,41 @@
541541
"valid": true
542542
}
543543
]
544+
},
545+
{
546+
"description": "$id must be resolved against nearest parent, not just immediate parent",
547+
"schema": {
548+
"$id": "http://example.com/a.json",
549+
"$defs": {
550+
"x": {
551+
"$id": "http://example.com/b/c.json",
552+
"not": {
553+
"$defs": {
554+
"y": {
555+
"$id": "d.json",
556+
"type": "number"
557+
}
558+
}
559+
}
560+
}
561+
},
562+
"allOf": [
563+
{
564+
"$ref": "http://example.com/b/d.json"
565+
}
566+
]
567+
},
568+
"tests": [
569+
{
570+
"description": "number should pass",
571+
"data": 1,
572+
"valid": true
573+
},
574+
{
575+
"description": "non-number should fail",
576+
"data": "a",
577+
"valid": false
578+
}
579+
]
544580
}
545581
]

tests/draft4/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,41 @@
467467
"valid": true
468468
}
469469
]
470+
},
471+
{
472+
"description": "id must be resolved against nearest parent, not just immediate parent",
473+
"schema": {
474+
"id": "http://example.com/a.json",
475+
"definitions": {
476+
"x": {
477+
"id": "http://example.com/b/c.json",
478+
"not": {
479+
"definitions": {
480+
"y": {
481+
"id": "d.json",
482+
"type": "number"
483+
}
484+
}
485+
}
486+
}
487+
},
488+
"allOf": [
489+
{
490+
"$ref": "http://example.com/b/d.json"
491+
}
492+
]
493+
},
494+
"tests": [
495+
{
496+
"description": "number should pass",
497+
"data": 1,
498+
"valid": true
499+
},
500+
{
501+
"description": "non-number should fail",
502+
"data": "a",
503+
"valid": false
504+
}
505+
]
470506
}
471507
]

tests/draft7/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,5 +608,41 @@
608608
"valid": true
609609
}
610610
]
611+
},
612+
{
613+
"description": "$id must be resolved against nearest parent, not just immediate parent",
614+
"schema": {
615+
"$id": "http://example.com/a.json",
616+
"definitions": {
617+
"x": {
618+
"$id": "http://example.com/b/c.json",
619+
"not": {
620+
"definitions": {
621+
"y": {
622+
"$id": "d.json",
623+
"type": "number"
624+
}
625+
}
626+
}
627+
}
628+
},
629+
"allOf": [
630+
{
631+
"$ref": "http://example.com/b/d.json"
632+
}
633+
]
634+
},
635+
"tests": [
636+
{
637+
"description": "number should pass",
638+
"data": 1,
639+
"valid": true
640+
},
641+
{
642+
"description": "non-number should fail",
643+
"data": "a",
644+
"valid": false
645+
}
646+
]
611647
}
612648
]

0 commit comments

Comments
 (0)