Skip to content

Commit 12a551a

Browse files
authored
fix: allOf withing $ref within allOf (#368) (#375)
1 parent 0fe5f8a commit 12a551a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ function buildCode (location, code, laterCode, name) {
819819
`
820820
}
821821

822+
if (schema.allOf) {
823+
const builtCode = buildCodeWithAllOfs(location, code, laterCode, name)
824+
code = builtCode.code
825+
laterCode = builtCode.laterCode
826+
}
827+
822828
return { code: code, laterCode: laterCode }
823829
}
824830

test/allof.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,58 @@ test('object with multiple $refs in allOf', (t) => {
277277
t.equal(value, '{"id1":1,"id2":2}')
278278
})
279279

280+
test('allOf with nested allOf in $ref', (t) => {
281+
t.plan(1)
282+
283+
const schema = {
284+
title: 'allOf with nested allOf in $ref',
285+
type: 'object',
286+
definitions: {
287+
group: {
288+
type: 'object',
289+
allOf: [{
290+
properties: {
291+
id2: {
292+
type: 'integer'
293+
}
294+
}
295+
}, {
296+
properties: {
297+
id3: {
298+
type: 'integer'
299+
}
300+
}
301+
}]
302+
}
303+
},
304+
allOf: [
305+
{
306+
type: 'object',
307+
properties: {
308+
id1: {
309+
type: 'integer'
310+
}
311+
},
312+
required: [
313+
'id1'
314+
]
315+
},
316+
{
317+
$ref: '#/definitions/group'
318+
}
319+
]
320+
}
321+
322+
const stringify = build(schema)
323+
const value = stringify({
324+
id1: 1,
325+
id2: 2,
326+
id3: 3,
327+
id4: 4 // extra prop shouldn't be in result
328+
})
329+
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
330+
})
331+
280332
test('object with external $refs in allOf', (t) => {
281333
t.plan(1)
282334

0 commit comments

Comments
 (0)