Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited parameters should be before operation method level parameters #2256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand All @@ -215,7 +215,7 @@ export function normalizeSwagger(parsedSpec) {
);

if (!exists) {
operation[inheritName].push(param);
operation[inheritName].unshift(param);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ describe('helpers', () => {
],
get: {
parameters: [
{ name: 'b', in: 'path' },
{ name: 'a', in: 'query' },
{ name: 'c', in: 'query' },
{ name: 'b', in: 'path' },
],
},
},
Expand Down
52 changes: 26 additions & 26 deletions test/subtree-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
},
],
},
},
Expand Down Expand Up @@ -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',
Expand All @@ -430,6 +422,14 @@ describe('subtree $ref resolver', () => {
in: 'query',
$$ref: '#/parameters/Two',
},
{
name: 'Three',
in: 'query',
},
{
name: 'Four',
in: 'query',
},
],
},
},
Expand Down Expand Up @@ -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',
Expand All @@ -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',
},
],
},
},
Expand Down