summaryrefslogtreecommitdiff
path: root/json
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-07-19 13:50:46 +0200
committerJulian Berman <Julian@GrayVines.com>2021-07-19 13:50:46 +0200
commit0d6c65da0e4609f5f33c9510211890e3bef0bc15 (patch)
tree3a02582f280a4028e82d663d986ee548600f306b /json
parentaab1a17e621ab64cf274791e4d95bc451e0b69b2 (diff)
parent22e5c949401c3a0cd650a4fb28c6e91574a7ec47 (diff)
downloadjsonschema-0d6c65da0e4609f5f33c9510211890e3bef0bc15.tar.gz
Merge commit '22e5c949401c3a0cd650a4fb28c6e91574a7ec47'
* commit '22e5c949401c3a0cd650a4fb28c6e91574a7ec47': Squashed 'json/' changes from 6327a3bc..fd0aa9f8
Diffstat (limited to 'json')
-rw-r--r--json/tests/draft-future/dynamicRef.json59
-rw-r--r--json/tests/draft-future/unevaluatedProperties.json106
-rw-r--r--json/tests/draft2019-09/unevaluatedProperties.json106
-rw-r--r--json/tests/draft2020-12/dynamicRef.json59
-rw-r--r--json/tests/draft2020-12/unevaluatedProperties.json106
5 files changed, 434 insertions, 2 deletions
diff --git a/json/tests/draft-future/dynamicRef.json b/json/tests/draft-future/dynamicRef.json
index 09fdb4e..40ed6d3 100644
--- a/json/tests/draft-future/dynamicRef.json
+++ b/json/tests/draft-future/dynamicRef.json
@@ -78,7 +78,7 @@
]
},
{
- "description": "A $dynamicRef should resolve to the first $dynamicAnchor that is encountered when the schema is evaluated",
+ "description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
"schema": {
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
"$ref": "list",
@@ -384,5 +384,62 @@
"valid": false
}
]
+ },
+ {
+ "description": "after leaving a dynamic scope, it should not be used by a $dynamicRef",
+ "schema": {
+ "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main",
+ "if": {
+ "$id": "first_scope",
+ "$defs": {
+ "thingy": {
+ "$comment": "this is first_scope#thingy",
+ "$dynamicAnchor": "thingy",
+ "type": "number"
+ }
+ }
+ },
+ "then": {
+ "$id": "second_scope",
+ "$ref": "start",
+ "$defs": {
+ "thingy": {
+ "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef",
+ "$dynamicAnchor": "thingy",
+ "type": "null"
+ }
+ }
+ },
+ "$defs": {
+ "start": {
+ "$comment": "this is the landing spot from $ref",
+ "$id": "start",
+ "$dynamicRef": "inner_scope#thingy"
+ },
+ "thingy": {
+ "$comment": "this is the first stop for the $dynamicRef",
+ "$id": "inner_scope",
+ "$dynamicAnchor": "thingy",
+ "type": "string"
+ }
+ }
+ },
+ "tests": [
+ {
+ "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here",
+ "data": "a string",
+ "valid": false
+ },
+ {
+ "description": "first_scope is not in dynamic scope for the $dynamicRef",
+ "data": 42,
+ "valid": false
+ },
+ {
+ "description": "/then/$defs/thingy is the final stop for the $dynamicRef",
+ "data": null,
+ "valid": true
+ }
+ ]
}
]
diff --git a/json/tests/draft-future/unevaluatedProperties.json b/json/tests/draft-future/unevaluatedProperties.json
index 56d1151..7a5f3f9 100644
--- a/json/tests/draft-future/unevaluatedProperties.json
+++ b/json/tests/draft-future/unevaluatedProperties.json
@@ -492,6 +492,112 @@
]
},
{
+ "description": "unevaluatedProperties with if/then/else, then not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "else": {
+ "properties": {
+ "baz": { "type": "string" }
+ },
+ "required": ["baz"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "unevaluatedProperties with if/then/else, else not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "then": {
+ "properties": {
+ "bar": { "type": "string" }
+ },
+ "required": ["bar"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
"description": "unevaluatedProperties with dependentSchemas",
"schema": {
"type": "object",
diff --git a/json/tests/draft2019-09/unevaluatedProperties.json b/json/tests/draft2019-09/unevaluatedProperties.json
index 31933c1..9f498d0 100644
--- a/json/tests/draft2019-09/unevaluatedProperties.json
+++ b/json/tests/draft2019-09/unevaluatedProperties.json
@@ -492,6 +492,112 @@
]
},
{
+ "description": "unevaluatedProperties with if/then/else, then not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "else": {
+ "properties": {
+ "baz": { "type": "string" }
+ },
+ "required": ["baz"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "unevaluatedProperties with if/then/else, else not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "then": {
+ "properties": {
+ "bar": { "type": "string" }
+ },
+ "required": ["bar"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
"description": "unevaluatedProperties with dependentSchemas",
"schema": {
"type": "object",
diff --git a/json/tests/draft2020-12/dynamicRef.json b/json/tests/draft2020-12/dynamicRef.json
index 09fdb4e..40ed6d3 100644
--- a/json/tests/draft2020-12/dynamicRef.json
+++ b/json/tests/draft2020-12/dynamicRef.json
@@ -78,7 +78,7 @@
]
},
{
- "description": "A $dynamicRef should resolve to the first $dynamicAnchor that is encountered when the schema is evaluated",
+ "description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
"schema": {
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
"$ref": "list",
@@ -384,5 +384,62 @@
"valid": false
}
]
+ },
+ {
+ "description": "after leaving a dynamic scope, it should not be used by a $dynamicRef",
+ "schema": {
+ "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main",
+ "if": {
+ "$id": "first_scope",
+ "$defs": {
+ "thingy": {
+ "$comment": "this is first_scope#thingy",
+ "$dynamicAnchor": "thingy",
+ "type": "number"
+ }
+ }
+ },
+ "then": {
+ "$id": "second_scope",
+ "$ref": "start",
+ "$defs": {
+ "thingy": {
+ "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef",
+ "$dynamicAnchor": "thingy",
+ "type": "null"
+ }
+ }
+ },
+ "$defs": {
+ "start": {
+ "$comment": "this is the landing spot from $ref",
+ "$id": "start",
+ "$dynamicRef": "inner_scope#thingy"
+ },
+ "thingy": {
+ "$comment": "this is the first stop for the $dynamicRef",
+ "$id": "inner_scope",
+ "$dynamicAnchor": "thingy",
+ "type": "string"
+ }
+ }
+ },
+ "tests": [
+ {
+ "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here",
+ "data": "a string",
+ "valid": false
+ },
+ {
+ "description": "first_scope is not in dynamic scope for the $dynamicRef",
+ "data": 42,
+ "valid": false
+ },
+ {
+ "description": "/then/$defs/thingy is the final stop for the $dynamicRef",
+ "data": null,
+ "valid": true
+ }
+ ]
}
]
diff --git a/json/tests/draft2020-12/unevaluatedProperties.json b/json/tests/draft2020-12/unevaluatedProperties.json
index 31933c1..9f498d0 100644
--- a/json/tests/draft2020-12/unevaluatedProperties.json
+++ b/json/tests/draft2020-12/unevaluatedProperties.json
@@ -492,6 +492,112 @@
]
},
{
+ "description": "unevaluatedProperties with if/then/else, then not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "else": {
+ "properties": {
+ "baz": { "type": "string" }
+ },
+ "required": ["baz"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "unevaluatedProperties with if/then/else, else not defined",
+ "schema": {
+ "type": "object",
+ "if": {
+ "properties": {
+ "foo": { "const": "then" }
+ },
+ "required": ["foo"]
+ },
+ "then": {
+ "properties": {
+ "bar": { "type": "string" }
+ },
+ "required": ["bar"]
+ },
+ "unevaluatedProperties": false
+ },
+ "tests": [
+ {
+ "description": "when if is true and has no unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar"
+ },
+ "valid": true
+ },
+ {
+ "description": "when if is true and has unevaluated properties",
+ "data": {
+ "foo": "then",
+ "bar": "bar",
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has no unevaluated properties",
+ "data": {
+ "baz": "baz"
+ },
+ "valid": false
+ },
+ {
+ "description": "when if is false and has unevaluated properties",
+ "data": {
+ "foo": "else",
+ "baz": "baz"
+ },
+ "valid": false
+ }
+ ]
+ },
+ {
"description": "unevaluatedProperties with dependentSchemas",
"schema": {
"type": "object",