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

pass an actual schema to the mHelpers.convertValue #387

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion middleware/swagger-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 60 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,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));
});
});
});
});