Skip to content

Commit

Permalink
feat: drop nullable const support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed Sep 2, 2022
1 parent ab900c8 commit 1b9d5a1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,6 @@ function buildValue (location, input) {
let funcName

if ('const' in schema) {
if (nullable) {
code += `
json += ${input} === null ? 'null' : '${JSON.stringify(schema.const)}'
`
return code
}
code += `json += '${JSON.stringify(schema.const)}'`
return code
}
Expand Down
4 changes: 2 additions & 2 deletions test/const.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ test('schema with const and null as type', (t) => {
foo: null
})

t.equal(output, '{"foo":null}')
t.equal(output, '{"foo":"baz"}')
t.ok(validate(JSON.parse(output)), 'valid schema')

const output2 = stringify({ foo: 'baz' })
Expand All @@ -262,7 +262,7 @@ test('schema with const as nullable', (t) => {
foo: null
})

t.equal(output, '{"foo":null}')
t.equal(output, '{"foo":"baz"}')
t.ok(validate(JSON.parse(output)), 'valid schema')

const output2 = stringify({
Expand Down

0 comments on commit 1b9d5a1

Please sign in to comment.