Skip to content

Commit 98c9a1c

Browse files
authored
fix: nested allOf + $ref resolution (#1282)
* add test for nested allOf + $ref * don't reach into originalDefinitionObj if it doesn't contain our key * satisfy linter
1 parent 7cec49c commit 98c9a1c

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/specmap/lib/all-of.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default {
2828
// Remove the `allOf` property so it doesn't get added to the result of the `allOf` plugin
2929
let originalDefinitionObj = patch.value
3030
parent.forEach((part) => {
31+
if (!originalDefinitionObj) return // bail out if we've lost sight of our target
3132
originalDefinitionObj = originalDefinitionObj[part]
3233
})
3334
originalDefinitionObj = Object.assign({}, originalDefinitionObj)

test/specmap/all-of.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,68 @@ describe('allOf', function () {
328328
})
329329
})
330330

331+
it('should suppport nested allOfs with $refs', function () {
332+
return mapSpec({
333+
plugins: [plugins.refs, plugins.allOf],
334+
spec: {
335+
definitions: {
336+
Alpha: {
337+
allOf: [{type: 'object'}],
338+
properties: {
339+
one: {
340+
$ref: '#/definitions/Bravo'
341+
},
342+
two: {
343+
type: 'string'
344+
}
345+
}
346+
},
347+
Bravo: {
348+
allOf: [{
349+
type: 'object',
350+
properties: {
351+
three: {
352+
type: 'string'
353+
}
354+
}
355+
}]
356+
}
357+
}
358+
}
359+
}).then((res) => {
360+
// To show the error, unfortunately, the expect call doesn't pretty print it nicely
361+
// console.log(res.errors[0])
362+
expect(res.errors).toEqual([])
363+
expect(res.spec).toEqual({
364+
definitions: {
365+
Alpha: {
366+
type: 'object',
367+
properties: {
368+
one: {
369+
type: 'object',
370+
properties: {
371+
three: {
372+
type: 'string',
373+
}
374+
}
375+
},
376+
two: {
377+
type: 'string'
378+
}
379+
}
380+
},
381+
Bravo: {
382+
type: 'object',
383+
properties: {
384+
three: {
385+
type: 'string'
386+
}
387+
}
388+
}
389+
},
390+
})
391+
})
392+
})
331393
it('merges arrays inside of an `allOf`', function () {
332394
return mapSpec({
333395
plugins: [plugins.refs, plugins.allOf],

0 commit comments

Comments
 (0)