Skip to content

Commit 19810ec

Browse files
Add a test for respecting dynamic scopes while avoiding the root of each schema
We $ref from base -> first#/$defs/stuff -> second#/$defs/stuff -> third#/$defs/stuff and then follow a $dynamicRef to #length. At no point do we ever actually evaluate at the root schema for each scope. The dynamic scope is [ base, first, second, third ] and we check the scopes in order, therefore the first scope we find with a dynamic anchor "length" is "second".
1 parent 8da0a7b commit 19810ec

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

tests/draft2020-12/dynamicRef.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,5 +811,63 @@
811811
"valid": false
812812
}
813813
]
814+
},
815+
{
816+
"description": "$dynamicRef avoids the root of each schema, but scopes are still registered",
817+
"schema": {
818+
"$schema": "https://json-schema.org/draft/2020-12/schema",
819+
"$id": "https://test.json-schema.org/dynamic-ref-avoids-root-of-each-schema/base",
820+
"$ref": "first#/$defs/stuff",
821+
"$defs": {
822+
"first": {
823+
"$id": "first",
824+
"$defs": {
825+
"stuff": {
826+
"$ref": "second#/$defs/stuff"
827+
},
828+
"length": {
829+
"$comment": "unused, because there is no $dynamicAnchor here",
830+
"maxLength": 1
831+
}
832+
}
833+
},
834+
"second": {
835+
"$id": "second",
836+
"$defs": {
837+
"stuff": {
838+
"$ref": "third#/$defs/stuff"
839+
},
840+
"length": {
841+
"$dynamicAnchor": "length",
842+
"maxLength": 2
843+
}
844+
}
845+
},
846+
"third": {
847+
"$id": "third",
848+
"$defs": {
849+
"stuff": {
850+
"$dynamicRef": "#length"
851+
},
852+
"length": {
853+
"$dynamicAnchor": "length",
854+
"maxLength": 3
855+
}
856+
}
857+
}
858+
}
859+
},
860+
"tests": [
861+
{
862+
"description": "data is sufficient for schema at second#/$defs/length",
863+
"data": "hi",
864+
"valid": true
865+
},
866+
{
867+
"description": "data is not sufficient for schema at second#/$defs/length",
868+
"data": "hey",
869+
"valid": false
870+
}
871+
]
814872
}
815873
]

tests/v1/dynamicRef.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,5 +592,63 @@
592592
"valid": false
593593
}
594594
]
595+
},
596+
{
597+
"description": "$dynamicRef avoids the root of each schema, but scopes are still registered",
598+
"schema": {
599+
"$schema": "https://json-schema.org/v1",
600+
"$id": "https://test.json-schema.org/dynamic-ref-avoids-root-of-each-schema/base",
601+
"$ref": "first#/$defs/stuff",
602+
"$defs": {
603+
"first": {
604+
"$id": "first",
605+
"$defs": {
606+
"stuff": {
607+
"$ref": "second#/$defs/stuff"
608+
},
609+
"length": {
610+
"$comment": "unused, because there is no $dynamicAnchor here",
611+
"maxLength": 1
612+
}
613+
}
614+
},
615+
"second": {
616+
"$id": "second",
617+
"$defs": {
618+
"stuff": {
619+
"$ref": "third#/$defs/stuff"
620+
},
621+
"length": {
622+
"$dynamicAnchor": "length",
623+
"maxLength": 2
624+
}
625+
}
626+
},
627+
"third": {
628+
"$id": "third",
629+
"$defs": {
630+
"stuff": {
631+
"$dynamicRef": "#length"
632+
},
633+
"length": {
634+
"$dynamicAnchor": "length",
635+
"maxLength": 3
636+
}
637+
}
638+
}
639+
}
640+
},
641+
"tests": [
642+
{
643+
"description": "data is sufficient for schema at second#/$defs/length",
644+
"data": "hi",
645+
"valid": true
646+
},
647+
{
648+
"description": "data is not sufficient for schema at second#/$defs/length",
649+
"data": "hey",
650+
"valid": false
651+
}
652+
]
595653
}
596654
]

0 commit comments

Comments
 (0)