Skip to content

Commit 9ce7b4c

Browse files
authored
Merge pull request #200 from handrews/draft-07
Draft 07 validation test suite
2 parents 1042cd6 + cf6e663 commit 9ce7b4c

40 files changed

+4229
-0
lines changed

tests/draft7/additionalItems.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
[
2+
{
3+
"description": "additionalItems as schema",
4+
"schema": {
5+
"items": [{}],
6+
"additionalItems": {"type": "integer"}
7+
},
8+
"tests": [
9+
{
10+
"description": "additional items match schema",
11+
"data": [ null, 2, 3, 4 ],
12+
"valid": true
13+
},
14+
{
15+
"description": "additional items do not match schema",
16+
"data": [ null, 2, 3, "foo" ],
17+
"valid": false
18+
}
19+
]
20+
},
21+
{
22+
"description": "items is schema, no additionalItems",
23+
"schema": {
24+
"items": {},
25+
"additionalItems": false
26+
},
27+
"tests": [
28+
{
29+
"description": "all items match schema",
30+
"data": [ 1, 2, 3, 4, 5 ],
31+
"valid": true
32+
}
33+
]
34+
},
35+
{
36+
"description": "array of items with no additionalItems",
37+
"schema": {
38+
"items": [{}, {}, {}],
39+
"additionalItems": false
40+
},
41+
"tests": [
42+
{
43+
"description": "fewer number of items present",
44+
"data": [ 1, 2 ],
45+
"valid": true
46+
},
47+
{
48+
"description": "equal number of items present",
49+
"data": [ 1, 2, 3 ],
50+
"valid": true
51+
},
52+
{
53+
"description": "additional items are not permitted",
54+
"data": [ 1, 2, 3, 4 ],
55+
"valid": false
56+
}
57+
]
58+
},
59+
{
60+
"description": "additionalItems as false without items",
61+
"schema": {"additionalItems": false},
62+
"tests": [
63+
{
64+
"description":
65+
"items defaults to empty schema so everything is valid",
66+
"data": [ 1, 2, 3, 4, 5 ],
67+
"valid": true
68+
},
69+
{
70+
"description": "ignores non-arrays",
71+
"data": {"foo" : "bar"},
72+
"valid": true
73+
}
74+
]
75+
},
76+
{
77+
"description": "additionalItems are allowed by default",
78+
"schema": {"items": [{"type": "integer"}]},
79+
"tests": [
80+
{
81+
"description": "only the first item is validated",
82+
"data": [1, "foo", false],
83+
"valid": true
84+
}
85+
]
86+
}
87+
]
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
[
2+
{
3+
"description":
4+
"additionalProperties being false does not allow other properties",
5+
"schema": {
6+
"properties": {"foo": {}, "bar": {}},
7+
"patternProperties": { "^v": {} },
8+
"additionalProperties": false
9+
},
10+
"tests": [
11+
{
12+
"description": "no additional properties is valid",
13+
"data": {"foo": 1},
14+
"valid": true
15+
},
16+
{
17+
"description": "an additional property is invalid",
18+
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
19+
"valid": false
20+
},
21+
{
22+
"description": "ignores arrays",
23+
"data": [1, 2, 3],
24+
"valid": true
25+
},
26+
{
27+
"description": "ignores strings",
28+
"data": "foobarbaz",
29+
"valid": true
30+
},
31+
{
32+
"description": "ignores other non-objects",
33+
"data": 12,
34+
"valid": true
35+
},
36+
{
37+
"description": "patternProperties are not additional properties",
38+
"data": {"foo":1, "vroom": 2},
39+
"valid": true
40+
}
41+
]
42+
},
43+
{
44+
"description":
45+
"additionalProperties allows a schema which should validate",
46+
"schema": {
47+
"properties": {"foo": {}, "bar": {}},
48+
"additionalProperties": {"type": "boolean"}
49+
},
50+
"tests": [
51+
{
52+
"description": "no additional properties is valid",
53+
"data": {"foo": 1},
54+
"valid": true
55+
},
56+
{
57+
"description": "an additional valid property is valid",
58+
"data": {"foo" : 1, "bar" : 2, "quux" : true},
59+
"valid": true
60+
},
61+
{
62+
"description": "an additional invalid property is invalid",
63+
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
64+
"valid": false
65+
}
66+
]
67+
},
68+
{
69+
"description":
70+
"additionalProperties can exist by itself",
71+
"schema": {
72+
"additionalProperties": {"type": "boolean"}
73+
},
74+
"tests": [
75+
{
76+
"description": "an additional valid property is valid",
77+
"data": {"foo" : true},
78+
"valid": true
79+
},
80+
{
81+
"description": "an additional invalid property is invalid",
82+
"data": {"foo" : 1},
83+
"valid": false
84+
}
85+
]
86+
},
87+
{
88+
"description": "additionalProperties are allowed by default",
89+
"schema": {"properties": {"foo": {}, "bar": {}}},
90+
"tests": [
91+
{
92+
"description": "additional properties are allowed",
93+
"data": {"foo": 1, "bar": 2, "quux": true},
94+
"valid": true
95+
}
96+
]
97+
}
98+
]

