Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

BUG: swagger-metadata can't read value 1 of undefined #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions middleware/swagger-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ exports = module.exports = function (rlOrSO, apiDeclarations) {
var metadata;

cacheEntry = apiCache[path] || _.find(apiCache, function (metadata) {
match = metadata.re.exec(path);
return _.isArray(match);
var isFound = metadata.re.exec(path);
return _.isArray(isFound);
});

debug('%s %s', req.method, req.url);
Expand All @@ -409,6 +409,7 @@ exports = module.exports = function (rlOrSO, apiDeclarations) {
if (!cacheEntry) {
return next();
}
match = cacheEntry.re.exec(path);

metadata = swaggerVersion === '1.2' ?
{
Expand Down
11 changes: 11 additions & 0 deletions test/2.0/test-middleware-swagger-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ describe('Swagger Metadata Middleware v2.0', function () {
});
});

it('should not crash when passing wrong data in path',function(done) {
var cPetStoreJson = _.cloneDeep(petStoreJson);

helpers.createServer([cPetStoreJson],{}, function (app) {
request(app)
.get('/api/pets/:id')
.expect(400)
.end(helpers.expectContent('Request validation failed: Parameter (id) is not a valid int64 integer: :id', done));
});
});

describe('non-multipart form parameters', function () {
it('should handle primitives', function (done) {
var cPetStoreJson = _.cloneDeep(petStoreJson);
Expand Down