-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from cdimascio/url_encoded_path_params
decode urlencoded path parameters #256
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as path from 'path'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
|
||
const apiSpecPath = path.join('test', 'resources', 'path.params.yaml'); | ||
|
||
describe('path params', () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// set up express app | ||
app = await createApp( | ||
{ | ||
apiSpec: apiSpecPath, | ||
validateResponses: true, | ||
}, | ||
3005, | ||
app => { | ||
app.get(`${app.basePath}/users/:id?`, (req, res) => { | ||
res.json({ | ||
id: req.params.id, | ||
}); | ||
}); | ||
|
||
app.use((err, req, res, next) => { | ||
res.status(err.status ?? 500).json({ | ||
message: err.message, | ||
code: err.status ?? 500, | ||
}); | ||
}); | ||
}, | ||
false, | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should url decode path parameters', async () => | ||
request(app) | ||
.get(`${app.basePath}/users/c%20dimascio`) | ||
.expect(200) | ||
.then(r => { | ||
expect(r.body.id).to.equal('c dimascio'); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
openapi: "3.0.0" | ||
info: | ||
title: "Test for allOf" | ||
version: "1" | ||
servers: | ||
- url: /v1/ | ||
paths: | ||
/users/{id}: | ||
get: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
200: | ||
description: "" | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/User" | ||
components: | ||
schemas: | ||
User: | ||
type: object | ||
properties: | ||
id: | ||
type: "string" |