diff --git a/index.js b/index.js index a4c43b56..b6c2e79b 100644 --- a/index.js +++ b/index.js @@ -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 } diff --git a/test/const.test.js b/test/const.test.js index c0b0b0aa..84706704 100644 --- a/test/const.test.js +++ b/test/const.test.js @@ -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' }) @@ -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({