Skip to content

Commit 433e35c

Browse files
committed
Updated required field according to the json schema spec.
1 parent ec7bdf0 commit 433e35c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function buildObject (schema, code, name) {
158158
`
159159
}
160160

161-
if (schema.properties[key].required) {
161+
if (schema.required && schema.required.indexOf(key) !== -1) {
162162
code += `
163163
} else {
164164
throw new Error('${key} is required!')

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ test('object with required field', (t) => {
263263
type: 'object',
264264
properties: {
265265
str: {
266-
type: 'string',
267-
required: true
266+
type: 'string'
268267
},
269268
num: {
270269
type: 'integer'
271270
}
272-
}
271+
},
272+
required: ['str']
273273
}
274274
const stringify = build(schema)
275275

0 commit comments

Comments
 (0)