Skip to content

Commit 4d61c78

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 9beb3cf commit 4d61c78

12 files changed

+276
-0
lines changed

tests/draft4/dependencies.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,43 @@
190190
"valid": false
191191
}
192192
]
193+
},
194+
{
195+
"description": "dependent subschema incompatible with root",
196+
"schema": {
197+
"properties": {
198+
"foo": {}
199+
},
200+
"dependencies": {
201+
"foo": {
202+
"properties": {
203+
"bar": {}
204+
},
205+
"additionalProperties": false
206+
}
207+
}
208+
},
209+
"tests": [
210+
{
211+
"description": "matches root",
212+
"data": {"foo": 1},
213+
"valid": false
214+
},
215+
{
216+
"description": "matches dependency",
217+
"data": {"bar": 1},
218+
"valid": true
219+
},
220+
{
221+
"description": "matches both",
222+
"data": {"foo": 1, "bar": 2},
223+
"valid": false
224+
},
225+
{
226+
"description": "no dependency",
227+
"data": {"baz": 1},
228+
"valid": true
229+
}
230+
]
193231
}
194232
]

tests/draft4/ref.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@
211211
}
212212
]
213213
},
214+
{
215+
"description": "nested ref with other properties",
216+
"schema": {
217+
"definitions": {
218+
"a": {
219+
"type": "number"
220+
}
221+
},
222+
"properties": {
223+
"foo": {
224+
"type": "number",
225+
"maximum": 5,
226+
"$ref": "#/definitions/a"
227+
}
228+
}
229+
},
230+
"tests": [
231+
{
232+
"description": "ignores other properties",
233+
"data": { "foo": 10 },
234+
"valid": true
235+
},
236+
{
237+
"description": "data matches ref",
238+
"data": { "foo": "bar" },
239+
"valid": false
240+
}
241+
]
242+
},
214243
{
215244
"description": "remote ref, containing refs itself",
216245
"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": "base URI change",
5474
"schema": {

tests/draft4/uniqueItems.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"data": [{"foo": "bar"}, {"foo": "bar"}],
5454
"valid": false
5555
},
56+
{
57+
"description": "property order of array of objects is ignored",
58+
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}],
59+
"valid": false
60+
},
5661
{
5762
"description": "unique array of nested objects is valid",
5863
"data": [

tests/draft6/dependencies.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,43 @@
244244
"valid": false
245245
}
246246
]
247+
},
248+
{
249+
"description": "dependent subschema incompatible with root",
250+
"schema": {
251+
"properties": {
252+
"foo": {}
253+
},
254+
"dependencies": {
255+
"foo": {
256+
"properties": {
257+
"bar": {}
258+
},
259+
"additionalProperties": false
260+
}
261+
}
262+
},
263+
"tests": [
264+
{
265+
"description": "matches root",
266+
"data": {"foo": 1},
267+
"valid": false
268+
},
269+
{
270+
"description": "matches dependency",
271+
"data": {"bar": 1},
272+
"valid": true
273+
},
274+
{
275+
"description": "matches both",
276+
"data": {"foo": 1, "bar": 2},
277+
"valid": false
278+
},
279+
{
280+
"description": "no dependency",
281+
"data": {"baz": 1},
282+
"valid": true
283+
}
284+
]
247285
}
248286
]

tests/draft6/ref.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@
211211
}
212212
]
213213
},
214+
{
215+
"description": "nested ref with other properties",
216+
"schema": {
217+
"definitions": {
218+
"a": {
219+
"type": "number"
220+
}
221+
},
222+
"properties": {
223+
"foo": {
224+
"type": "number",
225+
"maximum": 5,
226+
"$ref": "#/definitions/a"
227+
}
228+
}
229+
},
230+
"tests": [
231+
{
232+
"description": "ignores other properties",
233+
"data": { "foo": 10 },
234+
"valid": true
235+
},
236+
{
237+
"description": "data matches ref",
238+
"data": { "foo": "bar" },
239+
"valid": false
240+
}
241+
]
242+
},
214243
{
215244
"description": "remote ref, containing refs itself",
216245
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},

tests/draft6/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": "base URI change",
5474
"schema": {

tests/draft6/uniqueItems.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"data": [{"foo": "bar"}, {"foo": "bar"}],
5454
"valid": false
5555
},
56+
{
57+
"description": "property order of array of objects is ignored",
58+
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}],
59+
"valid": false
60+
},
5661
{
5762
"description": "unique array of nested objects is valid",
5863
"data": [

tests/draft7/dependencies.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,43 @@
244244
"valid": false
245245
}
246246
]
247+
},
248+
{
249+
"description": "dependent subschema incompatible with root",
250+
"schema": {
251+
"properties": {
252+
"foo": {}
253+
},
254+
"dependencies": {
255+
"foo": {
256+
"properties": {
257+
"bar": {}
258+
},
259+
"additionalProperties": false
260+
}
261+
}
262+
},
263+
"tests": [
264+
{
265+
"description": "matches root",
266+
"data": {"foo": 1},
267+
"valid": false
268+
},
269+
{
270+
"description": "matches dependency",
271+
"data": {"bar": 1},
272+
"valid": true
273+
},
274+
{
275+
"description": "matches both",
276+
"data": {"foo": 1, "bar": 2},
277+
"valid": false
278+
},
279+
{
280+
"description": "no dependency",
281+
"data": {"baz": 1},
282+
"valid": true
283+
}
284+
]
247285
}
248286
]

tests/draft7/ref.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@
211211
}
212212
]
213213
},
214+
{
215+
"description": "nested ref with other properties",
216+
"schema": {
217+
"definitions": {
218+
"a": {
219+
"type": "number"
220+
}
221+
},
222+
"properties": {
223+
"foo": {
224+
"type": "number",
225+
"maximum": 5,
226+
"$ref": "#/definitions/a"
227+
}
228+
}
229+
},
230+
"tests": [
231+
{
232+
"description": "ignores other properties",
233+
"data": { "foo": 10 },
234+
"valid": true
235+
},
236+
{
237+
"description": "data matches ref",
238+
"data": { "foo": "bar" },
239+
"valid": false
240+
}
241+
]
242+
},
214243
{
215244
"description": "remote ref, containing refs itself",
216245
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},

tests/draft7/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": "base URI change",
5474
"schema": {

tests/draft7/uniqueItems.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"data": [{"foo": "bar"}, {"foo": "bar"}],
5454
"valid": false
5555
},
56+
{
57+
"description": "property order of array of objects is ignored",
58+
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}],
59+
"valid": false
60+
},
5661
{
5762
"description": "unique array of nested objects is valid",
5863
"data": [

0 commit comments

Comments
 (0)