Skip to content

Commit

Permalink
support capital letters in headers (#26)
Browse files Browse the repository at this point in the history
Ignore capital letters in swagger headers
  • Loading branch information
rotemza12 authored and idanto committed Feb 27, 2018
1 parent e56d143 commit 8801cf8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function buildParametersValidation(parameters) {

const required = parameter.required;
const source = typeNameConversion[parameter.in] || parameter.in;
const key = parameter.name;
const key = parameter.in === 'header' ? parameter.name.toLowerCase() : parameter.name;

var destination = ajvParametersSchema.properties[source];

Expand Down
24 changes: 24 additions & 0 deletions test/middleware-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,30 @@ describe('input-validation middleware tests', function () {
done();
});
});
it('headers are in capital letters - should pass validation', function (done) {
request(app)
.get('/v1/capital')
.set('Capital-Letters', '1.0')
.expect(200, function (err, res) {
if (err) {
throw err;
}
expect(res.body.result).to.equal('OK');
done();
});
});
it('headers are in lowercase letters - should pass validation', function (done) {
request(app)
.get('/v1/capital')
.set('capital-letters', '1.0')
.expect(200, function (err, res) {
if (err) {
throw err;
}
expect(res.body.result).to.equal('OK');
done();
});
});
it('missing header - should fail', function (done) {
request(app)
.get('/v1/pets')
Expand Down
14 changes: 13 additions & 1 deletion test/pet-store-swagger-with-base-path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ paths:
description: unexpected error
schema:
$ref: '#/definitions/Error'
/capital:
get:
parameters:
- $ref: '#/parameters/CapitalLetters'
responses:
"200":
description: An paged array of pets
definitions:
Pet:
required:
Expand Down Expand Up @@ -210,4 +217,9 @@ parameters:
description: 'global request id through the system.'
type: string
minLength: 1
x-example: '123456'
x-example: '123456'
CapitalLetters:
name: 'Capital-Letters'
in: header
required: true
type: string
3 changes: 3 additions & 0 deletions test/test-simple-server-with-base-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = inputValidation.init('test/pet-store-swagger-with-base-path.yam
app.post('/v1/pets', inputValidation.validate, function (req, res, next) {
res.json({ result: 'OK' });
});
app.get('/v1/capital', inputValidation.validate, function (req, res, next) {
res.json({ result: 'OK' });
});

app.use('/v1', router);

Expand Down

0 comments on commit 8801cf8

Please sign in to comment.