Fixes for paths and non string enums (#238)

* Add path test

* Fix tests

* Update changelog
This commit is contained in:
Mariana Cardoso 2018-04-23 19:09:13 -07:00 коммит произвёл Vlad Barosan
Родитель 59f0409dcd
Коммит 3b66388e6e
6 изменённых файлов: 104 добавлений и 44 удалений

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

@ -1,3 +1,9 @@
### 04/23/2018 0.4.37
- Update dependencies.
- Bug fixes:
- Path parameters can include single quotes and be evaluated succesfully.
- Enums with non-string values are properly evaluated.
### 04/19/2018 0.4.36
- If enums mismatch only in casing the new error ENUM_CASE_MISMATCH will be returned.

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.4.36",
"version": "0.4.37",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -3073,7 +3073,7 @@
}
},
"sway": {
"version": "github:amarzavery/sway#02ede38a836bb39b76313ca779e59c6a5144d312",
"version": "github:amarzavery/sway#32784bab1cba7178bd4bf283cb4c6fdfafd15627",
"requires": {
"debug": "3.1.0",
"faker": "4.1.0",
@ -3432,4 +3432,4 @@
}
}
}
}
}

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.4.36",
"version": "0.4.37",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
@ -55,4 +55,4 @@
"test": "npm -s run-script jshint && mocha -t 100000 --reporter min",
"start": "node ./lib/autorestPlugin/pluginHost.js"
}
}
}

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

@ -0,0 +1,8 @@
{
"parameters": {
"quotes": "coolparameter"
},
"responses": {
"200": {}
}
}

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

@ -18,6 +18,31 @@
"text/json"
],
"paths": {
"/param('{quotes}')": {
"put": {
"operationId": "Path_WithQuotes",
"description": "The path has a parameter between quotes",
"x-ms-examples": {
"PathWithQuotes": {
"$ref": "./examples/pathwithquotes.json"
}
},
"parameters": [
{
"name": "quotes",
"in": "path",
"required": true,
"type": "string",
"description": "Parameter meant to be between quotes"
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/subscriptions/{scope}/providers/Microsoft.Test/checkNameAvailability": {
"post": {
"tags": [
@ -26,7 +51,9 @@
"operationId": "StorageAccounts_CheckNameAvailability",
"description": "Checks that the storage account name is valid and is not already in use.",
"x-ms-examples": {
"storageAccountCheckNameAvailability": {"$ref": "./examples/storageAccountCheckNameAvailability.json"}
"storageAccountCheckNameAvailability": {
"$ref": "./examples/storageAccountCheckNameAvailability.json"
}
},
"parameters": [
{
@ -67,7 +94,9 @@
"operationId": "StorageAccounts_pathParameterWithForwardSlashes",
"description": "Checks that the storage account name is valid and is not already in use.",
"x-ms-examples": {
"storageAccountPathParameterForwardSlash": {"$ref": "./examples/storageAccountPathParameterForwardSlash.json"}
"storageAccountPathParameterForwardSlash": {
"$ref": "./examples/storageAccountPathParameterForwardSlash.json"
}
},
"parameters": [
{
@ -108,7 +137,9 @@
"operationId": "StorageAccounts_duplicateforwardslashes",
"description": "Checks that the storage account name is valid and is not already in use.",
"x-ms-examples": {
"storageAccountduplicateforwardslashes": {"$ref": "./examples/storageAccountduplicateforwardslashes.json"}
"storageAccountduplicateforwardslashes": {
"$ref": "./examples/storageAccountduplicateforwardslashes.json"
}
},
"parameters": [
{
@ -151,7 +182,9 @@
"operationId": "StorageAccounts_pathParameterWithQuestionMark",
"description": "Checks that the storage account name is valid and is not already in use.",
"x-ms-examples": {
"storageAccountXmsPaths": {"$ref": "./examples/storageAccountXmsPaths.json"}
"storageAccountXmsPaths": {
"$ref": "./examples/storageAccountXmsPaths.json"
}
},
"parameters": [
{

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

@ -6,42 +6,55 @@ const validate = require('../lib/validate');
const specPath = `${__dirname}/modelValidation/swaggers/specification/scenarios/resource-manager/Microsoft.Test/2016-01-01/test.json`;
describe('Model Validation', function () {
it('should pass when path parameter has forward slashes', function (done) {
let operationIds = "StorageAccounts_pathParameterWithForwardSlashes";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`);
console.log(result);
done();
}).catch((err) => {
done(err);
});
});
it('should pass for paths in x-ms-paths with question mark', function (done) {
let operationIds = "StorageAccounts_pathParameterWithQuestionMark";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`);
console.log(result);
done();
}).catch((err) => {
done(err);
});
});
it('should fail for paths with path parameter value resulting in duplicate forward slashes', function (done) {
let operationIds = "StorageAccounts_duplicateforwardslashes";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === false, `swagger "${specPath}" with operation "${operationIds}" contains passed incorrectly.`);
console.log(result);
done();
}).catch((err) => {
try {
assert.equal(err.code, 'REQUEST_VALIDATION_ERROR');
assert.equal(err.innerErrors[0].code, 'DOUBLE_FORWARD_SLASHES_IN_URL');
describe('Path validation - ', function () {
it('should pass when path parameter has forward slashes', function (done) {
let operationIds = "StorageAccounts_pathParameterWithForwardSlashes";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`);
console.log(result);
done();
} catch (er) {
done(er);
}
}).catch((err) => {
done(err);
});
});
it('should pass for paths in x-ms-paths with question mark', function (done) {
let operationIds = "StorageAccounts_pathParameterWithQuestionMark";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`);
console.log(result);
done();
}).catch((err) => {
done(err);
});
});
it('should pass for paths with quotes', function (done) {
let operationIds = "Path_WithQuotes";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`);
console.log(result);
done();
}).catch((err) => {
done(err);
});
});
it('should fail for paths with path parameter value resulting in duplicate forward slashes', function (done) {
let operationIds = "StorageAccounts_duplicateforwardslashes";
validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => {
assert(result.validityStatus === false, `swagger "${specPath}" with operation "${operationIds}" contains passed incorrectly.`);
console.log(result);
done();
}).catch((err) => {
try {
assert.equal(err.code, 'REQUEST_VALIDATION_ERROR');
assert.equal(err.innerErrors[0].code, 'DOUBLE_FORWARD_SLASHES_IN_URL');
done();
} catch (er) {
done(er);
}
});
});
});