Task #1032251 live validator swaggerPathPattern (#466)

* Task #1032251 live validator swaggerPathPattern

Change the swaggerPathPattern to array type from string.
This commit is contained in:
Ray Chen 2019-12-05 17:43:14 +08:00 коммит произвёл GitHub
Родитель 5fd37b3e0a
Коммит 09f76726d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 77 добавлений и 40 удалений

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

@ -1,5 +1,8 @@
# Changelog
## 12/05/2019 0.20.3
- Change the swaggerPathsPattern of LiveValidatorOptions to array type
## 11/26/2019 0.20.2
- Upgrade yasway version to consume the change for x-ms-secret property update

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

@ -36,7 +36,7 @@ export interface LiveValidatorOptions {
}
useRelativeSourceLocationUrl?: boolean
directory: string
swaggerPathsPattern: string
swaggerPathsPattern: string[]
isPathCaseSensitive: boolean
}
@ -781,35 +781,48 @@ export class LiveValidator {
return op as OperationWithApiVersion
}
private async getMatchedPaths(jsonsPattern: string | string[]): Promise<string[]> {
const matchedPaths = await globby(jsonsPattern, {
ignore: [
"**/examples/**/*",
"**/quickstart-templates/**/*",
"**/schema/**/*",
"**/live/**/*",
"**/wire-format/**/*"
],
onlyFiles: true,
unique: true
})
this.logging(
`Using swaggers found from directory: "${
this.options.directory
}" and pattern: "${jsonsPattern.toString()}".
Total paths count: ${matchedPaths.length}`,
LiveValidatorLoggingLevels.debug
)
return matchedPaths
}
private async getSwaggerPaths(): Promise<string[]> {
if (this.options.swaggerPaths.length !== 0) {
this.logging(
`Using user provided swagger paths. Total paths: ${this.options.swaggerPaths.length}`
`Using user provided swagger paths. Total paths count: ${this.options.swaggerPaths.length}`
)
return this.options.swaggerPaths
} else {
const allJsonsPattern = "/specification/**/*.json"
const jsonsPattern = path.join(
this.options.directory,
this.options.swaggerPathsPattern || allJsonsPattern
)
const swaggerPaths = await globby(jsonsPattern, {
ignore: [
"**/examples/**/*",
"**/quickstart-templates/**/*",
"**/schema/**/*",
"**/live/**/*",
"**/wire-format/**/*"
],
onlyFiles: true,
unique: true
})
this.logging(
`Using swaggers found from directory: "${this.options.directory}" and pattern: "${jsonsPattern}".
Total paths: ${swaggerPaths.length}`,
LiveValidatorLoggingLevels.debug
)
return swaggerPaths
const allJsonsPattern = path.join(this.options.directory, "/specification/**/*.json")
const swaggerPathPatterns: string[] = []
if (
this.options.swaggerPathsPattern === undefined ||
this.options.swaggerPathsPattern.length === 0
) {
return this.getMatchedPaths(allJsonsPattern)
} else {
this.options.swaggerPathsPattern.map(item => {
swaggerPathPatterns.push(path.join(this.options.directory, item))
})
return this.getMatchedPaths(swaggerPathPatterns)
}
}
}

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.20.2",
"version": "0.20.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

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

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "0.20.2",
"version": "0.20.3",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",

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

