From 1008edcee8f9ca1e904153912b1cbf914aa38800 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Tekuri Date: Fri, 21 Apr 2023 00:04:05 +0530 Subject: [PATCH 1/2] ref: test empty tokens in json-pointer --- tests/draft-next/ref.json | 29 +++++++++++++++++++++++++++++ tests/draft2019-09/ref.json | 29 +++++++++++++++++++++++++++++ tests/draft2020-12/ref.json | 29 +++++++++++++++++++++++++++++ tests/draft4/ref.json | 29 +++++++++++++++++++++++++++++ tests/draft6/ref.json | 29 +++++++++++++++++++++++++++++ tests/draft7/ref.json | 29 +++++++++++++++++++++++++++++ 6 files changed, 174 insertions(+) diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json index 87a54765..5b4b7763 100644 --- a/tests/draft-next/ref.json +++ b/tests/draft-next/ref.json @@ -1026,5 +1026,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index b6044ce9..aa2542c0 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -1026,5 +1026,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/ref.json b/tests/draft2020-12/ref.json index 469a11a1..83996844 100644 --- a/tests/draft2020-12/ref.json +++ b/tests/draft2020-12/ref.json @@ -1026,5 +1026,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index a1e86779..b53bd2ab 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -559,5 +559,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 12eaeda7..8a8908a4 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -869,5 +869,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index fa0192e1..82631726 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -983,5 +983,34 @@ "valid": false } ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] } ] From e4bceb1ad293afc33ca960754c16d85ca0728e7c Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 21 Apr 2023 18:01:28 -0400 Subject: [PATCH 2/2] Bump the python-jsonschema version used for the sanity check. The test in this PR (#664) actually trips a bug in the older version (where it doesn't properly consider the keys in definitions to not be schemas, they're just labels) --- bin/jsonschema_suite | 14 ++++++++++++++ tox.ini | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/jsonschema_suite b/bin/jsonschema_suite index b4792a05..9fee8d7b 100755 --- a/bin/jsonschema_suite +++ b/bin/jsonschema_suite @@ -498,6 +498,13 @@ class SanityTests(unittest.TestCase): "title", "type", "uniqueItems", + + # Technically this is wrong, $comment doesn't exist in this + # draft, but the point of this test is to detect mistakes by, + # test authors, whereas the point of the $comment keyword is + # to just standardize a place for a comment, so it's not a + # mistake to use it in earlier drafts in tests per se. + "$comment", }, "draft3": { "$ref", @@ -528,6 +535,13 @@ class SanityTests(unittest.TestCase): "title", "type", "uniqueItems", + + # Technically this is wrong, $comment doesn't exist in this + # draft, but the point of this test is to detect mistakes by, + # test authors, whereas the point of the $comment keyword is + # to just standardize a place for a comment, so it's not a + # mistake to use it in earlier drafts in tests per se. + "$comment", }, } diff --git a/tox.ini b/tox.ini index 7ca9de98..dcc0dce6 100644 --- a/tox.ini +++ b/tox.ini @@ -5,5 +5,5 @@ skipsdist = True [testenv:sanity] # used just for validating the structure of the test case files themselves -deps = jsonschema==4.17.3 +deps = jsonschema==4.18.0a4 commands = {envpython} bin/jsonschema_suite check