Skip to content

Commit 1a7b975

Browse files
fix: serialize schema with boolean type (#489)
1 parent 967bacf commit 1a7b975

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ function generateFuncName () {
772772
function buildValue (location, input) {
773773
let schema = location.schema
774774

775+
if (typeof schema === 'boolean') {
776+
return `json += JSON.stringify(${input})`
777+
}
778+
775779
if (schema.$ref) {
776780
location = resolveRef(location, schema.$ref)
777781
schema = location.schema

test/basic.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,16 @@ test('render a single quote as JSON', (t) => {
359359
t.equal(output, JSON.stringify(toStringify))
360360
t.ok(validate(JSON.parse(output)), 'valid schema')
361361
})
362+
363+
test('returns JSON.stringify if schema type is boolean', t => {
364+
t.plan(1)
365+
366+
const schema = {
367+
type: 'array',
368+
items: true
369+
}
370+
371+
const array = [1, true, 'test']
372+
const stringify = build(schema)
373+
t.equal(stringify(array), JSON.stringify(array))
374+
})

0 commit comments

Comments
 (0)