Skip to content

Commit 4ee784c

Browse files
authored
Adds test case for anyOf with multiple array items (#235)
1 parent 4b6d837 commit 4ee784c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,9 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema, subKe
10241024
}
10251025

10261026
if (schema.type === undefined) {
1027-
var inferedType = inferTypeByKeyword(schema)
1028-
if (inferedType) {
1029-
schema.type = inferedType
1027+
var inferredType = inferTypeByKeyword(schema)
1028+
if (inferredType) {
1029+
schema.type = inferredType
10301030
}
10311031
}
10321032

test/anyof.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,42 @@ test('anyOf and $ref: multiple levels should throw at build.', (t) => {
396396
t.fail(e)
397397
}
398398
})
399+
400+
test('anyOf looks for all of the array items', (t) => {
401+
t.plan(1)
402+
403+
const schema = {
404+
title: 'type array that may have any of declared items',
405+
type: 'array',
406+
items: {
407+
anyOf: [
408+
{
409+
type: 'object',
410+
properties: {
411+
savedId: {
412+
type: 'string'
413+
}
414+
},
415+
required: ['savedId']
416+
},
417+
{
418+
type: 'object',
419+
properties: {
420+
error: {
421+
type: 'string'
422+
}
423+
},
424+
required: ['error']
425+
}
426+
]
427+
}
428+
}
429+
const stringify = build(schema)
430+
431+
try {
432+
const value = stringify([{ savedId: 'great' }, { error: 'oops' }])
433+
t.is(value, '[{"savedId":"great"},{"error":"oops"}]')
434+
} catch (e) {
435+
t.fail()
436+
}
437+
})

0 commit comments

Comments
 (0)