diff --git a/src/specmap/lib/all-of.js b/src/specmap/lib/all-of.js index 6953d960c..ebe4905b4 100644 --- a/src/specmap/lib/all-of.js +++ b/src/specmap/lib/all-of.js @@ -28,6 +28,7 @@ export default { // Remove the `allOf` property so it doesn't get added to the result of the `allOf` plugin let originalDefinitionObj = patch.value parent.forEach((part) => { + if (!originalDefinitionObj) return // bail out if we've lost sight of our target originalDefinitionObj = originalDefinitionObj[part] }) originalDefinitionObj = Object.assign({}, originalDefinitionObj) diff --git a/test/specmap/all-of.js b/test/specmap/all-of.js index 4deeeeab7..f9f29917d 100644 --- a/test/specmap/all-of.js +++ b/test/specmap/all-of.js @@ -328,6 +328,68 @@ describe('allOf', function () { }) }) + it('should suppport nested allOfs with $refs', function () { + return mapSpec({ + plugins: [plugins.refs, plugins.allOf], + spec: { + definitions: { + Alpha: { + allOf: [{type: 'object'}], + properties: { + one: { + $ref: '#/definitions/Bravo' + }, + two: { + type: 'string' + } + } + }, + Bravo: { + allOf: [{ + type: 'object', + properties: { + three: { + type: 'string' + } + } + }] + } + } + } + }).then((res) => { + // To show the error, unfortunately, the expect call doesn't pretty print it nicely + // console.log(res.errors[0]) + expect(res.errors).toEqual([]) + expect(res.spec).toEqual({ + definitions: { + Alpha: { + type: 'object', + properties: { + one: { + type: 'object', + properties: { + three: { + type: 'string', + } + } + }, + two: { + type: 'string' + } + } + }, + Bravo: { + type: 'object', + properties: { + three: { + type: 'string' + } + } + } + }, + }) + }) + }) it('merges arrays inside of an `allOf`', function () { return mapSpec({ plugins: [plugins.refs, plugins.allOf],