From 07fd389a3e6511e186220745209a2e795212aedc Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Fri, 30 Sep 2016 13:21:21 +0100 Subject: [PATCH] Added test cases from Foundations of JSON Schema research paper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the 25th internationl world wide web conference there was a paper named "Foundations of JSON Schema", presented by: * Felipe Pezoa (fipezoa@uc.cl) * Juan L. Reutter (jreutter@ing.puc.cl) * Fernando Suarez (fsuarez1@ing.puc.cl) * Martín Ugarte (martin.ugarte@ulb.ac.be) * Domagoj Vrgo (dvrgoc@ing.puc.cl) See: http://www2016.net/proceedings/proceedings/p263.pdf This paper compared a number of json schema implementations, using a set of 5 tests which highlighted inconsistencies between the implementations. I have reproduced those tests here. All credit should go to the authors of the paper for highlighting these inconsistencies and publishing the details of them online. --- tests/draft-next/dependentSchemas.json | 38 ++++++++++++++++++++++++ tests/draft-next/uniqueItems.json | 5 ++++ tests/draft2019-09/dependentSchemas.json | 38 ++++++++++++++++++++++++ tests/draft2019-09/uniqueItems.json | 5 ++++ tests/draft2020-12/dependentSchemas.json | 38 ++++++++++++++++++++++++ tests/draft2020-12/uniqueItems.json | 5 ++++ tests/draft4/dependencies.json | 38 ++++++++++++++++++++++++ tests/draft4/uniqueItems.json | 5 ++++ tests/draft6/dependencies.json | 38 ++++++++++++++++++++++++ tests/draft6/uniqueItems.json | 5 ++++ tests/draft7/dependencies.json | 38 ++++++++++++++++++++++++ tests/draft7/uniqueItems.json | 5 ++++ 12 files changed, 258 insertions(+) diff --git a/tests/draft-next/dependentSchemas.json b/tests/draft-next/dependentSchemas.json index 67c79796..8a847759 100644 --- a/tests/draft-next/dependentSchemas.json +++ b/tests/draft-next/dependentSchemas.json @@ -128,5 +128,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft-next/uniqueItems.json b/tests/draft-next/uniqueItems.json index 610b257d..b16dd505 100644 --- a/tests/draft-next/uniqueItems.json +++ b/tests/draft-next/uniqueItems.json @@ -56,6 +56,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/tests/draft2019-09/dependentSchemas.json b/tests/draft2019-09/dependentSchemas.json index b3975831..3577efdf 100644 --- a/tests/draft2019-09/dependentSchemas.json +++ b/tests/draft2019-09/dependentSchemas.json @@ -128,5 +128,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/uniqueItems.json b/tests/draft2019-09/uniqueItems.json index 6da878be..314b4b9c 100644 --- a/tests/draft2019-09/uniqueItems.json +++ b/tests/draft2019-09/uniqueItems.json @@ -56,6 +56,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/tests/draft2020-12/dependentSchemas.json b/tests/draft2020-12/dependentSchemas.json index bf7aa53a..66ac0eb4 100644 --- a/tests/draft2020-12/dependentSchemas.json +++ b/tests/draft2020-12/dependentSchemas.json @@ -128,5 +128,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft2020-12/uniqueItems.json b/tests/draft2020-12/uniqueItems.json index 707235c3..4ea3bf98 100644 --- a/tests/draft2020-12/uniqueItems.json +++ b/tests/draft2020-12/uniqueItems.json @@ -56,6 +56,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/tests/draft4/dependencies.json b/tests/draft4/dependencies.json index 51eeddf3..9045ddc2 100644 --- a/tests/draft4/dependencies.json +++ b/tests/draft4/dependencies.json @@ -190,5 +190,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft4/uniqueItems.json b/tests/draft4/uniqueItems.json index 2ccf666d..d2730c60 100644 --- a/tests/draft4/uniqueItems.json +++ b/tests/draft4/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/tests/draft6/dependencies.json b/tests/draft6/dependencies.json index a5e54282..c0bd809f 100644 --- a/tests/draft6/dependencies.json +++ b/tests/draft6/dependencies.json @@ -244,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft6/uniqueItems.json b/tests/draft6/uniqueItems.json index 2ccf666d..d2730c60 100644 --- a/tests/draft6/uniqueItems.json +++ b/tests/draft6/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ diff --git a/tests/draft7/dependencies.json b/tests/draft7/dependencies.json index a5e54282..c0bd809f 100644 --- a/tests/draft7/dependencies.json +++ b/tests/draft7/dependencies.json @@ -244,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft7/uniqueItems.json b/tests/draft7/uniqueItems.json index 2ccf666d..d2730c60 100644 --- a/tests/draft7/uniqueItems.json +++ b/tests/draft7/uniqueItems.json @@ -53,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [