Skip to content

Commit af6d60f

Browse files
committed
oneOf tests for success-caused failures
1 parent 5035ec4 commit af6d60f

1 file changed

Lines changed: 119 additions & 9 deletions

File tree

src/test-suite/tests/oneOf.json

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
{
77
"description": "oneOf",
88
"schema": {
9-
"oneOf": [
10-
{ "type": "string" },
11-
{ "type": "number" }
12-
]
9+
"oneOf": [{ "type": "string" }, { "type": "number" }]
1310
},
1411
"instance": null,
1512
"errors": [
@@ -46,10 +43,7 @@
4643
{
4744
"description": "oneOf more than one match",
4845
"schema": {
49-
"oneOf": [
50-
{ "type": "integer" },
51-
{ "type": "number" }
52-
]
46+
"oneOf": [{ "type": "integer" }, { "type": "number" }]
5347
},
5448
"instance": 1,
5549
"errors": [
@@ -100,7 +94,7 @@
10094
]
10195
},
10296
{
103-
"description": "oneOf pass",
97+
"description": "oneOf more than one match with an additional failing alternative",
10498
"schema": {
10599
"oneOf": [
106100
{ "type": "string" },
@@ -272,6 +266,122 @@
272266
]
273267
}
274268
]
269+
},
270+
{
271+
"description": "oneOf more than one match with success explanations",
272+
"schema": {
273+
"oneOf": [{ "type": "integer" }, { "type": "number" }]
274+
},
275+
"instance": 66,
276+
"errors": [
277+
{
278+
"messageId": "oneOf-message",
279+
"messageParams": { "matchCount": 2 },
280+
"alternatives": [
281+
[
282+
{
283+
"messageId": "type-success",
284+
"messageParams": {
285+
"actualType": "integer"
286+
},
287+
"instanceLocation": "#",
288+
"schemaLocations": ["#/oneOf/0/type"]
289+
}
290+
],
291+
[
292+
{
293+
"messageId": "type-success",
294+
"messageParams": {
295+
"actualType": "number"
296+
},
297+
"instanceLocation": "#",
298+
"schemaLocations": ["#/oneOf/1/type"]
299+
}
300+
]
301+
],
302+
"instanceLocation": "#",
303+
"schemaLocations": ["#/oneOf"]
304+
}
305+
]
306+
},
307+
{
308+
"description": "oneOf more than one match with failed alternatives ignored",
309+
"schema": {
310+
"oneOf": [
311+
{ "required": ["a"] },
312+
{ "required": ["b"] },
313+
{ "required": ["c"] }
314+
]
315+
},
316+
"instance": { "a": 1, "b": 2 },
317+
"errors": [
318+
{
319+
"messageId": "oneOf-message",
320+
"messageParams": { "matchCount": 2 },
321+
"alternatives": [
322+
[
323+
{
324+
"messageId": "required-success",
325+
"messageParams": {
326+
"property": "a"
327+
},
328+
"instanceLocation": "#",
329+
"schemaLocations": ["#/oneOf/0/required"]
330+
}
331+
],
332+
[
333+
{
334+
"messageId": "required-success",
335+
"messageParams": {
336+
"property": "b"
337+
},
338+
"instanceLocation": "#",
339+
"schemaLocations": ["#/oneOf/1/required"]
340+
}
341+
]
342+
],
343+
"instanceLocation": "#",
344+
"schemaLocations": ["#/oneOf"]
345+
}
346+
]
347+
},
348+
{
349+
"description": "nested oneOf producing multiple matches in inner oneOf",
350+
"schema": {
351+
"oneOf": [
352+
{
353+
"oneOf": [{ "required": ["a"] }, { "required": ["b"] }]
354+
},
355+
{ "required": ["c"] }
356+
]
357+
},
358+
"instance": { "a": 1, "b": 2 },
359+
"errors": [
360+
{
361+
"messageId": "oneOf-message",
362+
"messageParams": { "matchCount": 2 },
363+
"instanceLocation": "#",
364+
"schemaLocations": ["#/oneOf/0/oneOf"],
365+
"alternatives": [
366+
[
367+
{
368+
"messageId": "required-success",
369+
"messageParams": { "property": "a" },
370+
"instanceLocation": "#",
371+
"schemaLocations": ["#/oneOf/0/oneOf/0/required"]
372+
}
373+
],
374+
[
375+
{
376+
"messageId": "required-success",
377+
"messageParams": { "property": "b" },
378+
"instanceLocation": "#",
379+
"schemaLocations": ["#/oneOf/0/oneOf/1/required"]
380+
}
381+
]
382+
]
383+
}
384+
]
275385
}
276386
]
277387
}

0 commit comments

Comments
 (0)