Remove global cache (#393)
* Remove global cache * update/remove unusued dependencies and increment package version * Remove unusued imports * Fix lint errors
This commit is contained in:
Родитель
67fb79edbc
Коммит
15e1157efd
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
### 03/06/2019 0.14.0
|
||||
|
||||
- Remove package level global doc cache.
|
||||
- Remove external exports of `clearCache()` and of `executePromisesSequentially()`
|
||||
|
||||
### 02/06/2019 0.13.6
|
||||
|
||||
- Polymorphic models should have `"type": "object"`.
|
||||
|
|
3
index.ts
3
index.ts
|
@ -33,9 +33,6 @@ export {
|
|||
ValidationResult
|
||||
} from "./lib/util/validationError"
|
||||
|
||||
export { executePromisesSequentially} from "./lib/util/utils"
|
||||
export { clearCache } from "./lib/util/documents"
|
||||
|
||||
// Classes
|
||||
export { SpecValidator } from "./lib/validators/specValidator"
|
||||
export { LiveValidator } from "./lib/validators/liveValidator"
|
||||
|
|
|
@ -14,7 +14,7 @@ export interface CommonError {
|
|||
errors?: CommonError[]
|
||||
in?: unknown
|
||||
name?: string
|
||||
params?: Array<unknown>
|
||||
params?: unknown[]
|
||||
jsonUrl?: string
|
||||
jsonPosition?: FilePosition
|
||||
position?: FilePosition
|
||||
|
|
|
@ -2,13 +2,3 @@ import { MutableStringMap } from '@ts-common/string-map'
|
|||
import { SwaggerObject } from 'yasway'
|
||||
|
||||
export type DocCache = MutableStringMap<Promise<SwaggerObject>>
|
||||
|
||||
/*
|
||||
* Caches the json docs that were successfully parsed by parseJson().
|
||||
* This avoids, fetching them again.
|
||||
* key: docPath
|
||||
* value: parsed doc in JSON format
|
||||
*/
|
||||
export let docCache: DocCache = {}
|
||||
|
||||
export const clearCache = () => { docCache = {} }
|
||||
|
|
|
@ -11,7 +11,6 @@ import * as vfs from "@ts-common/virtual-fs"
|
|||
import jp = require("jsonpath")
|
||||
import { SwaggerObject } from "yasway"
|
||||
|
||||
import * as docs from "./documents"
|
||||
import { log } from "./logging"
|
||||
import { parseContent } from "./makeRequest"
|
||||
import { isSubPath, splitPathAndReverse } from "./path"
|
||||
|
@ -61,12 +60,10 @@ export async function parseJson(
|
|||
if (!specPath || (specPath && typeof specPath.valueOf() !== "string")) {
|
||||
throw new Error(
|
||||
"A (github) url or a local file path to the swagger spec is required and must be of type " +
|
||||
"string."
|
||||
"string."
|
||||
)
|
||||
}
|
||||
|
||||
const doc = docs.docCache[specPath]
|
||||
|
||||
const applySuppression = (result: SwaggerObject) => {
|
||||
const rootInfo = getFilePosition(result)
|
||||
// apply suppression
|
||||
|
@ -95,10 +92,6 @@ export async function parseJson(
|
|||
return result
|
||||
}
|
||||
|
||||
if (doc) {
|
||||
return await doc
|
||||
}
|
||||
|
||||
// If the spec path is a url starting with https://github then let us auto convert it to an
|
||||
// https://raw.githubusercontent url.
|
||||
if (specPath.startsWith("https://github")) {
|
||||
|
@ -117,7 +110,5 @@ export async function parseJson(
|
|||
|
||||
const swaggerObjectPromise = createSwaggerObject()
|
||||
|
||||
docs.docCache[specPath] = swaggerObjectPromise
|
||||
|
||||
return swaggerObjectPromise
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ export interface NodeError<T extends NodeError<T>> {
|
|||
innerErrors?: T[]
|
||||
in?: string
|
||||
name?: string
|
||||
params?: Array<unknown>
|
||||
params?: unknown[]
|
||||
inner?: T[]
|
||||
title?: string
|
||||
message?: string
|
||||
|
@ -148,7 +148,7 @@ export function processValidationErrors<
|
|||
*/
|
||||
export function serializeErrors<T extends NodeError<T>>(
|
||||
node: T,
|
||||
path: Array<unknown>
|
||||
path: unknown[]
|
||||
): T[] {
|
||||
|
||||
if (isLeaf(node)) {
|
||||
|
@ -284,9 +284,9 @@ const isLeaf = <T extends NodeError<T>>(node: T): boolean =>
|
|||
* Unifies a suffix path with a root path.
|
||||
*/
|
||||
function consolidatePath(
|
||||
path: Array<unknown>,
|
||||
path: unknown[],
|
||||
suffixPath: string | string[]
|
||||
): Array<unknown> {
|
||||
): unknown[] {
|
||||
let newSuffixIndex = 0
|
||||
let overlapIndex = path.lastIndexOf(suffixPath[newSuffixIndex])
|
||||
let previousIndex = overlapIndex
|
||||
|
@ -306,7 +306,7 @@ function consolidatePath(
|
|||
break
|
||||
}
|
||||
}
|
||||
let newPath: Array<unknown> = []
|
||||
let newPath: unknown[] = []
|
||||
if (newSuffixIndex === suffixPath.length) {
|
||||
// if all elements are contained in the existing path, nothing to do.
|
||||
newPath = path.slice(0)
|
||||
|
|
|
@ -54,19 +54,19 @@ export interface RequestResponseObj {
|
|||
export interface RequestValidationResult {
|
||||
successfulRequest: unknown
|
||||
operationInfo?: unknown
|
||||
errors?: Array<unknown>
|
||||
errors?: unknown[]
|
||||
}
|
||||
|
||||
export interface ResponseValidationResult {
|
||||
successfulResponse: unknown
|
||||
operationInfo?: unknown
|
||||
errors?: Array<unknown>
|
||||
errors?: unknown[]
|
||||
}
|
||||
|
||||
export interface ValidationResult {
|
||||
readonly requestValidationResult: RequestValidationResult
|
||||
readonly responseValidationResult: ResponseValidationResult
|
||||
errors: Array<unknown>
|
||||
errors: unknown[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -168,7 +168,7 @@ export class ModelValidator extends SpecValidator<SpecValidationResult> {
|
|||
private constructRequestResultWrapper(
|
||||
operationId: string,
|
||||
requestValidationErrors: ModelValidationError[],
|
||||
requestValidationWarnings: Array<unknown> | undefined,
|
||||
requestValidationWarnings: unknown[] | undefined,
|
||||
exampleType: OperationResultType,
|
||||
scenarioName?: string
|
||||
): void {
|
||||
|
@ -209,7 +209,7 @@ export class ModelValidator extends SpecValidator<SpecValidationResult> {
|
|||
operationId: string,
|
||||
responseStatusCode: string,
|
||||
responseValidationErrors: ModelValidationError[],
|
||||
responseValidationWarnings: Array<unknown> | undefined,
|
||||
responseValidationWarnings: unknown[] | undefined,
|
||||
exampleType: OperationResultType,
|
||||
scenarioName?: string
|
||||
): void {
|
||||
|
|
|
@ -15,7 +15,6 @@ import { StringMap } from "@ts-common/string-map"
|
|||
import { getSuppressions } from "./suppressions"
|
||||
import * as amd from "@azure/openapi-markdown"
|
||||
import { setMutableProperty } from "@ts-common/property-set"
|
||||
import * as docs from "../util/documents"
|
||||
import * as jsonUtils from "../util/jsonUtils"
|
||||
import * as jsonParser from "@ts-common/json-parser"
|
||||
import * as json from "@ts-common/json"
|
||||
|
@ -171,9 +170,6 @@ export class SpecValidator<T extends CommonValidationResult> {
|
|||
* and initializes the internal api validator.
|
||||
*/
|
||||
public async initialize(): Promise<Sway.SwaggerApi> {
|
||||
if (this.options.shouldResolveRelativePaths) {
|
||||
docs.clearCache()
|
||||
}
|
||||
const errors: jsonParser.ParseError[] = []
|
||||
const reportError = (e: jsonParser.ParseError) => errors.push(e)
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,6 @@ import { map, toArray } from "@ts-common/iterator"
|
|||
import { getSuppressions } from "./validators/suppressions"
|
||||
import { Suppression } from "@azure/openapi-markdown"
|
||||
import { setMutableProperty } from "@ts-common/property-set"
|
||||
import * as docs from "./util/documents"
|
||||
import * as jsonUtils from "./util/jsonUtils"
|
||||
import * as jsonParser from "@ts-common/json-parser"
|
||||
|
||||
|
@ -37,7 +36,6 @@ export class WireFormatGenerator {
|
|||
private specInJson: Sway.SwaggerObject | null
|
||||
private specResolver: SpecResolver | null
|
||||
private swaggerApi: Sway.SwaggerApi | null
|
||||
private readonly options: { readonly shouldResolveRelativePaths: unknown }
|
||||
// private specValidationResult: any
|
||||
public constructor(
|
||||
specPath: string,
|
||||
|
@ -73,15 +71,9 @@ export class WireFormatGenerator {
|
|||
this.specInJson = specInJson
|
||||
this.specResolver = null
|
||||
this.swaggerApi = null
|
||||
this.options = {
|
||||
shouldResolveRelativePaths: true
|
||||
}
|
||||
}
|
||||
|
||||
public async initialize(): Promise<Sway.SwaggerApi> {
|
||||
if (this.options.shouldResolveRelativePaths) {
|
||||
docs.clearCache()
|
||||
}
|
||||
try {
|
||||
const suppression = await getSuppressions(this.specPath)
|
||||
const result = await jsonUtils.parseJson(
|
||||
|
@ -186,12 +178,12 @@ export class WireFormatGenerator {
|
|||
* @return {object} err Return the constructed Error object.
|
||||
*/
|
||||
private constructErrorObject(
|
||||
code: unknown, message: string, innerErrors: Array<unknown>, _?: boolean
|
||||
code: unknown, message: string, innerErrors: unknown[], _?: boolean
|
||||
) {
|
||||
const err: {
|
||||
code: unknown
|
||||
message: string
|
||||
innerErrors?: Array<unknown>
|
||||
innerErrors?: unknown[]
|
||||
} = {
|
||||
code,
|
||||
message
|
||||
|
|
35
package.json
35
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oav",
|
||||
"version": "0.13.6",
|
||||
"version": "0.14.0",
|
||||
"author": {
|
||||
"name": "Microsoft Corporation",
|
||||
"email": "azsdkteam@microsoft.com",
|
||||
|
@ -12,58 +12,53 @@
|
|||
"@azure/openapi-markdown": "^0.7.4",
|
||||
"@microsoft.azure/autorest-extension-base": "1.0.13",
|
||||
"@ts-common/commonmark-to-markdown": "^1.1.10",
|
||||
"@ts-common/iterator": "^0.1.3",
|
||||
"@ts-common/iterator": "^0.1.4",
|
||||
"@ts-common/json": "^0.2.0",
|
||||
"@ts-common/json-parser": "^0.5.1",
|
||||
"@ts-common/property-set": "^0.0.10",
|
||||
"@ts-common/source-map": "^0.4.2",
|
||||
"@ts-common/string-map": "^0.2.4",
|
||||
"@ts-common/tuple": "^0.0.6",
|
||||
"@ts-common/virtual-fs": "^0.1.2",
|
||||
"azure-arm-resource": "^2.0.0-preview",
|
||||
"commonmark": "^0.28.1",
|
||||
"glob": "^5.0.14",
|
||||
"js-yaml": "^3.12.1",
|
||||
"js-yaml": "^3.12.2",
|
||||
"json-pointer": "^0.6.0",
|
||||
"json-refs": "^3.0.12",
|
||||
"jsonpath": "^1.0.0",
|
||||
"jsonpath": "^1.0.1",
|
||||
"linq": "^3.1.1",
|
||||
"lodash": "^4.17.11",
|
||||
"moment": "~2.23.0",
|
||||
"moment": "~2.24.0",
|
||||
"ms-rest": "^2.3.8",
|
||||
"ms-rest-azure": "^2.6.0",
|
||||
"recursive-readdir": "^2.2.2",
|
||||
"request": "^2.88.0",
|
||||
"swagger-parser": "^6.0.3",
|
||||
"swagger-parser": "^6.0.5",
|
||||
"swagger-tools": "^0.10.4",
|
||||
"tslint-config-prettier": "^1.17.0",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"uuid": "^3.3.2",
|
||||
"vscode-jsonrpc": "^3.6.2",
|
||||
"winston": "^3.1.0",
|
||||
"winston": "^3.2.1",
|
||||
"yargs": "^6.6.0",
|
||||
"yasway": "^1.5.14",
|
||||
"yuml2svg": "^3.1.0",
|
||||
"z-schema": "^3.25.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/commonmark": "^0.27.2",
|
||||
"@types/commonmark": "^0.27.3",
|
||||
"@types/glob": "^5.0.35",
|
||||
"@types/js-yaml": "^3.12.0",
|
||||
"@types/json-pointer": "^1.0.30",
|
||||
"@types/lodash": "^4.14.119",
|
||||
"@types/lodash": "^4.14.122",
|
||||
"@types/request": "^2.48.1",
|
||||
"@types/jsonpath": "^0.2.0",
|
||||
"@types/mocha": "^5.2.5",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@types/node": "^10.12.18",
|
||||
"@types/recursive-readdir": "^2.2.0",
|
||||
"@types/swagger-parser": "^4.0.2",
|
||||
"@types/swagger-parser": "^4.0.3",
|
||||
"@types/uuid": "^3.4.4",
|
||||
"@types/yargs": "^11.1.2",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-junit-reporter": "^1.18.0",
|
||||
"nyc": "^13.1.0",
|
||||
"nyc": "^13.3.0",
|
||||
"should": "^13.2.3",
|
||||
"tslint": "^5.12.1",
|
||||
"tslint": "^5.13.1",
|
||||
"typescript": "~3.2.4"
|
||||
},
|
||||
"homepage": "https://github.com/azure/oav",
|
||||
|
@ -123,4 +118,4 @@
|
|||
"engines": {
|
||||
"node": ">=10.11.0"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,8 +49,7 @@ const f = async () => {
|
|||
"C:/github.com/Azure/azure-rest-api-specs/specification/logic/resource-manager/Microsoft.Logic/preview/2018-07-01-preview/logic.json"
|
||||
]) {
|
||||
try {
|
||||
await oav.validateExamples(swagger, undefined, {consoleLogLevel: 'error', pretty: true});
|
||||
oav.clearCache();
|
||||
await oav.validateExamples(swagger, undefined, { consoleLogLevel: 'error', pretty: true });
|
||||
} catch (e) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.error("error: ")
|
||||
|
|
Загрузка…
Ссылка в новой задаче