Skip to content

Commit

Permalink
Fixes for paths and non string enums (#238)
Browse files Browse the repository at this point in the history
* Add path test

* Fix tests

* Update changelog
  • Loading branch information
mcardosos authored and Vlad Barosan committed Apr 24, 2018
1 parent 59f0409 commit 3b66388
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 40 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.4.36",
"version": "0.4.37",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
Expand Down Expand Up @@ -55,4 +55,4 @@
"test": "npm -s run-script jshint && mocha -t 100000 --reporter min",
"start": "node ./lib/autorestPlugin/pluginHost.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parameters": {
"quotes": "coolparameter"
},
"responses": {
"200": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand Down
75 changes: 44 additions & 31 deletions test/modelValidatorTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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((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 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');
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 (er) {
done(er);
}
}).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);
}
});
});
});

Expand Down

0 comments on commit 3b66388

Please sign in to comment.