updating model validator plugin to autorest

This commit is contained in:
Veronica Giaudrone 2017-10-02 14:10:39 -07:00
Родитель b3ee14feed
Коммит 1a94f6a365
3 изменённых файлов: 26 добавлений и 8 удалений

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

@ -82,5 +82,17 @@ Options:
bash-3.2$
```
### Autorest plugin configuration
- Please don't edit this section unless you're re-configuring how oav plugs in to AutoRest
AutoRest needs the below config to pick this up as a plug-in - see https://github.com/Azure/autorest/blob/master/docs/developer/architecture/AutoRest-extension.md
``` yaml $(model-validator)
pipeline:
swagger-document/model-validator:
input: swagger-document/identity
scope: azure-validator-composed
```
---
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

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

@ -8,7 +8,6 @@ const linq = require('linq');
const jsonPath = require('jsonpath');
const yaml = require("js-yaml");
const utils = require("../util/utils");
const validator = require("../validate");
const log = require('../util/logging');
const SpecValidator = require('../validators/specValidator');
const extensionBase = require('autorest-extension-base');
@ -19,6 +18,7 @@ exports = module.exports;
const extension = new extensionBase.AutoRestExtension();
const modelValidatorPluginName = "model-validator";
const modelValidationCategory = "ExampleModelViolation"
function FormattedOutput(channel, details, code, text, source) {
this.channel = channel;
@ -39,7 +39,7 @@ extension.Add(modelValidatorPluginName, autoRestApi => {
for (const result of exampleValidationResults) {
autoRestApi.Message({ Channel: result.channel, Text: result.text, Details: result.details, Key: result.code, Source: result.source });
}
console.error(JSON.stringify(exampleValidationResults, null, 2));
// console.error(JSON.stringify(exampleValidationResults, null, 2));
})
})
);
@ -48,9 +48,12 @@ extension.Add(modelValidatorPluginName, autoRestApi => {
})
});
exports.openApiValidationExample = function openApiValidationExample(swagger, swaggerFileName) {
exports.openApiValidationExample = function openApiValidationExample(swagger, swaggerFileName, options) {
var formattedResult = [];
let specVal = new SpecValidator("swagger.json", swagger, { "consoleLogLevel": "off" });
if (!options) options = {};
options.consoleLogLevel = "off";
log.consoleLogLevel = options.consoleLogLevel;
let specVal = new SpecValidator(swaggerFileName, swagger, options);
//console.error(JSON.stringify(swagger, null, 2));
return specVal.initialize().then(function () {
specVal.validateOperations();
@ -69,7 +72,7 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
throw new Error("Model Validator: Path to x-ms-examples not found.");
}
//console.error(JSON.stringify(scenarioItem, null, 2));
var result = new FormattedOutput("verbose", scenarioItem, scenario, ["ExampleModelViolation"], "Model validator found issue (see details).", [{ document: swaggerFileName, Position: { path: xmsexPath } }])
var result = new FormattedOutput("verbose", scenarioItem, scenario, [modelValidationCategory], "Model validator found issue (see details).", [{ document: swaggerFileName, Position: { path: xmsexPath } }])
formattedResult.push(result);
// request
@ -83,7 +86,8 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
for (const innerError of innerErrors) {
const path = ConvertIndicesFromStringToNumbers(innerError.path);
//console.error(JSON.stringify(error, null, 2));
result = new FormattedOutput("error", error, [error.code, error.id, "ExampleModelViolation"],
resultDetails = { type: "Error", code: error.code, message: error.message, id: error.id, validationCategory: modelValidationCategory, innerErrors: innerError };
result = new FormattedOutput("error", resultDetails, [error.code, error.id, modelValidationCategory],
innerError.message + ". \nScenario: " + scenario + ". \nDetails: " + JSON.stringify(innerError.errors, null, 2) + "\nMore info: " + openAPIDocUrl + "#" + error.id.toLowerCase() + "-" + error.code.toLowerCase() + "\n",
[{ document: swaggerFileName, Position: { path: path } }]);
formattedResult.push(result);
@ -101,7 +105,8 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
}
for (const innerError of innerErrors) {
//console.error(JSON.stringify(error, null, 2));
result = new FormattedOutput("error", error, [error.code, error.id, "ExampleModelViolation"],
resultDetails = { type: "Error", code: error.code, message: error.message, id: error.id, validationCategory: modelValidationCategory, innerErrors: innerError };
result = new FormattedOutput("error", resultDetails, [error.code, error.id, modelValidationCategory],
innerError.message + ". \nScenario: " + scenario + ". \nDetails: " + JSON.stringify(innerError.errors, null, 2) + "\nMore info: " + openAPIDocUrl + "#" + error.id.toLowerCase() + "-" + error.code.toLowerCase() + "\n",
[{ document: swaggerFileName, Position: { path: xmsexPath.slice(0, xmsexPath.length - 1).concat(["responses", responseCode]) } }
])

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

@ -51,6 +51,7 @@
},
"scripts": {
"jshint": "jshint index.js --reporter=jslint",
"test": "npm -s run-script jshint && mocha -t 50000"
"test": "npm -s run-script jshint && mocha -t 50000",
"start": "node ./lib/autorestPlugin/pluginHost.js"
}
}