Skip to content

Commit 856ebed

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 856ebed

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

tests/draft2020-12/dynamicRef.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,5 +811,62 @@
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+
},
829+
"length": {
830+
"maxLength": 1
831+
}
832+
},
833+
"second": {
834+
"$id": "second",
835+
"$defs": {
836+
"stuff": {
837+
"$ref": "third#/$defs/stuff"
838+
},
839+
"length": {
840+
"$dynamicAnchor": "length",
841+
"maxLength": 2
842+
}
843+
}
844+
},
845+
"third": {
846+
"$id": "third",
847+
"$defs": {
848+
"stuff": {
849+
"$dynamicRef": "#length"
850+
},
851+
"length": {
852+
"$dynamicAnchor": "length",
853+
"maxLength": 3
854+
}
855+
}
856+
}
857+
}
858+
},
859+
"tests": [
860+
{
861+
"description": "data is sufficient for schema at second#/$defs/length",
862+
"data": "hi",
863+
"valid": true
864+
},
865+
{
866+
"description": "data is not sufficient for schema at second#/$defs/length",
867+
"data": "hey",
868+
"valid": false
869+
}
870+
]
814871
}
815872
]

tests/v1/dynamicRef.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,5 +592,62 @@
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+
},
610+
"length": {
611+
"maxLength": 1
612+
}
613+
},
614+
"second": {
615+
"$id": "second",
616+
"$defs": {
617+
"stuff": {
618+
"$ref": "third#/$defs/stuff"
619+
},
620+
"length": {
621+
"$dynamicAnchor": "length",
622+
"maxLength": 2
623+
}
624+
}
625+
},
626+
"third": {
627+
"$id": "third",
628+
"$defs": {
629+
"stuff": {
630+
"$dynamicRef": "#length"
631+
},
632+
"length": {
633+
"$dynamicAnchor": "length",
634+
"maxLength": 3
635+
}
636+
}
637+
}
638+
}
639+
},
640+
"tests": [
641+
{
642+
"description": "data is sufficient for schema at second#/$defs/length",
643+
"data": "hi",
644+
"valid": true
645+
},
646+
{
647+
"description": "data is not sufficient for schema at second#/$defs/length",
648+
"data": "hey",
649+
"valid": false
650+
}
651+
]
595652
}
596653
]

0 commit comments

Comments
 (0)