Skip to content

Commit ebc469d

Browse files
feat!: drop required property support
1 parent 320747e commit ebc469d

File tree

5 files changed

+2
-287
lines changed

5 files changed

+2
-287
lines changed

index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ function buildCode (location) {
319319
}
320320

321321
const schema = location.schema
322-
const required = schema.required || []
323322

324323
let code = ''
325324

@@ -351,23 +350,12 @@ function buildCode (location) {
351350
${addComma}
352351
json += ${asString} + ':' + ${JSON.stringify(JSON.stringify(defaultValue))}
353352
`
354-
} else if (required.includes(key)) {
355-
code += `
356-
} else {
357-
throw new Error('${sanitized} is required!')
358-
`
359353
}
360-
361354
code += `
362355
}
363356
`
364357
})
365358

366-
for (const requiredProperty of required) {
367-
if (schema.properties && schema.properties[requiredProperty] !== undefined) continue
368-
code += `if (obj['${requiredProperty}'] === undefined) throw new Error('"${requiredProperty}" is required!')\n`
369-
}
370-
371359
return code
372360
}
373361

test/allof.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test('allOf: combine pattern properties', (t) => {
6060
})
6161

6262
test('object with allOf and multiple schema on the allOf', (t) => {
63-
t.plan(4)
63+
t.plan(2)
6464

6565
const schema = {
6666
title: 'object with allOf and multiple schema on the allOf',
@@ -95,22 +95,6 @@ test('object with allOf and multiple schema on the allOf', (t) => {
9595
}
9696
const stringify = build(schema)
9797

98-
try {
99-
stringify({
100-
id: 1
101-
})
102-
} catch (e) {
103-
t.equal(e.message, '"name" is required!')
104-
}
105-
106-
try {
107-
stringify({
108-
name: 'string'
109-
})
110-
} catch (e) {
111-
t.equal(e.message, '"id" is required!')
112-
}
113-
11498
t.equal(stringify({
11599
id: 1,
116100
name: 'string'

test/required.test.js

Lines changed: 0 additions & 238 deletions
This file was deleted.

test/sanitize4.test.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/toJSON.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ test('toJSON forwards nullable types', (t) => {
10881088
})
10891089

10901090
test('toJSON supports required types', (t) => {
1091-
t.plan(2)
1091+
t.plan(1)
10921092

10931093
const stringify = build({
10941094
title: 'object of required primitive (json) types',
@@ -1134,11 +1134,6 @@ test('toJSON supports required types', (t) => {
11341134
}
11351135
const expected = '{"_bool":true,"_int":42,"_null":null,"_num":3.14,"_str":"whatever"}'
11361136
t.equal(stringify(input), expected)
1137-
1138-
const invalidInput = {
1139-
toJSON () { return {} }
1140-
}
1141-
t.throws(() => { stringify(invalidInput) })
11421137
})
11431138

11441139
test('use toJSON recursively', (t) => {

0 commit comments

Comments
 (0)