Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve casing errors #202

Merged
merged 4 commits into from
Jan 31, 2018
Merged
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
53 changes: 26 additions & 27 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
{
"esversion": 6,
"bitwise": true,
"camelcase": true,
"curly": false,
"eqeqeq": false,
"forin": true,
"immed": true,
"indent": 2,
"latedef": true,
"maxparams": false,
"maxdepth": false,
"maxstatements": false,
"maxcomplexity": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": true,
"sub": true,
"strict": false,
"trailing": true,
"undef": true,
"unused": false,
"shadow": true
"esversion": 6,
"bitwise": true,
"camelcase": true,
"curly": false,
"eqeqeq": false,
"forin": true,
"immed": true,
"indent": 2,
"latedef": false,
"maxparams": false,
"maxdepth": false,
"maxstatements": false,
"maxcomplexity": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": true,
"nonew": true,
"plusplus": false,
"regexp": true,
"sub": true,
"strict": false,
"trailing": true,
"undef": true,
"unused": false,
"shadow": true
}
10 changes: 7 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 01/31/2018 0.4.26
- Fix all linter issues. [#201](https://github.com/Azure/oav/issues/201)
- Add option to do case insensitive regex matches on swagger paths to the SpecValidator and LiveValidator. [#203](https://github.com/Azure/oav/issues/203)

### 01/30/2018 0.4.25
- Fixed a typo in the variable name while resolving nullable types.

Expand Down Expand Up @@ -52,13 +56,13 @@
### 08/03/2017 0.4.9
- [Live Validator] Shallow clone the azure-rest-api-spec repo.
- [Model Validator] Improve pluggability of oav into vs-code. #143

### 08/03/2017 0.4.8
- [Live Validator] Before cloning the rest api specs repo if directory named 'repo' exists we delete it and then create an empty directory to clone repo inside it.

### 07/11/2017 0.4.7
- Fixed Live validator for reorg branch of azure-rest-api-specs #137

### 07/03/2017 0.4.6
- Fixed issue #134

Expand Down
57 changes: 32 additions & 25 deletions lib/autorestPlugin/pluginHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const vscode_jsonrpc_1 = require("vscode-jsonrpc");
const vscodeJsonRpc = require("vscode-jsonrpc");
const linq = require('linq');
const jsonPath = require('jsonpath');
const yaml = require("js-yaml");
Expand All @@ -18,7 +18,7 @@ exports = module.exports;

const extension = new extensionBase.AutoRestExtension();
const modelValidatorPluginName = "model-validator";
const modelValidationCategory = "ExampleModelViolation"
const modelValidationCategory = "ExampleModelViolation";

function FormattedOutput(channel, details, code, text, source) {
this.channel = channel;
Expand All @@ -28,24 +28,31 @@ function FormattedOutput(channel, details, code, text, source) {
this.source = source;
}

/**
* Returns a promise with the examples validation of the swagger.
*/
function analyzeSwagger(swaggerFileName, autoRestApi) {
autoRestApi.ReadFile(swaggerFileName).then((swaggerFile) => {
const swagger = yaml.safeLoad(swaggerFile);
return exports.openApiValidationExample(swagger, swaggerFileName).then(function (exampleValidationResults) {
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));
});
});
}

extension.Add(modelValidatorPluginName, autoRestApi => {
return autoRestApi.ListInputs().then(function (swaggerFileNames) {
return autoRestApi.ListInputs().then((swaggerFileNames) => {
const promises = [];
for (const swaggerFileName of swaggerFileNames) {
promises.push(
autoRestApi.ReadFile(swaggerFileName).then(function (swaggerFile) {
const swagger = yaml.safeLoad(swaggerFile);
return exports.openApiValidationExample(swagger, swaggerFileName).then(function (exampleValidationResults) {
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));
})
})
analyzeSwagger(swaggerFileName)
);
}
return Promise.all(promises).then(_ => true)
})
return Promise.all(promises).then(_ => true);
});
});

