From a300b534dd5191985c433f06e7bf5997c1540f53 Mon Sep 17 00:00:00 2001 From: Josh Ponelat Date: Tue, 20 Mar 2018 13:09:55 +0200 Subject: [PATCH 1/3] add test for nested allOf + $ref --- test/specmap/all-of.js | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) 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], From ae2c977e04a1d874d994c41e6b0479260e323dc0 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Thu, 12 Apr 2018 19:09:18 -0700 Subject: [PATCH 2/3] don't reach into originalDefinitionObj if it doesn't contain our key --- src/specmap/lib/all-of.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/specmap/lib/all-of.js b/src/specmap/lib/all-of.js index 6953d960c..3a4d1e77a 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) From fb3a5e303d325e5d9875a0c7709e55ee90a27aec Mon Sep 17 00:00:00 2001 From: kyle Date: Fri, 13 Apr 2018 12:45:27 -0700 Subject: [PATCH 3/3] satisfy linter --- src/specmap/lib/all-of.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/specmap/lib/all-of.js b/src/specmap/lib/all-of.js index 3a4d1e77a..ebe4905b4 100644 --- a/src/specmap/lib/all-of.js +++ b/src/specmap/lib/all-of.js @@ -28,7 +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 + if (!originalDefinitionObj) return // bail out if we've lost sight of our target originalDefinitionObj = originalDefinitionObj[part] }) originalDefinitionObj = Object.assign({}, originalDefinitionObj)