diff --git a/src/middlewares/parsers/request.schema.preprocessor.ts b/src/middlewares/parsers/request.schema.preprocessor.ts index 82273c00..b25cbb24 100644 --- a/src/middlewares/parsers/request.schema.preprocessor.ts +++ b/src/middlewares/parsers/request.schema.preprocessor.ts @@ -57,16 +57,17 @@ export class RequestSchemaPreprocessor { if (parameters.length === 0) return; - const v = pathItem[pathItemKey]; + let v = pathItem[pathItemKey]; if (v === parameters) return; const ref = v?.parameters?.$ref; - const operationParameters = < - Array - >(ref ? this.ajv.getSchema(ref)?.schema : v.parameters); + const op = ref && this.ajv.getSchema(ref)?.schema; + if (op) + v = op; + v.parameters = v.parameters || []; for (const param of parameters) { - operationParameters.push(param); + v.parameters.push(param); } } diff --git a/test/path.params.spec.ts b/test/path.params.spec.ts index f53a8eef..2fba345e 100644 --- a/test/path.params.spec.ts +++ b/test/path.params.spec.ts @@ -17,7 +17,7 @@ describe('path params', () => { }, 3005, (app) => { - app.get(`${app.basePath}/users/:id?`, (req, res) => { + app.get([`${app.basePath}/users/:id?`, `${app.basePath}/users_alt/:id?`], (req, res) => { res.json({ id: req.params.id, }); @@ -51,7 +51,7 @@ describe('path params', () => { app.server.close(); }); - it('should url decode path parameters', async () => + it('should url decode path parameters (type level)', async () => request(app) .get(`${app.basePath}/users/c%20dimascio`) .expect(200) @@ -59,6 +59,14 @@ describe('path params', () => { expect(r.body.id).to.equal('c dimascio'); })); + it('should url decode path parameters (path level)', async () => + request(app) + .get(`${app.basePath}/users_alt/c%20dimascio`) + .expect(200) + .then((r) => { + expect(r.body.id).to.equal('c dimascio'); + })); + it('should handle path parameter with style=simple', async () => request(app) .get(`${app.basePath}/multi_users/aa,bb,cc`) diff --git a/test/resources/path.params.yaml b/test/resources/path.params.yaml index 38413ab7..832c93a6 100644 --- a/test/resources/path.params.yaml +++ b/test/resources/path.params.yaml @@ -20,6 +20,21 @@ paths: application/json: schema: $ref: "#/components/schemas/User" + /users_alt/{id}: + parameters: + - name: id + in: path + required: true + schema: + type: string + get: + responses: + 200: + description: "" + content: + application/json: + schema: + $ref: "#/components/schemas/User" /multi_users/{ids}: get: summary: Deletes Features given a number of uuids.