Skip to content

Commit 7d6cc6b

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 5fb3d9f commit 7d6cc6b

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-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": false
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,58 @@
140140
}
141141
]
142142
},
143+
{
144+
"description": "recursive refs",
145+
"schema": {
146+
"definitions": {
147+
"a": {"$ref": "#/definitions/b"},
148+
"b": {"$ref": "#/definitions/a"}
149+
},
150+
"properties": {
151+
"foo": {
152+
"type": "integer"
153+
},
154+
"bar": {
155+
"$ref": "#/definitions/a"
156+
}
157+
}
158+
},
159+
"tests": [
160+
{
161+
"description": "unrelated property",
162+
"data": {"foo": 1},
163+
"valid": true
164+
}
165+
]
166+
},
167+
{
168+
"description": "nested ref with other properties",
169+
"schema": {
170+
"definitions": {
171+
"a": {
172+
"type": "number"
173+
}
174+
},
175+
"properties": {
176+
"foo": {
177+
"type": "string",
178+
"$ref": "#/definitions/a"
179+
}
180+
}
181+
},
182+
"tests": [
183+
{
184+
"description": "data matches ref",
185+
"data": { "foo": 1 },
186+
"valid": true
187+
},
188+
{
189+
"description": "data matches other properties",
190+
"data": { "foo": "bar" },
191+
"valid": false
192+
}
193+
]
194+
},
143195
{
144196
"description": "remote ref, containing refs itself",
145197
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"},

tests/draft4/refRemote.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@
4949
}
5050
]
5151
},
52+
{
53+
"description": "ref with other properties",
54+
"schema": {
55+
"$ref": "http://localhost:1234/integer.json",
56+
"type": "string"
57+
},
58+
"tests": [
59+
{
60+
"description": "data matches ref",
61+
"data": 1,
62+
"valid": true
63+
},
64+
{
65+
"description": "data matches other properties",
66+
"data": "a",
67+
"valid": false
68+
}
69+
]
70+
},
5271
{
5372
"description": "change resolution scope",
5473
"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)