diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index 416c2249..4e8987e0 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft-next/id.json b/tests/draft-next/id.json index c5eab10d..db7afaf2 100644 --- a/tests/draft-next/id.json +++ b/tests/draft-next/id.json @@ -254,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json index bc87c9e4..421b5f85 100644 --- a/tests/draft-next/ref.json +++ b/tests/draft-next/ref.json @@ -577,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index 416c2249..4e8987e0 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json index e225aad5..0d825ea4 100644 --- a/tests/draft2019-09/id.json +++ b/tests/draft2019-09/id.json @@ -1,7 +1,9 @@ [ { "description": "Invalid use of fragments in location-independent $id", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "Identifier name", @@ -252,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index fd8a3b21..55a447c4 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -177,7 +177,9 @@ }, { "description": "remote ref, containing refs itself", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "remote ref valid", @@ -298,7 +300,7 @@ "tests": [ { "description": "valid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -327,7 +329,7 @@ }, { "description": "invalid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -575,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 416c2249..4e8987e0 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/id.json b/tests/draft2020-12/id.json index 14a0e9c7..37fb4297 100644 --- a/tests/draft2020-12/id.json +++ b/tests/draft2020-12/id.json @@ -254,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/ref.json b/tests/draft2020-12/ref.json index 8a65e51e..122ff750 100644 --- a/tests/draft2020-12/ref.json +++ b/tests/draft2020-12/ref.json @@ -577,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft6/id.json b/tests/draft6/id.json index b58e0d00..b03248b2 100644 --- a/tests/draft6/id.json +++ b/tests/draft6/id.json @@ -48,6 +48,67 @@ "valid": false } ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } - ] diff --git a/tests/draft7/id.json b/tests/draft7/id.json index b58e0d00..b03248b2 100644 --- a/tests/draft7/id.json +++ b/tests/draft7/id.json @@ -48,6 +48,67 @@ "valid": false } ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } - ] diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 764d6379..b2f94b33 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -644,5 +644,69 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$id": "#bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/#bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ]