diff --git a/packages/oas/src/utils/params.ts b/packages/oas/src/utils/params.ts index 9b2fd2b4..b53891d2 100644 --- a/packages/oas/src/utils/params.ts +++ b/packages/oas/src/utils/params.ts @@ -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( - 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()]; }; diff --git a/packages/oas/tests/fixtures/path-item.params.resolution.oas.result.json b/packages/oas/tests/fixtures/path-item.params.resolution.oas.result.json index 94d4609f..61bc213d 100644 --- a/packages/oas/tests/fixtures/path-item.params.resolution.oas.result.json +++ b/packages/oas/tests/fixtures/path-item.params.resolution.oas.result.json @@ -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" } ] diff --git a/packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml b/packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml index 281a3796..db36e9b6 100644 --- a/packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml +++ b/packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml @@ -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