diff --git a/middleware/swagger-validator.js b/middleware/swagger-validator.js index 3ac5f4caa9..b175b63a72 100644 --- a/middleware/swagger-validator.js +++ b/middleware/swagger-validator.js @@ -113,7 +113,7 @@ var validateValue = function (req, schema, path, val, callback) { var isModel = mHelpers.isModelParameter(version, schema); var spec = cHelpers.getSpec(version); - val = mHelpers.convertValue(val, schema, mHelpers.getParameterType(schema)); + val = mHelpers.convertValue(val, schema.schema ? schema.schema : schema, mHelpers.getParameterType(schema)); try { validators.validateSchemaConstraints(version, schema, path, val); diff --git a/test/2.0/test-middleware-swagger-validator.js b/test/2.0/test-middleware-swagger-validator.js index 803282d196..756ff7db0f 100644 --- a/test/2.0/test-middleware-swagger-validator.js +++ b/test/2.0/test-middleware-swagger-validator.js @@ -1570,5 +1570,65 @@ 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)); + } + } + }, + swaggerValidatorOptions: { + validateResponse: true + } + }, function (app) { + // + request(app) + .post('/api/tags') + .set('content-type', 'application/json; charset=utf-8') + .send(tags) + .expect(200) + .end(helpers.expectContent(tags, done)); + }); + }); }); });