From fa8d453374104d9bebd5727d17925c323757c55e Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Mon, 25 May 2020 20:49:30 -0400 Subject: [PATCH] fix 305: Unable to use array as a path parameter --- .../parsers/req.parameter.mutator.ts | 1 + test/path.params.spec.ts | 19 ++++++++++++++++--- test/resources/path.params.yaml | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/middlewares/parsers/req.parameter.mutator.ts b/src/middlewares/parsers/req.parameter.mutator.ts index ec688233..113368ab 100644 --- a/src/middlewares/parsers/req.parameter.mutator.ts +++ b/src/middlewares/parsers/req.parameter.mutator.ts @@ -20,6 +20,7 @@ type ParameterObject = OpenAPIV3.ParameterObject; const RESERVED_CHARS = /[\:\/\?#\[\]@!\$&\'()\*\+,;=]/; const ARRAY_DELIMITER = { + simple: ',', form: ',', spaceDelimited: ' ', pipeDelimited: '|', diff --git a/test/path.params.spec.ts b/test/path.params.spec.ts index 4f2b6e5b..8db3e770 100644 --- a/test/path.params.spec.ts +++ b/test/path.params.spec.ts @@ -16,13 +16,17 @@ describe('path params', () => { validateResponses: true, }, 3005, - app => { + (app) => { app.get(`${app.basePath}/users/:id?`, (req, res) => { res.json({ id: req.params.id, }); }); - + app.get(`${app.basePath}/multi_users/:ids?`, (req, res) => { + res.json({ + ids: req.params.ids, + }); + }); app.use((err, req, res, next) => { res.status(err.status ?? 500).json({ message: err.message, @@ -42,7 +46,16 @@ describe('path params', () => { request(app) .get(`${app.basePath}/users/c%20dimascio`) .expect(200) - .then(r => { + .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`) + // .expect(200) + .then((r) => { + console.log(r.body); + // expect(r.body.id).to.equal('c dimascio'); + })); }); diff --git a/test/resources/path.params.yaml b/test/resources/path.params.yaml index 4797e40e..e2b55def 100644 --- a/test/resources/path.params.yaml +++ b/test/resources/path.params.yaml @@ -20,6 +20,25 @@ paths: application/json: schema: $ref: "#/components/schemas/User" + /multi_users/{ids}: + get: + summary: Deletes Features given a number of uuids. + parameters: + - in: path + name: ids + required: true + schema: + type: array + items: + type: string + style: simple + responses: + "200": + description: Features were successfully deleted + content: + application/json: + schema: + type: object components: schemas: User: