From 15e1157efd1065d8161c183a11476a2cd385b643 Mon Sep 17 00:00:00 2001 From: Vlad Barosan Date: Wed, 6 Mar 2019 10:05:37 -0800 Subject: [PATCH] Remove global cache (#393) * Remove global cache * update/remove unusued dependencies and increment package version * Remove unusued imports * Fix lint errors --- ChangeLog.md | 5 +++++ index.ts | 3 --- lib/util/commonError.ts | 2 +- lib/util/documents.ts | 10 --------- lib/util/jsonUtils.ts | 11 +--------- lib/util/validationError.ts | 10 ++++----- lib/validators/liveValidator.ts | 6 +++--- lib/validators/modelValidator.ts | 4 ++-- lib/validators/specValidator.ts | 4 ---- lib/wireFormatGenerator.ts | 12 ++--------- package.json | 35 ++++++++++++++------------------ scripts/testNetwork.ts | 3 +-- 12 files changed, 35 insertions(+), 70 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 7a0e709d..3fc9554c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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"`. diff --git a/index.ts b/index.ts index e31a8f25..2c9b9355 100644 --- a/index.ts +++ b/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" diff --git a/lib/util/commonError.ts b/lib/util/commonError.ts index cf8dc8b0..057127d5 100644 --- a/lib/util/commonError.ts +++ b/lib/util/commonError.ts @@ -14,7 +14,7 @@ export interface CommonError { errors?: CommonError[] in?: unknown name?: string - params?: Array + params?: unknown[] jsonUrl?: string jsonPosition?: FilePosition position?: FilePosition diff --git a/lib/util/documents.ts b/lib/util/documents.ts index 60c6c440..bda6122e 100644 --- a/lib/util/documents.ts +++ b/lib/util/documents.ts @@ -2,13 +2,3 @@ import { MutableStringMap } from '@ts-common/string-map' import { SwaggerObject } from 'yasway' export type DocCache = MutableStringMap> - -/* - * 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 = {} } diff --git a/lib/util/jsonUtils.ts b/lib/util/jsonUtils.ts index 633cf089..9e3db789 100644 --- a/lib/util/jsonUtils.ts +++ b/lib/util/jsonUtils.ts @@ -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 } diff --git a/lib/util/validationError.ts b/lib/util/validationError.ts index e7c439b7..ed7e57a1 100644 --- a/lib/util/validationError.ts +++ b/lib/util/validationError.ts @@ -99,7 +99,7 @@ export interface NodeError> { innerErrors?: T[] in?: string name?: string - params?: Array + params?: unknown[] inner?: T[] title?: string message?: string @@ -148,7 +148,7 @@ export function processValidationErrors< */ export function serializeErrors>( node: T, - path: Array + path: unknown[] ): T[] { if (isLeaf(node)) { @@ -284,9 +284,9 @@ const isLeaf = >(node: T): boolean => * Unifies a suffix path with a root path. */ function consolidatePath( - path: Array, + path: unknown[], suffixPath: string | string[] -): Array { +): unknown[] { let newSuffixIndex = 0 let overlapIndex = path.lastIndexOf(suffixPath[newSuffixIndex]) let previousIndex = overlapIndex @@ -306,7 +306,7 @@ function consolidatePath( break } } - let newPath: Array = [] + let newPath: unknown[] = [] if (newSuffixIndex === suffixPath.length) { // if all elements are contained in the existing path, nothing to do. newPath = path.slice(0) diff --git a/lib/validators/liveValidator.ts b/lib/validators/liveValidator.ts index 07c924ea..c2eef368 100644 --- a/lib/validators/liveValidator.ts +++ b/lib/validators/liveValidator.ts @@ -54,19 +54,19 @@ export interface RequestResponseObj { export interface RequestValidationResult { successfulRequest: unknown operationInfo?: unknown - errors?: Array + errors?: unknown[] } export interface ResponseValidationResult { successfulResponse: unknown operationInfo?: unknown - errors?: Array + errors?: unknown[] } export interface ValidationResult { readonly requestValidationResult: RequestValidationResult readonly responseValidationResult: ResponseValidationResult - errors: Array + errors: unknown[] } /** diff --git a/lib/validators/modelValidator.ts b/lib/validators/modelValidator.ts index ba16f175..1c1ebf86 100644 --- a/lib/validators/modelValidator.ts +++ b/lib/validators/modelValidator.ts @@ -168,7 +168,7 @@ export class ModelValidator extends SpecValidator { private constructRequestResultWrapper( operationId: string, requestValidationErrors: ModelValidationError[], - requestValidationWarnings: Array | undefined, + requestValidationWarnings: unknown[] | undefined, exampleType: OperationResultType, scenarioName?: string ): void { @@ -209,7 +209,7 @@ export class ModelValidator extends SpecValidator { operationId: string, responseStatusCode: string, responseValidationErrors: ModelValidationError[], - responseValidationWarnings: Array | undefined, + responseValidationWarnings: unknown[] | undefined, exampleType: OperationResultType, scenarioName?: string ): void { diff --git a/lib/validators/specValidator.ts b/lib/validators/specValidator.ts index a8eac566..28885114 100644 --- a/lib/validators/specValidator.ts +++ b/lib/validators/specValidator.ts @@ -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 { * and initializes the internal api validator. */ public async initialize(): Promise { - if (this.options.shouldResolveRelativePaths) { - docs.clearCache() - } const errors: jsonParser.ParseError[] = [] const reportError = (e: jsonParser.ParseError) => errors.push(e) try { diff --git a/lib/wireFormatGenerator.ts b/lib/wireFormatGenerator.ts index c769ac6f..7991b316 100644 --- a/lib/wireFormatGenerator.ts +++ b/lib/wireFormatGenerator.ts @@ -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 { - 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, _?: boolean + code: unknown, message: string, innerErrors: unknown[], _?: boolean ) { const err: { code: unknown message: string - innerErrors?: Array + innerErrors?: unknown[] } = { code, message diff --git a/package.json b/package.json index 9b00e6a7..49fcb2de 100644 --- a/package.json +++ b/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" } -} +} \ No newline at end of file diff --git a/scripts/testNetwork.ts b/scripts/testNetwork.ts index 27974474..dbbfa6db 100644 --- a/scripts/testNetwork.ts +++ b/scripts/testNetwork.ts @@ -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: ")