Skip to content

Commit 4471a40

Browse files
authored
Fix allOf with $ref property (#705)
1 parent bb08e77 commit 4471a40

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function cloneOriginSchema (context, schema, schemaId) {
438438
for (const key in schema) {
439439
let value = schema[key]
440440

441-
if (key === '$ref' && value.charAt(0) === '#') {
441+
if (key === '$ref' && typeof value === 'string' && value.charAt(0) === '#') {
442442
value = schemaId + value
443443
}
444444

test/allof.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,39 @@ test('external recursive allOfs', (t) => {
717717
const stringify = build(schema, { schema: { externalSchema } })
718718
t.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
719719
})
720+
721+
test('do not crash with $ref prop', (t) => {
722+
t.plan(1)
723+
724+
const schema = {
725+
title: 'object with $ref',
726+
type: 'object',
727+
properties: {
728+
outside: {
729+
$ref: '#/$defs/outside'
730+
}
731+
},
732+
$defs: {
733+
inside: {
734+
type: 'object',
735+
properties: {
736+
$ref: {
737+
type: 'string'
738+
}
739+
}
740+
},
741+
outside: {
742+
allOf: [{
743+
$ref: '#/$defs/inside'
744+
}]
745+
}
746+
}
747+
}
748+
const stringify = build(schema)
749+
const value = stringify({
750+
outside: {
751+
$ref: 'true'
752+
}
753+
})
754+
t.equal(value, '{"outside":{"$ref":"true"}}')
755+
})

0 commit comments

Comments
 (0)