Skip to content

Commit 22e5c94

Browse files
committed
Squashed 'json/' changes from 6327a3bc..fd0aa9f8
fd0aa9f8 Merge pull request #500 from anexia-it/master d0107804 Extend if/then/else tests on unevaluated properties 017d4e56 Merge pull request #499 from json-schema-org/ether/dynamic-scope-enter-leave aa621ed4 test that dynamic scopes are not always in scope git-subtree-dir: json git-subtree-split: fd0aa9f8e2497d9048e17f071abb8fa409f5cb52
1 parent 401a857 commit 22e5c94

File tree

5 files changed

+434
-2
lines changed

5 files changed

+434
-2
lines changed

tests/draft-future/dynamicRef.json

+58-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
{
81-
"description": "A $dynamicRef should resolve to the first $dynamicAnchor that is encountered when the schema is evaluated",
81+
"description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
8282
"schema": {
8383
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
8484
"$ref": "list",
@@ -384,5 +384,62 @@
384384
"valid": false
385385
}
386386
]
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+
]
387444
}
388445
]

tests/draft-future/unevaluatedProperties.json

+106
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,112 @@
491491
}
492492
]
493493
},
494+
{
495+
"description": "unevaluatedProperties with if/then/else, then not defined",
496+
"schema": {
497+
"type": "object",
498+
"if": {
499+
"properties": {
500+
"foo": { "const": "then" }
501+
},
502+
"required": ["foo"]
503+
},
504+
"else": {
505+
"properties": {
506+
"baz": { "type": "string" }
507+
},
508+
"required": ["baz"]
509+
},
510+
"unevaluatedProperties": false
511+
},
512+
"tests": [
513+
{
514+
"description": "when if is true and has no unevaluated properties",
515+
"data": {
516+
"foo": "then",
517+
"bar": "bar"
518+
},
519+
"valid": false
520+
},
521+
{
522+
"description": "when if is true and has unevaluated properties",
523+
"data": {
524+
"foo": "then",
525+
"bar": "bar",
526+
"baz": "baz"
527+
},
528+
"valid": false
529+
},
530+
{
531+
"description": "when if is false and has no unevaluated properties",
532+
"data": {
533+
"baz": "baz"
534+
},
535+
"valid": true
536+
},
537+
{
538+
"description": "when if is false and has unevaluated properties",
539+
"data": {
540+
"foo": "else",
541+
"baz": "baz"
542+
},
543+
"valid": false
544+
}
545+
]
546+
},
547+
{
548+
"description": "unevaluatedProperties with if/then/else, else not defined",
549+
"schema": {
550+
"type": "object",
551+
"if": {
552+
"properties": {
553+
"foo": { "const": "then" }
554+
},
555+
"required": ["foo"]
556+
},
557+
"then": {
558+
"properties": {
559+
"bar": { "type": "string" }
560+
},
561+
"required": ["bar"]
562+
},
563+
"unevaluatedProperties": false
564+
},
565+
"tests": [
566+
{
567+
"description": "when if is true and has no unevaluated properties",
568+
"data": {
569+
"foo": "then",
570+
"bar": "bar"
571+
},
572+
"valid": true
573+
},
574+
{
575+
"description": "when if is true and has unevaluated properties",
576+
"data": {
577+
"foo": "then",
578+
"bar": "bar",
579+
"baz": "baz"
580+
},
581+
"valid": false
582+
},
583+
{
584+
"description": "when if is false and has no unevaluated properties",
585+
"data": {
586+
"baz": "baz"
587+
},
588+
"valid": false
589+
},
590+
{
591+
"description": "when if is false and has unevaluated properties",
592+
"data": {
593+
"foo": "else",
594+
"baz": "baz"
595+
},
596+
"valid": false
597+
}
598+
]
599+
},
494600
{
495601
"description": "unevaluatedProperties with dependentSchemas",
496602
"schema": {

tests/draft2019-09/unevaluatedProperties.json

+106
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,112 @@
491491
}
492492
]
493493
},
494+
{
495+
"description": "unevaluatedProperties with if/then/else, then not defined",
496+
"schema": {
497+
"type": "object",
498+
"if": {
499+
"properties": {
500+
"foo": { "const": "then" }
501+
},
502+
"required": ["foo"]
503+
},
504+
"else": {
505+
"properties": {
506+
"baz": { "type": "string" }
507+
},
508+
"required": ["baz"]
509+
},
510+
"unevaluatedProperties": false
511+
},
512+
"tests": [
513+
{
514+
"description": "when if is true and has no unevaluated properties",
515+
"data": {
516+
"foo": "then",
517+
"bar": "bar"
518+
},
519+
"valid": false
520+
},
521+
{
522+
"description": "when if is true and has unevaluated properties",
523+
"data": {
524+
"foo": "then",
525+
"bar": "bar",
526+
"baz": "baz"
527+
},
528+
"valid": false
529+
},
530+
{
531+
"description": "when if is false and has no unevaluated properties",
532+
"data": {
533+
"baz": "baz"
534+
},
535+
"valid": true
536+
},
537+
{
538+
"description": "when if is false and has unevaluated properties",
539+
"data": {
540+
"foo": "else",
541+
"baz": "baz"
542+
},
543+
"valid": false
544+
}
545+
]
546+
},
547+
{
548+
"description": "unevaluatedProperties with if/then/else, else not defined",
549+
"schema": {
550+
"type": "object",
551+
"if": {
552+
"properties": {
553+
"foo": { "const": "then" }
554+
},
555+
"required": ["foo"]
556+
},
557+
"then": {
558+
"properties": {
559+
"bar": { "type": "string" }
560+
},
561+
"required": ["bar"]
562+
},
563+
"unevaluatedProperties": false
564+
},
565+
"tests": [
566+
{
567+
"description": "when if is true and has no unevaluated properties",
568+
"data": {
569+
"foo": "then",
570+
"bar": "bar"
571+
},
572+
"valid": true
573+
},
574+
{
575+
"description": "when if is true and has unevaluated properties",
576+
"data": {
577+
"foo": "then",
578+
"bar": "bar",
579+
"baz": "baz"
580+
},
581+
"valid": false
582+
},
583+
{
584+
"description": "when if is false and has no unevaluated properties",
585+
"data": {
586+
"baz": "baz"
587+
},
588+
"valid": false
589+
},
590+
{
591+
"description": "when if is false and has unevaluated properties",
592+
"data": {
593+
"foo": "else",
594+
"baz": "baz"
595+
},
596+
"valid": false
597+
}
598+
]
599+
},
494600
{
495601
"description": "unevaluatedProperties with dependentSchemas",
496602
"schema": {

tests/draft2020-12/dynamicRef.json

+58-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
{
81-
"description": "A $dynamicRef should resolve to the first $dynamicAnchor that is encountered when the schema is evaluated",
81+
"description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
8282
"schema": {
8383
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
8484
"$ref": "list",
@@ -384,5 +384,62 @@
384384
"valid": false
385385
}
386386
]
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+
]
387444
}
388445
]

0 commit comments

Comments
 (0)