Skip to content

Commit c9dd26e

Browse files
William P. Riley-Landmcollina
authored andcommitted
Check for null value before using in. (#176)
* Check for null value before using `in`. * Add test for schema with null value.
1 parent 1fb572f commit c9dd26e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ function inferTypeByKeyword (schema) {
188188
}
189189

190190
function hasAnyOf (schema) {
191+
if (!schema) { return false }
191192
if ('anyOf' in schema) { return true }
192193

193194
var objectKeys = Object.keys(schema)

test/anyof.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,20 @@ test('object with field with type union of multiple objects', (t) => {
231231
t.fail()
232232
}
233233
})
234+
235+
test('null value in schema', (t) => {
236+
t.plan(0)
237+
238+
const schema = {
239+
title: 'schema with null child',
240+
type: 'string',
241+
nullable: true,
242+
enum: [null]
243+
}
244+
245+
try {
246+
build(schema)
247+
} catch (e) {
248+
t.fail()
249+
}
250+
})

0 commit comments

Comments
 (0)