tests/draft7/allOf.json

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
[
2+
{
3+
"description": "allOf",
4+
"schema": {
5+
"allOf": [
6+
{
7+
"properties": {
8+
"bar": {"type": "integer"}
9+
},
10+
"required": ["bar"]
11+
},
12+
{
13+
"properties": {
14+
"foo": {"type": "string"}
15+
},
16+
"required": ["foo"]
17+
}
18+
]
19+
},
20+
"tests": [
21+
{
22+
"description": "allOf",
23+
"data": {"foo": "baz", "bar": 2},
24+
"valid": true
25+
},
26+
{
27+
"description": "mismatch second",
28+
"data": {"foo": "baz"},
29+
"valid": false
30+
},
31+
{
32+
"description": "mismatch first",
33+
"data": {"bar": 2},
34+
"valid": false
35+
},
36+
{
37+
"description": "wrong type",
38+
"data": {"foo": "baz", "bar": "quux"},
39+
"valid": false
40+
}
41+
]
42+
},
43+
{
44+
"description": "allOf with base schema",
45+
"schema": {
46+
"properties": {"bar": {"type": "integer"}},
47+
"required": ["bar"],
48+
"allOf" : [
49+
{
50+
"properties": {
51+
"foo": {"type": "string"}
52+
},
53+
"required": ["foo"]
54+
},
55+
{
56+
"properties": {
57+
"baz": {"type": "null"}
58+
},
59+
"required": ["baz"]
60+
}
61+
]
62+
},
63+
"tests": [
64+
{
65+
"description": "valid",
66+
"data": {"foo": "quux", "bar": 2, "baz": null},
67+
"valid": true
68+
},
69+
{
70+
"description": "mismatch base schema",
71+
"data": {"foo": "quux", "baz": null},
72+
"valid": false
73+
},
74+
{
75+
"description": "mismatch first allOf",
76+
"data": {"bar": 2, "baz": null},
77+
"valid": false
78+
},
79+
{
80+
"description": "mismatch second allOf",
81+
"data": {"foo": "quux", "bar": 2},
82+
"valid": false
83+
},
84+
{
85+
"description": "mismatch both",
86+
"data": {"bar": 2},
87+
"valid": false
88+
}
89+
]
90+
},
91+
{
92+
"description": "allOf simple types",
93+
"schema": {
94+
"allOf": [
95+
{"maximum": 30},
96+
{"minimum": 20}
97+
]
98+
},
99+
"tests": [
100+
{
101+
"description": "valid",
102+
"data": 25,
103+
"valid": true
104+
},
105+
{
106+
"description": "mismatch one",
107+
"data": 35,
108+
"valid": false
109+
}
110+
]
111+
},
112+
{
113+
"description": "allOf with boolean schemas, all true",
114+
"schema": {"allOf": [true, true]},
115+
"tests": [
116+
{
117+
"description": "any value is valid",
118+
"data": "foo",
119+
"valid": true
120+
}
121+
]
122+
},
123+
{
124+
"description": "allOf with boolean schemas, some false",
125+
"schema": {"allOf": [true, false]},
126+
"tests": [
127+
{
128+
"description": "any value is invalid",
129+
"data": "foo",
130+
"valid": false
131+
}
132+
]
133+
},
134+
{
135+
"description": "allOf with boolean schemas, all false",
136+
"schema": {"allOf": [false, false]},
137+
"tests": [
138+
{
139+
"description": "any value is invalid",
140+
"data": "foo",
141+
"valid": false
142+
}
143+
]
144+
}
145+
]

0 commit comments

Comments
 (0)