Update the check for MultipleOperationsFound (#473)

* Update the check for MultipleOperationsFound

* Update the package version

* address comments in the review
This commit is contained in:
Renhe Li 2020-01-06 15:20:21 +08:00 коммит произвёл GitHub
Родитель 5fa8be45ad
Коммит 178de9bfeb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 1428 добавлений и 39 удалений

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

@ -765,12 +765,24 @@ export class LiveValidator {
throw potentialOperationsResult.reason
// Found more than 1 potentialOperations
} else if (potentialOperationsResult.operations.length > 1) {
const operationIds = potentialOperationsResult.operations
.map(operation => operation.operationId)
.join()
const operationInfos: Array<{ id: number; path: string; specPath: string }> = []
potentialOperationsResult.operations.forEach(operation => {
const swaggerSpecPath =
this.options.useRelativeSourceLocationUrl && operation.pathObject.specPath
? operation.pathObject.specPath.substr(this.options.directory.length)
: operation.pathObject.specPath
operationInfos.push({
id: operation.operationId,
path: operation.pathObject.path,
specPath: swaggerSpecPath
})
})
const msg =
`Found multiple matching operations with operationIds "${operationIds}" ` +
`for request url "${requestInfo.requestUrl}" with HTTP Method "${requestInfo.requestMethod}".`
`Found multiple matching operations ` +
`for request url "${requestInfo.requestUrl}" with HTTP Method "${requestInfo.requestMethod}".` +
`Operation Information: ${JSON.stringify(operationInfos)}`
this.logging(
msg,
LiveValidatorLoggingLevels.debug,

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

@ -209,7 +209,8 @@ export class SpecValidator<T extends CommonValidationResult> {
jsonRefs: {
relativeBase: this.specDir
},
isPathCaseSensitive: this.options.isPathCaseSensitive
isPathCaseSensitive: this.options.isPathCaseSensitive,
specPath: this.specPath
}
this.swaggerApi = await Sway.create(options)
} catch (err) {

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.20.4",
"version": "0.20.5-beta",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -702,20 +702,14 @@
}
},
"@types/jest": {
"version": "24.0.18",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.18.tgz",
"integrity": "sha512-jcDDXdjTcrQzdN06+TSVsPPqxvsZA/5QkYfIZlq1JMw7FdP5AZylbOc+6B/cuDurctRe+MziUMtQ3xQdrbjqyQ==",
"version": "24.0.25",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.25.tgz",
"integrity": "sha512-hnP1WpjN4KbGEK4dLayul6lgtys6FPz0UfxMeMQCv0M+sTnzN3ConfiO72jHgLxl119guHgI8gLqDOrRLsyp2g==",
"dev": true,
"requires": {
"@types/jest-diff": "*"
"jest-diff": "^24.3.0"
}
},
"@types/jest-diff": {
"version": "20.0.1",
"resolved": "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz",
"integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==",
"dev": true
},
"@types/js-yaml": {
"version": "3.12.1",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.1.tgz",
@ -734,9 +728,9 @@
"integrity": "sha512-v7qlPA0VpKUlEdhghbDqRoKMxFB3h3Ch688TApBJ6v+XLDdvWCGLJIYiPKGZnS6MAOie+IorCfNYVHOPIHSWwQ=="
},
"@types/lodash": {
"version": "4.14.123",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.123.tgz",
"integrity": "sha512-pQvPkc4Nltyx7G1Ww45OjVqUsJP4UsZm+GWJpigXgkikZqJgRm4c48g027o6tdgubWHwFRF15iFd+Y4Pmqv6+Q==",
"version": "4.14.149",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz",
"integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==",
"dev": true
},
"@types/md5-file": {
@ -2792,9 +2786,9 @@
"dev": true
},
"handlebars": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz",
"integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==",
"version": "4.5.3",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.3.tgz",
"integrity": "sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==",
"requires": {
"neo-async": "^2.6.0",
"optimist": "^0.6.1",
@ -6276,19 +6270,19 @@
"dev": true
},
"uglify-js": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
"version": "3.7.3",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.7.3.tgz",
"integrity": "sha512-7tINm46/3puUA4hCkKYo4Xdts+JDaVC9ZPRcG8Xw9R4nhO/gZgUM3TENq8IF4Vatk8qCig4MzP/c8G4u2BkVQg==",
"optional": true,
"requires": {
"commander": "~2.20.0",
"commander": "~2.20.3",
"source-map": "~0.6.1"
},
"dependencies": {
"commander": {
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"optional": true
},
"source-map": {
@ -6601,9 +6595,9 @@
}
},
"yasway": {
"version": "1.8.9",
"resolved": "https://registry.npmjs.org/yasway/-/yasway-1.8.9.tgz",
"integrity": "sha512-2bCZEy89yzrVaN8cizoy+lwTJ0kHbuCgk7w99q66MR6TGS9gHuUlPas6E2RCJ1uujS/m9GvmkYYjv1LF4Cg3nQ==",
"version": "1.8.11",
"resolved": "https://registry.npmjs.org/yasway/-/yasway-1.8.11.tgz",
"integrity": "sha512-LhMkY455qHEV7rKMjfvwgXkoB26JJkuK4hqQnbjNXjpuT/lfEpbYJiPMjFOvZTf2VmJqCoM7sej6P+7LJyxM1Q==",
"requires": {
"@ts-common/json": "^0.3.0",
"@ts-common/string-map": "^0.3.0",

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.20.4",
"version": "0.20.5-beta",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
@ -28,7 +28,7 @@
"json-refs": "^3.0.13",
"jsonpath": "^1.0.1",
"linq": "^3.2.0",
"lodash": "^4.17.11",
"lodash": "^4.17.15",
"md5-file": "^4.0.0",
"moment": "^2.24.0",
"ms-rest": "^2.5.0",
@ -37,24 +37,24 @@
"vscode-jsonrpc": "^3.6.2",
"winston": "^3.2.1",
"yargs": "^6.6.0",
"yasway": "^1.8.9",
"yasway": "^1.8.11",
"yuml2svg": "^4.2.1",
"z-schema": "^4.2.2"
},
"devDependencies": {
"@types/commonmark": "^0.27.3",
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.11",
"@types/jest": "^24.0.25",
"@types/js-yaml": "^3.12.1",
"@types/json-pointer": "^1.0.30",
"@types/lodash": "4.14.123",
"@types/lodash": "4.14.149",
"@types/md5-file": "^4.0.0",
"@types/node": "^10.12.18",
"@types/request": "^2.48.1",
"@types/swagger-parser": "^4.0.3",
"@types/uuid": "^3.4.4",
"@types/yargs": "^11.1.2",
"jest": "^24.7.1",
"jest": "^24.9.0",
"jest-junit": "^6.3.0",
"prettier": "^1.18.2",
"should": "^13.2.3",

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

@ -0,0 +1,27 @@
{
"liveRequest": {
"headers": {
"strict-Transport-Security": "max-age=31536000; includeSubDomains",
"x-ms-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"x-ms-correlation-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"date": "Tue, 11 Sep 2018 18:45:41 GMT",
"eTag": "\"AAAAAAAAjAIAAAAAAACL/A==\"",
"server": "Microsoft-HTTPAPI/2.0",
"Content-Type": "application/json"
},
"method": "GET",
"url": "/subscriptions/bd41953c-0447-4c09-8a5e-9e1717f952a2/resourceGroups/Stream-REFE1-ScaleUnit1/providers/Microsoft.Media/mediaServices/streamrefe1su011/assets/65a63811-7bd5-4867-9f75-77fb3f40a700?api-version=2018-07-01",
"query": { "api-version": "2018-07-01" }
},
"liveResponse": {
"statusCode": "400",
"headers": {
"x-ms-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"x-ms-correlation-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"date": "Tue, 11 Sep 2018 18:45:41 GMT",
"eTag": "\"AAAAAAAAjAIAAAAAAACL/A==\"",
"server": "Microsoft-HTTPAPI/2.0",
"Content-Type": "application/json"
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,80 @@
{
"swagger": "2.0",
"info": {
"title": "Azure Media Services",
"version": "2018-07-01"
},
"securityDefinitions": {
"azure_auth": {
"type": "oauth2",
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
"flow": "implicit",
"description": "Azure Active Directory OAuth2 Flow",
"scopes": {
"user_impersonation": "Impersonate your user account"
}
}
},
"paths": {},
"definitions": {
"Resource": {
"description": "The core properties of ARM resources.",
"properties": {
"id": {
"readOnly": true,
"type": "string",
"description": "Fully qualified resource ID for the resource."
},
"name": {
"readOnly": true,
"type": "string",
"description": "The name of the resource."
},
"type": {
"readOnly": true,
"type": "string",
"description": "The type of the resource."
}
},
"x-ms-azure-resource": true
},
"TrackedResource": {
"description": "The resource model definition for a ARM tracked resource.",
"properties": {
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"x-ms-mutability": [
"read",
"create",
"update"
],
"description": "Resource tags."
},
"location": {
"type": "string",
"x-ms-mutability": [
"read",
"create"
],
"description": "The Azure Region of the resource."
}
},
"allOf": [
{
"$ref": "#/definitions/Resource"
}
]
},
"ProxyResource": {
"description": "The resource model definition for a ARM proxy resource.",
"allOf": [
{
"$ref": "#/definitions/Resource"
}
]
}
}
}

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

@ -673,6 +673,41 @@ describe("Live validator snapshot validation", () => {
expect(validationResult).toMatchSnapshot()
})
test(`should return expected error for multiple operation found`, async () => {
const options = {
directory: `${__dirname}/liveValidation/swaggers/`,
isPathCaseSensitive: false,
useRelativeSourceLocationUrl: true,
swaggerPathsPattern: [
"specification\\mediaservices\\resource-manager\\Microsoft.Media\\**\\*.json"
],
git: {
shouldClone: false
}
}
const liveValidator = new LiveValidator(options)
await liveValidator.initialize()
const payload = require(`${__dirname}/liveValidation/payloads/multiplePperationFound_input`)
const result = liveValidator.validateLiveRequestResponse(payload)
expect(
result.responseValidationResult.runtimeException &&
result.responseValidationResult.runtimeException.code === "MULTIPLE_OPERATIONS_FOUND"
)
expect(
result.responseValidationResult.runtimeException &&
result.responseValidationResult.runtimeException.message.indexOf(
"specification/mediaservices/resource-manager/Microsoft.Media/2018-07-01/AssetsAndAssetFilters.json"
) >= 0
)
expect(
result.responseValidationResult.runtimeException &&
result.responseValidationResult.runtimeException.message.indexOf(
"specification/mediaservices/resource-manager/Microsoft.Media/2019-05-01-preview/AssetsAndAssetFilters.json"
) >= 0
)
})
test(`should return expected error for unresolvable reference`, async () => {
const options = {
directory: `${__dirname}/liveValidation/swaggers/`,