Skip to content

Commit 0e1ee65

Browse files
committed
Added test cases from Foundations of JSON Schema research paper
In the 25th internationl world wide web conference there was a paper named "Foundations of JSON Schema", presented by: * Felipe Pezoa ([email protected]) * Juan L. Reutter ([email protected]) * Fernando Suarez ([email protected]) * Martín Ugarte ([email protected]) * Domagoj Vrgo ([email protected]) 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.
1 parent 0799212 commit 0e1ee65

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

tests/draft4/dependencies.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,43 @@
109109
"valid": false
110110
}
111111
]
112+
},
113+
{
114+
"description": "dependent subschema incompatible with root",
115+
"schema": {
116+
"properties": {
117+
"foo": {}
118+
},
119+
"dependencies": {
120+
"foo": {
121+
"properties": {
122+
"bar": {}
123+
},
124+
"additionalProperties": false
125+
}
126+
}
127+
},
128+
"tests": [
129+
{
130+
"description": "matches root",
131+
"data": {"foo": 1},
132+
"valid": false
133+
},
134+
{
135+
"description": "matches dependency",
136+
"data": {"bar": 1},
137+
"valid": true
138+
},
139+
{
140+
"description": "matches both",
141+
"data": {"foo": 1, "bar": 2},
142+
"valid": false
143+
},
144+
{
145+
"description": "no dependency",
146+
"data": {"baz": 1},
147+
"valid": true
148+
}
149+
]
112150
}
113151
]

tests/draft4/ref.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,35 @@
173173
}
174174
]
175175
},
176+
{
177+
"description": "nested ref with other properties",
178+
"schema": {
179+
"definitions": {
180+
"a": {
181+
"type": "number"
182+
}
183+
},
184+
"properties": {
185+
"foo": {
186+
"type": "number",
187+
"maximum": 5,
188+
"$ref": "#/definitions/a"
189+
}
190+
}
191+
},
192+
"tests": [
193+
{
194+
"description": "ignores other properties",
195+
"data": { "foo": 10 },
196+
"valid": true
197+
},
198+
{
199+
"description": "data matches ref",
200+
"data": { "foo": "bar" },
201+
"valid": false
202+
}
203+
]
204+
},
176205
{
177206
"description": "remote ref, containing refs itself",
178207
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"},

tests/draft4/refRemote.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@
4949
}
5050
]
5151
},
52+
{
53+
"description": "ref with other properties",
54+
"schema": {
55+
"type": "number",
56+
"maximum": 5,
57+
"$ref": "http://localhost:1234/integer.json"
58+
},
59+
"tests": [
60+
{
61+
"description": "ignores other properties",
62+
"data": 10,
63+
"valid": true
64+
},
65+
{
66+
"description": "data matches ref",
67+
"data": "a",
68+
"valid": false
69+
}
70+
]
71+
},
5272
{
5373
"description": "change resolution scope",
5474
"schema": {

tests/draft4/uniqueItems.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"data": [{"foo": "bar"}, {"foo": "bar"}],
2929
"valid": false
3030
},
31+
{
32+
"description": "property order of array of objects is ignored",
33+
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}],
34+
"valid": false
35+
},
3136
{
3237
"description": "unique array of nested objects is valid",
3338
"data": [
@@ -54,6 +59,16 @@
5459
"data": [["foo"], ["foo"]],
5560
"valid": false
5661
},
62+
{
63+
"description": "sub-arrays are valid using same elements in different order",
64+
"data": [["foo", "bar"], ["bar", "foo"]],
65+
"valid": true
66+
},
67+
{
68+
"description": "sub-arrays are invalid using same elements in same order",
69+
"data": [["foo", "bar"], ["foo", "bar"]],
70+
"valid": false
71+
},
5772
{
5873
"description": "1 and true are unique",
5974
"data": [1, true],

0 commit comments

Comments
 (0)