1[
2 {
3 "description": "oneOf",
4 "schema": {
5 "oneOf": [
6 {
7 "type": "integer"
8 },
9 {
10 "minimum": 2
11 }
12 ]
13 },
14 "tests": [
15 {
16 "description": "first oneOf valid",
17 "data": 1,
18 "valid": true
19 },
20 {
21 "description": "second oneOf valid",
22 "data": 2.5,
23 "valid": true
24 },
25 {
26 "description": "both oneOf valid",
27 "data": 3,
28 "valid": false
29 },
30 {
31 "description": "neither oneOf valid",
32 "data": 1.5,
33 "valid": false
34 }
35 ]
36 },
37 {
38 "description": "oneOf with base schema",
39 "schema": {
40 "type": "string",
41 "oneOf" : [
42 {
43 "minLength": 2
44 },
45 {
46 "maxLength": 4
47 }
48 ]
49 },
50 "tests": [
51 {
52 "description": "mismatch base schema",
53 "data": 3,
54 "valid": false
55 },
56 {
57 "description": "one oneOf valid",
58 "data": "foobar",
59 "valid": true
60 },
61 {
62 "description": "both oneOf valid",
63 "data": "foo",
64 "valid": false
65 }
66 ]
67 },
68 {
69 "description": "oneOf with boolean schemas, all true",
70 "schema": {"oneOf": [true, true, true]},
71 "tests": [
72 {
73 "description": "any value is invalid",
74 "data": "foo",
75 "valid": false
76 }
77 ]
78 },
79 {
80 "description": "oneOf with boolean schemas, one true",
81 "schema": {"oneOf": [true, false, false]},
82 "tests": [
83 {
84 "description": "any value is valid",
85 "data": "foo",
86 "valid": true
87 }
88 ]
89 },
90 {
91 "description": "oneOf with boolean schemas, more than one true",
92 "schema": {"oneOf": [true, true, false]},
93 "tests": [
94 {
95 "description": "any value is invalid",
96 "data": "foo",
97 "valid": false
98 }
99 ]
100 },
101 {
102 "description": "oneOf with boolean schemas, all false",
103 "schema": {"oneOf": [false, false, false]},
104 "tests": [
105 {
106 "description": "any value is invalid",
107 "data": "foo",
108 "valid": false
109 }
110 ]
111 },
112 {
113 "description": "oneOf complex types",
114 "schema": {
115 "oneOf": [
116 {
117 "properties": {
118 "bar": {"type": "integer"}
119 },
120 "required": ["bar"]
121 },
122 {
123 "properties": {
124 "foo": {"type": "string"}
125 },
126 "required": ["foo"]
127 }
128 ]
129 },
130 "tests": [
131 {
132 "description": "first oneOf valid (complex)",
133 "data": {"bar": 2},
134 "valid": true
135 },
136 {
137 "description": "second oneOf valid (complex)",
138 "data": {"foo": "baz"},
139 "valid": true
140 },
141 {
142 "description": "both oneOf valid (complex)",
143 "data": {"foo": "baz", "bar": 2},
144 "valid": false
145 },
146 {
147 "description": "neither oneOf valid (complex)",
148 "data": {"foo": 2, "bar": "quux"},
149 "valid": false
150 }
151 ]
152 },
153 {
154 "description": "oneOf with empty schema",
155 "schema": {
156 "oneOf": [
157 { "type": "number" },
158 {}
159 ]
160 },
161 "tests": [
162 {
163 "description": "one valid - valid",
164 "data": "foo",
165 "valid": true
166 },
167 {
168 "description": "both valid - invalid",
169 "data": 123,
170 "valid": false
171 }
172 ]
173 },
174 {
175 "description": "oneOf with required",
176 "schema": {
177 "type": "object",
178 "oneOf": [
179 { "required": ["foo", "bar"] },
180 { "required": ["foo", "baz"] }
181 ]
182 },
183 "tests": [
184 {
185 "description": "both invalid - invalid",
186 "data": {"bar": 2},
187 "valid": false
188 },
189 {
190 "description": "first valid - valid",
191 "data": {"foo": 1, "bar": 2},
192 "valid": true
193 },
194 {
195 "description": "second valid - valid",
196 "data": {"foo": 1, "baz": 3},
197 "valid": true
198 },
199 {
200 "description": "both valid - invalid",
201 "data": {"foo": 1, "bar": 2, "baz" : 3},
202 "valid": false
203 }
204 ]
205 },
206 {
207 "description": "oneOf with missing optional property",
208 "schema": {
209 "oneOf": [
210 {
211 "properties": {
212 "bar": true,
213 "baz": true
214 },
215 "required": ["bar"]
216 },
217 {
218 "properties": {
219 "foo": true
220 },
221 "required": ["foo"]
222 }
223 ]
224 },
225 "tests": [
226 {
227 "description": "first oneOf valid",
228 "data": {"bar": 8},
229 "valid": true
230 },
231 {
232 "description": "second oneOf valid",
233 "data": {"foo": "foo"},
234 "valid": true
235 },
236 {
237 "description": "both oneOf valid",
238 "data": {"foo": "foo", "bar": 8},
239 "valid": false
240 },
241 {
242 "description": "neither oneOf valid",
243 "data": {"baz": "quux"},
244 "valid": false
245 }
246 ]
247 },
248 {
249 "description": "nested oneOf, to check validation semantics",
250 "schema": {
251 "oneOf": [
252 {
253 "oneOf": [
254 {
255 "type": "null"
256 }
257 ]
258 }
259 ]
260 },
261 "tests": [
262 {
263 "description": "null is valid",
264 "data": null,
265 "valid": true
266 },
267 {
268 "description": "anything non-null is invalid",
269 "data": 123,
270 "valid": false
271 }
272 ]
273 }
274]
View as plain text