exports.openApiValidationExample = function openApiValidationExample(swagger, swaggerFileName, options) {
Expand All @@ -57,10 +64,10 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
//console.error(JSON.stringify(swagger, null, 2));
return specVal.initialize().then(function () {
specVal.validateOperations();
Promise.resolve(specVal.specValidationResult).then(function (specValidationResult) {
for (var op in specValidationResult.operations) {
Promise.resolve(specVal.specValidationResult).then((specValidationResult) => {
for (let op of utils.getKeys(specValidationResult.operations)) {
const xmsExamplesNode = specValidationResult.operations[op]["x-ms-examples"];
for (var scenario in xmsExamplesNode.scenarios) {
for (let scenario of utils.getKeys(xmsExamplesNode.scenarios)) {
// invalid? meaning that there's an issue found in the validation
var scenarioItem = xmsExamplesNode.scenarios[scenario];
if (scenarioItem.isValid === false) {
Expand All @@ -72,7 +79,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, [modelValidationCategory], "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
Expand All @@ -84,9 +91,9 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
throw new Error("Model Validator: Unexpected format.");
}
for (const innerError of innerErrors) {
const path = ConvertIndicesFromStringToNumbers(innerError.path);
const path = convertIndicesFromStringToNumbers(innerError.path);
//console.error(JSON.stringify(error, null, 2));
resultDetails = { type: "Error", code: error.code, message: error.message, id: error.id, validationCategory: modelValidationCategory, innerErrors: innerError };
let 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 } }]);
Expand All @@ -95,7 +102,7 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
}

// responses
for (var responseCode in scenarioItem.responses) {
for (let responseCode of utils.getKeys(scenarioItem.responses)) {
const response = scenarioItem.responses[responseCode];
if (response.isValid === false) {
const error = response.error;
Expand All @@ -105,19 +112,19 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
}
for (const innerError of innerErrors) {
//console.error(JSON.stringify(error, null, 2));
resultDetails = { type: "Error", code: error.code, message: error.message, id: error.id, validationCategory: modelValidationCategory, innerErrors: innerError };
let 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]) } }
])
]);
formattedResult.push(result);
}
}
}
}
}
}
})
});
return formattedResult;
}).catch(function (err) {
console.error(err);
Expand All @@ -127,7 +134,7 @@ exports.openApiValidationExample = function openApiValidationExample(swagger, sw
/**
* Path comes with indices as strings in "inner errors", so converting those to actual numbers for path to work.
*/
function ConvertIndicesFromStringToNumbers(path) {
function convertIndicesFromStringToNumbers(path) {
const result = path.slice();
for (let i = 1; i < result.length; ++i) {
const num = parseInt(result[i]);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/extract-xmsexamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ exports.handler = function (argv) {
vOptions.matchApiVersion = argv.matchApiVersion;

return validate.extractXMsExamples(specPath, recordings, vOptions);
}
};

exports = module.exports;
2 changes: 1 addition & 1 deletion lib/commands/generate-wireformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ exports.handler = function (argv) {
}
}
return execWireFormat().catch((err) => { process.exitCode = 1; });
}
};

exports = module.exports;
8 changes: 4 additions & 4 deletions lib/commands/validate-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ exports.describe = 'Performs validation of x-ms-examples and examples present in
exports.builder = {
o: {
alias: 'operationIds',
describe: 'A comma separated string of operationIds for which the examples ' +
'need to be validated. If operationIds are not provided then the entire spec will be validated. ' +
'Example: "StorageAccounts_Create, StorageAccounts_List, Usages_List".',
describe: 'A comma separated string of operationIds for which the examples ' +
'need to be validated. If operationIds are not provided then the entire spec will be validated. ' +
'Example: "StorageAccounts_Create, StorageAccounts_List, Usages_List".',
string: true
}
};
Expand All @@ -32,6 +32,6 @@ exports.handler = function (argv) {
} else {
return validate.validateExamples(specPath, operationIds, vOptions);
}
}
};

exports = module.exports;
5 changes: 3 additions & 2 deletions lib/templates/httpTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

'use strict';
const url = require('url'),
uuid = require('uuid');
uuid = require('uuid'),
utils = require('../util/utils');

