From 56a6c3621be2fcee5dc0cdfbce748737dad8ce99 Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Thu, 19 Aug 2021 15:55:37 +0200 Subject: [PATCH 1/2] AWS2OPENAPI-45 fix: remove generic 'allOf' composites - only keep them where we actually have multiple types that are accepted --- index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 07c827b..45bf0d6 100644 --- a/index.js +++ b/index.js @@ -490,12 +490,18 @@ function transformShape(openapi,shape){ recurse(shape,{},function(obj,key,state){ // do this in separate pass, refs #41 - if ((key === '$ref') && (typeof obj.$ref === 'string') && (Object.keys(obj).length > 1) && (!obj.allOf)) { - const $ref = obj.$ref; - delete obj.$ref; - delete obj.tags; // were previously being ignored as siblings of a $ref - delete obj.location; - state.parent[state.pkey] = { allOf: [ { $ref }, obj ] }; + if ((key === '$ref') && (typeof obj.$ref === 'string') && (!obj.allOf)) { + const keys = Object.keys(obj); + if (keys.length === 2 && keys[1] === "description") { + return; + } + if (keys.length > 1) { + const $ref = obj.$ref; + delete obj.$ref; + delete obj.tags; // were previously being ignored as siblings of a $ref + delete obj.location; + state.parent[state.pkey] = { allOf: [ { $ref }, obj ] }; + } } }); From 5c74729e98ceb25c85369096011baf133ea17ace Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Tue, 24 Aug 2021 11:17:07 +0200 Subject: [PATCH 2/2] AWS2OPENAPI-45 description out ouf allOf compositions makes the spec more compliant with swagger-codegen --- index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 45bf0d6..b77a0dc 100644 --- a/index.js +++ b/index.js @@ -490,18 +490,18 @@ function transformShape(openapi,shape){ recurse(shape,{},function(obj,key,state){ // do this in separate pass, refs #41 - if ((key === '$ref') && (typeof obj.$ref === 'string') && (!obj.allOf)) { - const keys = Object.keys(obj); - if (keys.length === 2 && keys[1] === "description") { - return; - } - if (keys.length > 1) { - const $ref = obj.$ref; - delete obj.$ref; - delete obj.tags; // were previously being ignored as siblings of a $ref - delete obj.location; - state.parent[state.pkey] = { allOf: [ { $ref }, obj ] }; + if ((key === '$ref') && (typeof obj.$ref === 'string') && (Object.keys(obj).length > 1) && (!obj.allOf)) { + const $ref = obj.$ref; + delete obj.$ref; + const description = obj.description + delete obj.description; + delete obj.tags; // were previously being ignored as siblings of a $ref + delete obj.location; + allOf = [ { $ref } ] + if (Object.keys(obj).length > 0) { + allOf.push(obj); } + state.parent[state.pkey] = { description, allOf }; } });