This commit is contained in:
Vlad Barosan 2018-03-15 14:53:01 -07:00
Родитель 2fbf9d8164
Коммит 1530142a2a
4 изменённых файлов: 80 добавлений и 37 удалений

Просмотреть файл

@ -759,15 +759,34 @@ function isPropertyRequired(propName, model) {
*/
exports.statusCodeStringToStatusCode = lodash.invert(lodash.mapValues(http.STATUS_CODES, value => { return value.replace(/ |-/g, "").toLowerCase(); }));
/**
* Models an ARM cloud error.
* Models an ARM cloud error schema.
*/
exports.CloudError = {
exports.CloudErrorSchema = {
description: "Error response describing why the operation failed.",
schema: {
"$ref": "#/definitions/CloudErrorWrapper"
}
};
/**
* Models an ARM cloud error wrapper.
*/
exports.CloudErrorWrapper = {
type: "object",
properties: {
error: {
"$ref": "#/definitions/CloudError"
}
},
additionalProperties: false
};
/**
* Models a Cloud Error
*/
exports.CloudError = {
type: "object",
properties: {
code: {
type: "string",
@ -792,9 +811,6 @@ exports.CloudError = {
description: "A list of additional info about an error."
}
},
required: ["code", "message"],
additionalProperties: false
}
},
additionalProperties: false
}
};

Просмотреть файл

@ -607,12 +607,15 @@ class SpecResolver {
modelImplicitDefaultResponse() {
let self = this;
let spec = self.specInJson;
if (!spec.definitions.CloudError) {
spec.definitions.CloudErrorWrapper = utils.CloudErrorWrapper;
spec.definitions.CloudError = utils.CloudError;
}
for (let pathObj of utils.getValues(spec.paths)) {
for (let operation of utils.getValues(pathObj)) {
// going through responses
if (operation.responses && !operation.responses.default) {
operation.responses.default = utils.CloudError;
operation.responses.default = utils.CloudErrorSchema;
}
}
}

2
package-lock.json сгенерированный
Просмотреть файл

@ -2333,7 +2333,7 @@
}
},
"sway": {
"version": "github:amarzavery/sway#21d2160311380134e31e252a7e1ce1268441c8c3",
"version": "github:amarzavery/sway#6fe07a9dc10d301b84b985c8f0a27eed7bb0e4c9",
"requires": {
"debug": "3.1.0",
"faker": "4.1.0",

Просмотреть файл

@ -6,7 +6,8 @@ var assert = require('assert'),
os = require('os'),
glob = require('glob'),
LiveValidator = require('../lib/validators/liveValidator.js'),
Constants = require('../lib/util/constants');
Constants = require('../lib/util/constants'),
utils = require('../lib/util/utils');
const livePaths = glob.sync(path.join(__dirname, 'liveValidation/swaggers/**/live/*.json'));
describe('Live Validator', function () {
@ -260,6 +261,29 @@ describe('Live Validator', function () {
done();
}).catch(done);
});
it('it should create an implicit default response and find it', function (done) {
let options = {
"directory": "./test/liveValidation/swaggers/specification/scenarios",
"swaggerPathsPattern": "**/*.json",
"shouldModelImplicitDefaultResponse": true
};
let apiUrl = "https://management.azure.com/subscriptions/subscriptionId/providers/Microsoft.Test/storageAccounts?api-version=2016-01-01";
let validator = new LiveValidator(options);
validator.initialize().then(() => {
// Operations to match is StorageAccounts_List
let operations = validator.cache['microsoft.test']['2016-01-01']['post'];
for (const operation of operations) {
assert(operation.responses.default);
assert.deepEqual(operation.responses.default.schema.properties.error, utils.CloudError);
}
done();
}).catch((err) => {
assert.ifError(err);
done();
}).catch(done);
});
});
describe('Initialize cache and validate', function () {