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) #415 Cannot read property 'push' of undefined bug #420

Merged
merged 1 commit into from
Oct 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/middlewares/parsers/request.schema.preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>
>(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);
}
}

Expand Down
12 changes: 10 additions & 2 deletions test/path.params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -51,14 +51,22 @@ 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)
.then((r) => {
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`)
Expand Down
15 changes: 15 additions & 0 deletions test/resources/path.params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down