From 1d5583de68548cbdcdbfd817bc00e027ae2e8ec5 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 31 May 2020 17:12:54 -0700 Subject: [PATCH 1/3] some tests of the interactions between $id, $anchor and $ref --- tests/draft2019-09/anchor.json | 31 ++++++++++++++++ tests/draft2019-09/id.json | 31 ++++++++++++++++ tests/draft2019-09/ref.json | 65 ++++++++++++++++++++++++++++++++++ tests/draft6/id.json | 63 +++++++++++++++++++++++++++++++- tests/draft7/id.json | 63 +++++++++++++++++++++++++++++++- tests/draft7/ref.json | 64 +++++++++++++++++++++++++++++++++ 6 files changed, 315 insertions(+), 2 deletions(-) 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..fbe40651 100644 --- a/tests/draft2019-09/id.json +++ b/tests/draft2019-09/id.json @@ -252,5 +252,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..c7f53fb2 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -575,5 +575,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": "/base/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /base/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /int.json", + "$id": "/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": "/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint", + "$id": "/", + "$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..72c9aa9c 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": "/base/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /base/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /int.json", + "$id": "/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: plain-name $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint", + "$id": "#bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#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 + } + ] } ] From e157bc0b7ac201f6e506db568f7fbeb9bbc114c6 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Tue, 23 Jun 2020 11:06:50 -0700 Subject: [PATCH 2/3] squash: use a unique $id to prevent namespace collisions across tests --- tests/draft2019-09/ref.json | 16 ++++++++-------- tests/draft7/ref.json | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index c7f53fb2..72f04ba0 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -580,17 +580,17 @@ "description": "order of evaluation: $id and $ref", "schema": { "$comment": "$id must be evaluated before $ref to get the proper $ref destination", - "$id": "/base/base.json", + "$id": "/ref-and-id1/base.json", "$ref": "int.json", "$defs": { "bigint": { - "$comment": "canonical uri: /base/int.json", + "$comment": "canonical uri: /ref-and-id1/int.json", "$id": "int.json", "maximum": 10 }, "smallint": { - "$comment": "canonical uri: /int.json", - "$id": "/int.json", + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", "maximum": 2 } } @@ -612,17 +612,17 @@ "description": "order of evaluation: $id and $anchor and $ref", "schema": { "$comment": "$id must be evaluated before $ref to get the proper $ref destination", - "$id": "/base.json", + "$id": "/ref-and-id2/base.json", "$ref": "#bigint", "$defs": { "bigint": { - "$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#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: /#/$defs/smallint; another valid uri for this location: /#bigint", - "$id": "/", + "$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 } diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 72c9aa9c..b2f94b33 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -649,17 +649,17 @@ "description": "order of evaluation: $id and $ref", "schema": { "$comment": "$id must be evaluated before $ref to get the proper $ref destination", - "$id": "/base/base.json", + "$id": "/ref-and-id1/base.json", "$ref": "int.json", "$defs": { "bigint": { - "$comment": "canonical uri: /base/int.json", + "$comment": "canonical uri: /ref-and-id1/int.json", "$id": "int.json", "maximum": 10 }, "smallint": { - "$comment": "canonical uri: /int.json", - "$id": "/int.json", + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", "maximum": 2 } } @@ -678,19 +678,19 @@ ] }, { - "description": "order of evaluation: plain-name $id and $ref", + "description": "order of evaluation: $id and $anchor and $ref", "schema": { "$comment": "$id must be evaluated before $ref to get the proper $ref destination", - "$id": "/base.json", + "$id": "/ref-and-id2/base.json", "$ref": "#bigint", "$defs": { "bigint": { - "$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#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: /#/$defs/smallint; another valid uri for this location: /#bigint", + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", "$id": "/#bigint", "maximum": 2 } From d593591d78160acae69a364e178765b5fa012eec Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 22 Jun 2022 13:00:23 -0400 Subject: [PATCH 3/3] Forward port the just-added tests to 2020 and next. --- tests/draft-next/anchor.json | 31 ++++++++++++++++ tests/draft-next/id.json | 31 ++++++++++++++++ tests/draft-next/ref.json | 65 ++++++++++++++++++++++++++++++++++ tests/draft2019-09/id.json | 4 ++- tests/draft2019-09/ref.json | 8 +++-- tests/draft2020-12/anchor.json | 31 ++++++++++++++++ tests/draft2020-12/id.json | 31 ++++++++++++++++ tests/draft2020-12/ref.json | 65 ++++++++++++++++++++++++++++++++++ 8 files changed, 262 insertions(+), 4 deletions(-) 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/id.json b/tests/draft2019-09/id.json index fbe40651..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", diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index 72f04ba0..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": [ { 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 + } + ] } ]