Skip to content

Commit

Permalink
fix(oas): address review comments
Browse files Browse the repository at this point in the history
fixes #248
  • Loading branch information
ostridm committed Aug 22, 2024
1 parent 7d8d8d4 commit f95f1f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
10 changes: 3 additions & 7 deletions packages/oas/src/utils/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ export const getParameters = (
path: string,
method: string
): ParameterObject[] => {
const pathParams = [...(spec.paths[path]?.parameters ?? [])].filter(
assertDereferencedParam
);
const operationParams = [
const params = [
...(spec.paths[path]?.parameters ?? []),
...(getOperation(spec, path, method)?.parameters ?? [])
].filter(assertDereferencedParam);

const combinedParams = new Map<string, ParameterObject>(
pathParams.map((x) => [`${x.in}:${x.name}`, x])
params.map((x) => [`${x.in}:${x.name}`, x])
);

operationParams.forEach((x) => combinedParams.set(`${x.in}:${x.name}`, x));

return [...combinedParams.values()];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "https://brokencrystals.com/users/42"
},
{
"bodySize": 0,
"cookies": [],
"headers": [],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"queryString": [],
"url": "https://brokencrystals.com/users/lorem"
},
{
"bodySize": 0,
"cookies": [],
"headers": [],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "PUT",
"queryString": [],
"url": "https://brokencrystals.com/users/lorem"
"url": "https://brokencrystals.com/org/lorem/users/42/devices/42"
}
]
30 changes: 13 additions & 17 deletions packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,34 @@ info:
servers:
- url: https://brokencrystals.com
paths:
/users/{id}:
/org/{orgId}/users/{userId}/devices/{deviceId}:
parameters:
- $ref: '#/components/parameters/orgId'
- in: path
name: id
name: userId
required: true
schema:
type: number
type: string
get:
responses:
'200':
description: ''
post:
parameters:
- in: path
name: id
name: userId
required: true
schema:
type: string
responses:
'200':
description: ''
put:
parameters:
- $ref: '#/components/parameters/userid'
type: number
- in: path
name: deviceId
required: true
schema:
type: number
responses:
'200':
description: ''
components:
parameters:
userid:
orgId:
in: path
name: id
name: orgId
required: true
schema:
type: string

0 comments on commit f95f1f2

Please sign in to comment.