Skip to content

Commit

Permalink
apigee-127#380 fix validation of a numeric strings array
Browse files Browse the repository at this point in the history
  • Loading branch information
calibr committed May 28, 2016
1 parent b077f64 commit 5aa4f47
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
3 changes: 1 addition & 2 deletions middleware/swagger-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ var validateValue = function (req, schema, path, val, callback) {
var spec = cHelpers.getSpec(version);

val = mHelpers.convertValue(val, schema, mHelpers.getParameterType(schema));

try {
validators.validateSchemaConstraints(version, schema, path, val);
} catch (err) {
Expand Down Expand Up @@ -367,7 +366,7 @@ exports = module.exports = function (options) {
return oCallback();
}

validateValue(req, schema, paramPath, val, oCallback);
validateValue(req, schema.schema || schema, paramPath, val, oCallback);

paramIndex++;
}, function (err) {
Expand Down
57 changes: 57 additions & 0 deletions test/2.0/test-middleware-swagger-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,5 +1570,62 @@ describe('Swagger Validator Middleware v2.0', function () {
}
});
});

it('should consume/return array of strings if they are numeric (Issue 380)', function (done) {
var swaggerObject = _.cloneDeep(petStoreJson);

swaggerObject.paths['/tags'] = {
post: {
consumes: ['application/json; charset=utf-8'],
produces: ['application/json; charset=utf-8'],
summary: 'Save Tags',
description: 'save a list of tags.',
operationId: 'saveStringTags',
parameters: [
{
name: 'tags',
in: 'body',
description: 'tags',
required: true,
schema: {
type: 'array',
items: {
type: 'string'
}
}
}
],
responses: {
'200': {
description: 'OK',
schema: {
type: 'array',
items: {
type: 'string'
}
}
}
}
}
};
var tags = ['somephotourl', '123'];
helpers.createServer([swaggerObject], {
swaggerRouterOptions: {
controllers: {
saveStringTags: function (req, res) {
res.end(JSON.stringify(req.swagger.params.tags.value));
}
}
}
}, function (app) {
//
request(app)
.post('/api/tags')
.set('content-type', 'application/json; charset=utf-8')
.send(tags)
.expect(200)
.end(helpers.expectContent(tags, done));
});
});
});
});

0 comments on commit 5aa4f47

Please sign in to comment.