Skip to content

Commit 7acc486

Browse files
author
calibr
committed
apigee-127#380 fix validation of a numeric strings array
1 parent b077f64 commit 7acc486

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

middleware/swagger-validator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ exports = module.exports = function (options) {
367367
return oCallback();
368368
}
369369

370-
validateValue(req, schema, paramPath, val, oCallback);
370+
validateValue(req, schema.schema || schema, paramPath, val, oCallback);
371371

372372
paramIndex++;
373373
}, function (err) {

test/2.0/test-middleware-swagger-validator.js

+57
Original file line numberDiff line numberDiff line change
@@ -1570,5 +1570,62 @@ describe('Swagger Validator Middleware v2.0', function () {
15701570
}
15711571
});
15721572
});
1573+
1574+
it('should consume/return array of strings if they are numeric (Issue 380)', function (done) {
1575+
var swaggerObject = _.cloneDeep(petStoreJson);
1576+
1577+
swaggerObject.paths['/tags'] = {
1578+
post: {
1579+
consumes: ['application/json; charset=utf-8'],
1580+
produces: ['application/json; charset=utf-8'],
1581+
summary: 'Save Tags',
1582+
description: 'save a list of tags.',
1583+
operationId: 'saveStringTags',
1584+
parameters: [
1585+
{
1586+
name: 'tags',
1587+
in: 'body',
1588+
description: 'tags',
1589+
required: true,
1590+
schema: {
1591+
type: 'array',
1592+
items: {
1593+
type: 'string'
1594+
}
1595+
}
1596+
}
1597+
],
1598+
responses: {
1599+
'200': {
1600+
description: 'OK',
1601+
schema: {
1602+
type: 'array',
1603+
items: {
1604+
type: 'string'
1605+
}
1606+
}
1607+
}
1608+
}
1609+
}
1610+
};
1611+
var tags = ['somephotourl', '123'];
1612+
helpers.createServer([swaggerObject], {
1613+
swaggerRouterOptions: {
1614+
controllers: {
1615+
saveStringTags: function (req, res) {
1616+
res.end(JSON.stringify(req.swagger.params.tags.value));
1617+
}
1618+
}
1619+
}
1620+
}, function (app) {
1621+
//
1622+
request(app)
1623+
.post('/api/tags')
1624+
.set('content-type', 'application/json; charset=utf-8')
1625+
.send(tags)
1626+
.expect(200)
1627+
.end(helpers.expectContent(tags, done));
1628+
});
1629+
});
15731630
});
15741631
});

0 commit comments

Comments
 (0)