Skip to content

Commit

Permalink
Escape colons in path. Fixes #320
Browse files Browse the repository at this point in the history
  • Loading branch information
siimsoni committed Oct 30, 2020
1 parent a3908cd commit 1e3bd24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/framework/openapi.spec.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export class OpenApiSpecLoader {
}
const openApiRoute = `${bp}${path}`;
const expressRoute = `${openApiRoute}`
.split('/')
.split(':')
.map(toExpressParams)
.join('/');
.join('\\:');

routes.push({
basePath: bp,
Expand Down
16 changes: 6 additions & 10 deletions test/path.params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ describe('path params', () => {
id: req.params.id,
});
});
app.get(`${app.basePath}/users:lookup`, (req, res) => {
res.json([
{
id: req.query.name,
},
]);
app.get(`${app.basePath}/user_lookup\\::name`, (req, res) => {
res.json({
id: req.params.name,
});
});
app.get(`${app.basePath}/multi_users/:ids?`, (req, res) => {
res.json({
Expand Down Expand Up @@ -77,11 +75,9 @@ describe('path params', () => {

it("should handle :'s in path parameters", async () =>
request(app)
.get(`${app.basePath}/users:lookup`)
.query({ name: 'carmine' })
.get(`${app.basePath}/user_lookup:carmine`)
.expect(200)
.then((r) => {
expect(r.body).to.be.an('array');
expect(r.body[0].id).to.equal('carmine');
expect(r.body.id).to.equal('carmine');
}));
});
8 changes: 3 additions & 5 deletions test/resources/path.params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ paths:
application/json:
schema:
type: object
"/users:lookup":
"/user_lookup:{name}":
get:
parameters:
- name: name
in: query
in: path
required: true
schema:
type: string
Expand All @@ -68,9 +68,7 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/User"
$ref: "#/components/schemas/User"
components:
schemas:
User:
Expand Down

0 comments on commit 1e3bd24

Please sign in to comment.