Skip to content

Commit bf48f83

Browse files
authored
omit symbol properties for anyOf (#272)
1 parent 0e5ea7d commit bf48f83

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ function nested (laterCode, name, key, location, subKey, isArray) {
11591159
// 2. `nested`, through `buildCode`, replaces any reference in object properties with the actual schema
11601160
// (see https://github.com/fastify/fast-json-stringify/blob/6da3b3e8ac24b1ca5578223adedb4083b7adf8db/index.js#L631)
11611161
code += `
1162-
${index === 0 ? 'if' : 'else if'}(ajv.validate(${require('util').inspect(location.schema, { depth: null, maxArrayLength: null })}, obj${accessor}))
1162+
${index === 0 ? 'if' : 'else if'}(ajv.validate(${JSON.stringify(location.schema)}, obj${accessor}))
11631163
${nestedResult.code}
11641164
`
11651165
laterCode = nestedResult.laterCode

test/anyof.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@ test('null value in schema', (t) => {
197197
build(schema)
198198
})
199199

200+
test('symbol value in schema', (t) => {
201+
t.plan(4)
202+
203+
const ObjectKind = Symbol('LiteralKind')
204+
const UnionKind = Symbol('UnionKind')
205+
const LiteralKind = Symbol('LiteralKind')
206+
207+
const schema = {
208+
kind: ObjectKind,
209+
type: 'object',
210+
properties: {
211+
value: {
212+
kind: UnionKind,
213+
anyOf: [
214+
{ kind: LiteralKind, type: 'string', enum: ['foo'] },
215+
{ kind: LiteralKind, type: 'string', enum: ['bar'] },
216+
{ kind: LiteralKind, type: 'string', enum: ['baz'] }
217+
]
218+
}
219+
},
220+
required: ['value']
221+
}
222+
223+
const stringify = build(schema)
224+
t.is(stringify({ value: 'foo' }), '{"value":"foo"}')
225+
t.is(stringify({ value: 'bar' }), '{"value":"bar"}')
226+
t.is(stringify({ value: 'baz' }), '{"value":"baz"}')
227+
t.is(stringify({ value: 'qux' }), '{"value":null}')
228+
})
229+
200230
test('anyOf and $ref together', (t) => {
201231
t.plan(2)
202232

0 commit comments

Comments
 (0)