Skip to content

Commit 555dfd3

Browse files
committed
Initialize draft6 tests from draft4.
We are not currently adding tests for draft5, see issue json-schema-org#136 for discussion.
1 parent 5363098 commit 555dfd3

32 files changed

+2436
-0
lines changed

tests/draft6/additionalItems.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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": "no additional items present",
44+
"data": [ 1, 2, 3 ],
45+
"valid": true
46+
},
47+
{
48+
"description": "additional items are not permitted",
49+
"data": [ 1, 2, 3, 4 ],
50+
"valid": false
51+
}
52+
]
53+
},
54+
{
55+
"description": "additionalItems as false without items",
56+
"schema": {"additionalItems": false},
57+
"tests": [
58+
{
59+
"description":
60+
"items defaults to empty schema so everything is valid",
61+
"data": [ 1, 2, 3, 4, 5 ],
62+
"valid": true
63+
},
64+
{
65+
"description": "ignores non-arrays",
66+
"data": {"foo" : "bar"},
67+
"valid": true
68+
}
69+
]
70+
},
71+
{
72+
"description": "additionalItems are allowed by default",
73+
"schema": {"items": [{"type": "integer"}]},
74+
"tests": [
75+
{
76+
"description": "only the first item is validated",
77+
"data": [1, "foo", false],
78+
"valid": true
79+
}
80+
]
81+
}
82+
]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 non-objects",
23+
"data": [1, 2, 3],
24+
"valid": true
25+
},
26+
{
27+
"description": "patternProperties are not additional properties",
28+
"data": {"foo":1, "vroom": 2},
29+
"valid": true
30+
}
31+
]
32+
},
33+
{
34+
"description":
35+
"additionalProperties allows a schema which should validate",
36+
"schema": {
37+
"properties": {"foo": {}, "bar": {}},
38+
"additionalProperties": {"type": "boolean"}
39+
},
40+
"tests": [
41+
{
42+
"description": "no additional properties is valid",
43+
"data": {"foo": 1},
44+
"valid": true
45+
},
46+
{
47+
"description": "an additional valid property is valid",
48+
"data": {"foo" : 1, "bar" : 2, "quux" : true},
49+
"valid": true
50+
},
51+
{
52+
"description": "an additional invalid property is invalid",
53+
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
54+
"valid": false
55+
}
56+
]
57+
},
58+
{
59+
"description":
60+
"additionalProperties can exist by itself",
61+
"schema": {
62+
"additionalProperties": {"type": "boolean"}
63+
},
64+
"tests": [
65+
{
66+
"description": "an additional valid property is valid",
67+
"data": {"foo" : true},
68+
"valid": true
69+
},
70+
{
71+
"description": "an additional invalid property is invalid",
72+
"data": {"foo" : 1},
73+
"valid": false
74+
}
75+
]
76+
},
77+
{
78+
"description": "additionalProperties are allowed by default",
79+
"schema": {"properties": {"foo": {}, "bar": {}}},
80+
"tests": [
81+
{
82+
"description": "additional properties are allowed",
83+
"data": {"foo": 1, "bar": 2, "quux": true},
84+
"valid": true
85+
}
86+
]
87+
}
88+
]

tests/draft6/allOf.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
]

tests/draft6/anyOf.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[
2+
{
3+
"description": "anyOf",
4+
"schema": {
5+
"anyOf": [
6+
{
7+
"type": "integer"
8+
},
9+
{
10+
"minimum": 2
11+
}
12+
]
13+
},
14+
"tests": [
15+
{
16+
"description": "first anyOf valid",
17+
"data": 1,
18+
"valid": true
19+
},
20+
{
21+
"description": "second anyOf valid",
22+
"data": 2.5,
23+
"valid": true
24+
},
25+
{
26+
"description": "both anyOf valid",
27+
"data": 3,
28+
"valid": true
29+
},
30+
{
31+
"description": "neither anyOf valid",
32+
"data": 1.5,
33+
"valid": false
34+
}
35+
]
36+
},
37+
{
38+
"description": "anyOf with base schema",
39+
"schema": {
40+
"type": "string",
41+
"anyOf" : [
42+
{
43+
"maxLength": 2
44+
},
45+
{
46+
"minLength": 4
47+
}
48+
]
49+
},
50+
"tests": [
51+
{
52+
"description": "mismatch base schema",
53+
"data": 3,
54+
"valid": false
55+
},
56+
{
57+
"description": "one anyOf valid",
58+
"data": "foobar",
59+
"valid": true
60+
},
61+
{
62+
"description": "both anyOf invalid",
63+
"data": "foo",
64+
"valid": false
65+
}
66+
]
67+
}
68+
]

0 commit comments

Comments
 (0)