@ -135,6 +135,20 @@ describe("Live Validator", () => {
assert.deepStrictEqual(validator.cache, {})
assert.deepStrictEqual(validator.options, options)
})
it("should initialize with multiple path patterns", async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification",
swaggerPathsPattern: [
"mediaservices/resource-manager/Microsoft.Media/2015-10-01/media.json",
"rpsaas/resource-manager/Microsoft.Contoso/**/*.json"
]
}
const validator = new LiveValidator(options)
await validator.initialize()
assert.strictEqual(2, Object.keys(validator.cache).length)
assert.strictEqual(true, "microsoft.media" in validator.cache)
assert.strictEqual(true, "microsoft.contoso" in validator.cache)
})
})
describe("Initialize cache", () => {
@ -143,7 +157,9 @@ describe("Live Validator", () => {
const expectedApiVersion = "2015-10-01"
const options = {
directory: "./test/liveValidation/swaggers/specification",
swaggerPathsPattern: "mediaservices/resource-manager/Microsoft.Media/2015-10-01/media.json"
swaggerPathsPattern: [
"mediaservices/resource-manager/Microsoft.Media/2015-10-01/media.json"
]
}
const validator = new LiveValidator(options)
try {
@ -202,8 +218,9 @@ describe("Live Validator", () => {
it("should initialize for batch", async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification",
swaggerPathsPattern:
swaggerPathsPattern: [
"batch/resource-manager/Microsoft.Batch/stable/2017-01-01/BatchManagement.json"
]
}
const validator = new LiveValidator(options)
await validator.initialize()
@ -385,7 +402,7 @@ describe("Live Validator", () => {
it("it shouldn't create an implicit default response", async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification/scenarios",
swaggerPathsPattern: "**/*.json",
swaggerPathsPattern: ["**/*.json"],
shouldModelImplicitDefaultResponse: true
}
const validator = new LiveValidator(options)
@ -412,7 +429,7 @@ describe("Live Validator", () => {
it(`should validate request and response for "${livePath}"`, async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification/storage",
swaggerPathsPattern: "**/*.json"
swaggerPathsPattern: ["**/*.json"]
}
const validator = new LiveValidator(options)
await validator.initialize()
@ -426,7 +443,7 @@ describe("Live Validator", () => {
it("should initialize for defaultErrorOnly and fail on unknown status code", async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification/defaultIsErrorOnly",
swaggerPathsPattern: "test.json"
swaggerPathsPattern: ["test.json"]
}
const validator = new LiveValidator(options)
await validator.initialize()
@ -460,7 +477,7 @@ describe("Live Validator", () => {
const options = {
directory:
"./test/liveValidation/swaggers/specification/storage/resource-manager/Microsoft.Storage/2015-05-01-preview",
swaggerPathsPattern: "*.json"
swaggerPathsPattern: ["*.json"]
}
// Upper and lowercased provider and api-version strings for testing purpose
const adjustedUrl =
@ -513,7 +530,7 @@ describe("Live Validator", () => {
it("should initialize for defaultErrorOnly and pass", async () => {
const options = {
directory: "./test/liveValidation/swaggers/specification/defaultIsErrorOnly",
swaggerPathsPattern: "test.json"
swaggerPathsPattern: ["test.json"]
}
const validator = new LiveValidator(options)
await validator.initialize()
@ -560,16 +577,18 @@ describe("Live validator snapshot validation", () => {
directory: `${__dirname}/liveValidation/swaggers/`,
isPathCaseSensitive: false,
useRelativeSourceLocationUrl: true,
swaggerPathsPattern:
"specification\\apimanagement\\resource-manager\\Microsoft.ApiManagement\\preview\\2018-01-01\\*.json",
swaggerPathsPattern: [
"specification\\apimanagement\\resource-manager\\Microsoft.ApiManagement\\preview\\2018-01-01\\*.json"
],
git: {
shouldClone: false
}
}
validator = new LiveValidator(options)
await validator.initialize()
options.swaggerPathsPattern =
options.swaggerPathsPattern = [
"specification\\mediaservices\\resource-manager\\Microsoft.Media\\2018-07-01\\*.json"
]
validatorOneOf = new LiveValidator(options)
await validatorOneOf.initialize()
}, 100000)
@ -585,8 +604,9 @@ describe("Live validator snapshot validation", () => {
directory: `${__dirname}/liveValidation/swaggers/`,
isPathCaseSensitive: false,
useRelativeSourceLocationUrl: true,
swaggerPathsPattern:
"specification\\rpsaas\\resource-manager\\Microsoft.Contoso\\stable\\2019-01-01\\*.json",
swaggerPathsPattern: [
"specification\\rpsaas\\resource-manager\\Microsoft.Contoso\\stable\\2019-01-01\\*.json"
],
git: {
shouldClone: false
}

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

@ -6,8 +6,9 @@ import { LiveValidator } from "../lib/validators/liveValidator"
const options = {
directory: `${__dirname}/../../test/liveValidation/swaggers/`,
swaggerPathsPattern:
"specification\\mediaservices\\resource-manager\\Microsoft.Media\\2018-07-01\\*.json",
swaggerPathsPattern: [
"specification\\mediaservices\\resource-manager\\Microsoft.Media\\2018-07-01\\*.json"
],
git: {
shouldClone: false
}