зеркало из https://github.com/Azure/sway.git
Keep origin customized validator (#97)
* Don't reset customized validator. Added unit test.
This commit is contained in:
Родитель
210d29e22b
Коммит
6016762e88
|
@ -368,10 +368,7 @@ function checkGlobalParameterInRequest (schema, json, report) {
|
|||
var isResponse = this.validateOptions && this.validateOptions.isResponse
|
||||
|
||||
if (!isResponse && schema && schema.schema && json !== undefined) {
|
||||
if (this.options && this.options.customValidator) {
|
||||
this.options.customValidator = null
|
||||
ZSchemaValidator.validate.call(this, report, schema.schema, json)
|
||||
}
|
||||
ZSchemaValidator.validate.call(this, report, schema.schema, json)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "yasway",
|
||||
"version": "1.9.2",
|
||||
"version": "1.9.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "yasway",
|
||||
"version": "1.9.2",
|
||||
"version": "1.9.3",
|
||||
"description": "A library that simplifies Swagger integrations.",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
|
|
|
@ -715,6 +715,49 @@ describe('Operation', function () {
|
|||
operation = swaggerApi.getOperation('/pet', 'post');
|
||||
});
|
||||
|
||||
it('body parameter with schema', function (done) {
|
||||
var cSwagger2 = _.cloneDeep(helpers.swaggerDoc);
|
||||
|
||||
cSwagger2.parameters = {
|
||||
petInfoParam: {
|
||||
in: 'body',
|
||||
name: 'petInfo',
|
||||
required: true,
|
||||
schema: {
|
||||
$ref: '#/definitions/Pet'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cSwagger2.paths['/user/createWithList'].post.parameters = [
|
||||
{
|
||||
$ref: '#/parameters/petInfoParam'
|
||||
}
|
||||
];
|
||||
Sway.create({
|
||||
definition: cSwagger2
|
||||
})
|
||||
.then(function (api) {
|
||||
var operation1 = api.getOperation('/user/createWithList', 'post');
|
||||
var results = operation1.validateRequest({
|
||||
url: '/v2/user/createWithList',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: {
|
||||
petType: 'dog'
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(results.warnings.length, 0);
|
||||
assert.equal(results.errors.length, 1);
|
||||
assert.equal(results.errors[0].errors.length, 2);
|
||||
assert.equal(results.errors[0].errors[0].code, 'OBJECT_MISSING_REQUIRED_PROPERTY');
|
||||
assert.equal(results.errors[0].errors[1].code, 'OBJECT_MISSING_REQUIRED_PROPERTY');
|
||||
})
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
it('should return an error for an unsupported value', function () {
|
||||
var request = _.cloneDeep(baseRequest);
|
||||
var results;
|
||||
|
|
Загрузка…
Ссылка в новой задаче