From 80ea2ec3e3ac3ee9cb930d7c15b3d88bba7b151e Mon Sep 17 00:00:00 2001 From: mathis-m Date: Fri, 24 Sep 2021 02:57:12 +0200 Subject: [PATCH 1/2] feat(normalize): prepend inherited params instead --- src/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 8afe372a2..688438b46 100755 --- a/src/helpers.js +++ b/src/helpers.js @@ -205,7 +205,7 @@ export function normalizeSwagger(parsedSpec) { operation[inheritName] = inherits[inheritName]; } else if (inheritName === 'parameters') { // eslint-disable-next-line no-restricted-syntax - for (const param of inherits[inheritName]) { + for (const param of inherits[inheritName].slice(0).reverse()) { const exists = operation[inheritName].some( (opParam) => (opParam.name && opParam.name === param.name) || @@ -215,7 +215,7 @@ export function normalizeSwagger(parsedSpec) { ); if (!exists) { - operation[inheritName].push(param); + operation[inheritName].unshift(param); } } } From 118255414e119bd9ad9f298636e0f59cb685ef1a Mon Sep 17 00:00:00 2001 From: mathis-m Date: Fri, 24 Sep 2021 02:57:54 +0200 Subject: [PATCH 2/2] test(normalize): test for prepended inherited params instead --- test/helpers.js | 2 +- test/subtree-resolver.js | 52 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/test/helpers.js b/test/helpers.js index 983377abb..051cdcf4f 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -609,9 +609,9 @@ describe('helpers', () => { ], get: { parameters: [ + { name: 'b', in: 'path' }, { name: 'a', in: 'query' }, { name: 'c', in: 'query' }, - { name: 'b', in: 'path' }, ], }, }, diff --git a/test/subtree-resolver.js b/test/subtree-resolver.js index 62275f5f7..d671c8400 100644 --- a/test/subtree-resolver.js +++ b/test/subtree-resolver.js @@ -289,6 +289,15 @@ describe('subtree $ref resolver', () => { ], get: { parameters: [ + { + name: 'petId', + in: 'path', + description: 'ID of pet to return', + required: true, + type: 'integer', + format: 'int64', + $$ref: '#/parameters/petId', + }, { name: 'name', in: 'formData', @@ -303,15 +312,6 @@ describe('subtree $ref resolver', () => { required: false, type: 'string', }, - { - name: 'petId', - in: 'path', - description: 'ID of pet to return', - required: true, - type: 'integer', - format: 'int64', - $$ref: '#/parameters/petId', - }, ], }, }, @@ -410,14 +410,6 @@ describe('subtree $ref resolver', () => { delete: { summary: 'has own operation parameters', parameters: [ - { - name: 'Three', - in: 'query', - }, - { - name: 'Four', - in: 'query', - }, { type: 'string', name: 'One', @@ -430,6 +422,14 @@ describe('subtree $ref resolver', () => { in: 'query', $$ref: '#/parameters/Two', }, + { + name: 'Three', + in: 'query', + }, + { + name: 'Four', + in: 'query', + }, ], }, }, @@ -524,6 +524,15 @@ describe('subtree $ref resolver', () => { ], get: { parameters: [ + { + name: 'petId', + in: 'path', + description: 'ID of pet to return', + required: true, + type: 'integer', + format: 'int64', + $$ref: '#/parameters/petId', + }, { name: 'name', in: 'formData', @@ -538,15 +547,6 @@ describe('subtree $ref resolver', () => { required: false, type: 'string', }, - { - name: 'petId', - in: 'path', - description: 'ID of pet to return', - required: true, - type: 'integer', - format: 'int64', - $$ref: '#/parameters/petId', - }, ], }, },