class HttpTemplate {

Expand All @@ -27,7 +28,7 @@ class HttpTemplate {
result += `\n${padding}-H 'Content-Length: ${JSON.stringify(this.request.body).length}' \\`;
}
if (this.request.headers) {
let headers = Object.keys(this.request.headers);
let headers = utils.getKeys(this.request.headers);

for (let i = 0; i < headers.length; i++) {
let headerName = headers[i];
Expand Down
11 changes: 6 additions & 5 deletions lib/templates/markdownHttpTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
'use strict';
const url = require('url'),
HttpTemplate = require('./httpTemplate'),
uuid = require('uuid');
uuid = require('uuid'),
utils = require('../util/utils');

class MarkdownHttpTemplate extends HttpTemplate {

Expand All @@ -18,7 +19,7 @@ class MarkdownHttpTemplate extends HttpTemplate {
result += `Content-Length: ${JSON.stringify(this.request.body).length}\n`;
}
if (this.request.headers) {
let headers = Object.keys(this.request.headers);
let headers = utils.getKeys(this.request.headers);

for (let i = 0; i < headers.length; i++) {
let headerName = headers[i];
Expand All @@ -38,7 +39,7 @@ class MarkdownHttpTemplate extends HttpTemplate {
}
let gotContentType = false;
if (response.headers) {
let headers = Object.keys(response.headers);
let headers = utils.getKeys(response.headers);
for (let i = 0; i < headers.length; i++) {
let headerName = headers[i];
if (headerName.match(/^Content-Type$/ig) !== null) gotContentType = true;
Expand All @@ -49,7 +50,7 @@ class MarkdownHttpTemplate extends HttpTemplate {
}
}
if (!gotContentType) {
result += `Content-Type: application/json; charset=utf-8`
result += `Content-Type: application/json; charset=utf-8`;
}
return result;
}
Expand Down Expand Up @@ -121,7 +122,7 @@ curl -X ${this.request.method} '${this.request.url}' \\\n-H 'authorization: bear
template += this.populateResponse(this.responses.longrunning.initialResponse, 'Initial Response');
}
if (this.responses.longrunning.finalResponse) {
template += this.populateResponse(this.responses.longrunning.finalResponse, 'Final Response after polling is complete and successful')
template += this.populateResponse(this.responses.longrunning.finalResponse, 'Final Response after polling is complete and successful');
}
} else {
template += this.populateResponse(this.responses.standard.finalResponse, 'Response');
Expand Down
11 changes: 6 additions & 5 deletions lib/templates/yamlHttpTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

'use strict';
const url = require('url'),
utils = require('../util/utils'),
HttpTemplate = require('./httpTemplate'),
uuid = require('uuid');

class YamlHttpTemplate extends HttpTemplate {

constructor(request, responses) {
super(request, responses)
super(request, responses);
}

getRequestHeaders() {
Expand All @@ -18,7 +19,7 @@ class YamlHttpTemplate extends HttpTemplate {
result += ` Content-Length: ${JSON.stringify(this.request.body).length}\n`;
}
if (this.request.headers) {
let headers = Object.keys(this.request.headers);
let headers = utils.getKeys(this.request.headers);

for (let i = 0; i < headers.length; i++) {
let headerName = headers[i];
Expand All @@ -38,7 +39,7 @@ class YamlHttpTemplate extends HttpTemplate {
}
let gotContentType = false;
if (response.headers) {
let headers = Object.keys(response.headers);
let headers = utils.getKeys(response.headers);
for (let i = 0; i < headers.length; i++) {
let headerName = headers[i];
if (headerName.match(/^Content-Type$/ig) !== null) gotContentType = true;
Expand All @@ -49,7 +50,7 @@ class YamlHttpTemplate extends HttpTemplate {
}
}
if (!gotContentType) {
result += ` Content-Type: application/json; charset=utf-8`
result += ` Content-Type: application/json; charset=utf-8`;
}
return result;
}
Expand Down Expand Up @@ -115,7 +116,7 @@ curl: |
template += this.populateResponse(this.responses.longrunning.initialResponse, 'Initial Response');
}
if (this.responses.longrunning.finalResponse) {
template += this.populateResponse(this.responses.longrunning.finalResponse, 'Final Response after polling is complete and successful')
template += this.populateResponse(this.responses.longrunning.finalResponse, 'Final Response after polling is complete and successful');
}
} else {
template += this.populateResponse(this.responses.standard.finalResponse, 'Response');
Expand Down
Loading