Skip to content

Commit

Permalink
Merge pull request #306 from cdimascio/305
Browse files Browse the repository at this point in the history
fix 305: Unable to use array as a path parameter
  • Loading branch information
cdimascio committed May 26, 2020
2 parents c108f06 + 8c01a79 commit c3a8aef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/middlewares/parsers/req.parameter.mutator.ts
Expand Up @@ -20,6 +20,7 @@ type ParameterObject = OpenAPIV3.ParameterObject;
const RESERVED_CHARS = /[\:\/\?#\[\]@!\$&\'()\*\+,;=]/;

const ARRAY_DELIMITER = {
simple: ',',
form: ',',
spaceDelimited: ' ',
pipeDelimited: '|',
Expand Down
19 changes: 16 additions & 3 deletions test/path.params.spec.ts
Expand Up @@ -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,
Expand All @@ -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');
}));
});
19 changes: 19 additions & 0 deletions test/resources/path.params.yaml
Expand Up @@ -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:
Expand Down

0 comments on commit c3a8aef

Please sign in to comment.