Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 305: Unable to use array as a path parameter #306

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/middlewares/parsers/req.parameter.mutator.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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