@ehuelsmann/openapi-validator 0.16.2 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -104,6 +104,8 @@ var getPathnameWithoutBasePath = (basePath, pathname) => basePath === defaultBas
104
104
 
105
105
  // lib/classes/AbstractOpenApiSpec.ts
106
106
  var import_openapi_response_validator = __toESM(require("openapi-response-validator"));
107
+ var _a;
108
+ var OpenAPIResponseValidator = (_a = import_openapi_response_validator.default.default) != null ? _a : import_openapi_response_validator.default;
107
109
  var OpenApiSpec = class {
108
110
  constructor(spec) {
109
111
  this.spec = spec;
@@ -118,8 +120,8 @@ var OpenApiSpec = class {
118
120
  return Object.keys(this.pathsObject());
119
121
  }
120
122
  getSchemaObject(schemaName) {
121
- var _a2;
122
- return (_a2 = this.getSchemaObjects()) == null ? void 0 : _a2[schemaName];
123
+ var _a3;
124
+ return (_a3 = this.getSchemaObjects()) == null ? void 0 : _a3[schemaName];
123
125
  }
124
126
  getExpectedResponse(responseOperation, status) {
125
127
  const response = responseOperation.responses[status];
@@ -173,7 +175,7 @@ var OpenApiSpec = class {
173
175
  }
174
176
  throw error;
175
177
  }
176
- const validator = new import_openapi_response_validator.default({
178
+ const validator = new OpenAPIResponseValidator({
177
179
  responses: expectedResponse,
178
180
  ...this.getComponentDefinitionsProperty()
179
181
  });
@@ -198,7 +200,7 @@ var OpenApiSpec = class {
198
200
  validateObject(actualObject, schema) {
199
201
  const mockResStatus = "200";
200
202
  const mockExpectedResponse = { [mockResStatus]: { schema } };
201
- const validator = new import_openapi_response_validator.default({
203
+ const validator = new OpenAPIResponseValidator({
202
204
  responses: mockExpectedResponse,
203
205
  ...this.getComponentDefinitionsProperty(),
204
206
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -245,9 +247,9 @@ var OpenApi2Spec = class extends OpenApiSpec {
245
247
  return openApiPath;
246
248
  }
247
249
  findResponseDefinition(referenceString) {
248
- var _a2;
250
+ var _a3;
249
251
  const nameOfResponseDefinition = referenceString.split("#/responses/")[1];
250
- return (_a2 = this.spec.responses) == null ? void 0 : _a2[nameOfResponseDefinition];
252
+ return (_a3 = this.spec.responses) == null ? void 0 : _a3[nameOfResponseDefinition];
251
253
  }
252
254
  getComponentDefinitionsProperty() {
253
255
  return { definitions: this.spec.definitions };
@@ -369,24 +371,24 @@ var OpenApi3Spec = class extends OpenApiSpec {
369
371
  return openApiPath;
370
372
  }
371
373
  findResponseDefinition(referenceString) {
372
- var _a2, _b;
374
+ var _a3, _b;
373
375
  const nameOfResponseDefinition = referenceString.split(
374
376
  "#/components/responses/"
375
377
  )[1];
376
- return (_b = (_a2 = this.spec.components) == null ? void 0 : _a2.responses) == null ? void 0 : _b[nameOfResponseDefinition];
378
+ return (_b = (_a3 = this.spec.components) == null ? void 0 : _a3.responses) == null ? void 0 : _b[nameOfResponseDefinition];
377
379
  }
378
380
  getComponentDefinitionsProperty() {
379
381
  return { components: this.spec.components };
380
382
  }
381
383
  getSchemaObjects() {
382
- var _a2;
383
- return (_a2 = this.spec.components) == null ? void 0 : _a2.schemas;
384
+ var _a3;
385
+ return (_a3 = this.spec.components) == null ? void 0 : _a3.schemas;
384
386
  }
385
387
  };
386
388
 
387
389
  // lib/openApiSpecFactory.ts
388
- var _a;
389
- var OpenAPISchemaValidator = (_a = import_openapi_schema_validator.default.default) != null ? _a : import_openapi_schema_validator.default;
390
+ var _a2;
391
+ var OpenAPISchemaValidator = (_a2 = import_openapi_schema_validator.default.default) != null ? _a2 : import_openapi_schema_validator.default;
390
392
  var isObject = (arg) => typeof arg === "object" && arg !== null && !Array.isArray(arg);
391
393
  function makeApiSpec(filepathOrObject) {
392
394
  const spec = loadSpec(filepathOrObject);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/index.ts","../lib/classes/errors/ValidationError.ts","../lib/openApiSpecFactory.ts","../lib/utils/common.utils.ts","../lib/classes/AbstractOpenApiSpec.ts","../lib/classes/OpenApi2Spec.ts","../lib/utils/OpenApi3Spec.utils.ts","../lib/classes/OpenApi3Spec.ts","../lib/classes/AbstractResponse.ts","../lib/classes/AxiosResponse.ts","../lib/classes/SuperAgentResponse.ts","../lib/responseFactory.ts"],"sourcesContent":["import type { OpenAPI } from 'openapi-types';\nimport type OpenApi2Spec from './classes/OpenApi2Spec';\nimport type OpenApi3Spec from './classes/OpenApi3Spec';\n\nexport type { Schema } from './classes/AbstractOpenApiSpec';\nexport type {\n ActualRequest,\n ActualResponse,\n RawResponse,\n} from './classes/AbstractResponse';\nexport type { default as ValidationError } from './classes/errors/ValidationError';\nexport { ErrorCode } from './classes/errors/ValidationError';\nexport type { default as OpenApi2Spec } from './classes/OpenApi2Spec';\nexport type { default as OpenApi3Spec } from './classes/OpenApi3Spec';\nexport { default as makeApiSpec } from './openApiSpecFactory';\nexport { default as makeResponse } from './responseFactory';\n\nexport type OpenApiSpec = OpenApi2Spec | OpenApi3Spec;\nexport type OpenAPISpecObject = OpenAPI.Document;\n","export enum ErrorCode {\n ServerNotFound,\n BasePathNotFound,\n PathNotFound,\n MethodNotFound,\n StatusNotFound,\n InvalidBody,\n InvalidObject,\n}\n\nexport default class ValidationError extends Error {\n constructor(\n public code: ErrorCode,\n message?: string,\n ) {\n super(message);\n }\n\n override toString(): string {\n return this.message;\n }\n}\n","import fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport OpenAPISchemaValidatorModule from 'openapi-schema-validator';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport path from 'path';\nimport typeOf from 'typeof';\nimport OpenApi2Spec from './classes/OpenApi2Spec';\nimport OpenApi3Spec from './classes/OpenApi3Spec';\nimport { stringify } from './utils/common.utils';\n\n// openapi-schema-validator is a CommonJS module that sets `exports.__esModule = true`\n// and exports the class via `exports.default`. When imported natively as ESM, Node.js\n// exposes the whole `module.exports` object as the default, so we must unwrap `.default`\n// to get the actual constructor. The `??` fallback covers the CJS build context where\n// the bundler (esbuild/__toESM) has already unwrapped it for us.\nconst OpenAPISchemaValidator = (\n (\n OpenAPISchemaValidatorModule as unknown as {\n default?: typeof OpenAPISchemaValidatorModule;\n }\n ).default ?? OpenAPISchemaValidatorModule\n);\n\ntype AnyObject = Record<string, unknown>;\n\nconst isObject = (arg: unknown): arg is AnyObject =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg);\n\nexport default function makeApiSpec(\n filepathOrObject: string | OpenAPI.Document,\n): OpenApi2Spec | OpenApi3Spec {\n const spec = loadSpec(filepathOrObject);\n validateSpec(spec);\n const validSpec = spec as OpenAPI.Document;\n if ('swagger' in validSpec) {\n return new OpenApi2Spec(validSpec);\n }\n return new OpenApi3Spec(validSpec as OpenAPIV3.Document);\n}\n\nfunction loadSpec(arg: unknown): AnyObject {\n try {\n if (typeof arg === 'string') {\n return loadFile(arg);\n }\n if (isObject(arg)) {\n return arg;\n }\n throw new Error(`Received type '${typeOf(arg)}'`);\n } catch (error) {\n throw new Error(\n `The provided argument must be either an absolute filepath or an object representing an OpenAPI specification.\\nError details: ${\n (error as Error).message\n }`,\n );\n }\n}\n\nfunction loadFile(filepath: string): AnyObject {\n if (!path.isAbsolute(filepath)) {\n throw new Error(`'${filepath}' is not an absolute filepath`);\n }\n const fileData = fs.readFileSync(filepath, { encoding: 'utf8' });\n try {\n return yaml.load(fileData) as AnyObject;\n } catch (error) {\n throw new Error(`Invalid YAML or JSON:\\n${(error as Error).message}`);\n }\n}\n\nfunction validateSpec(obj: AnyObject): OpenAPI.Document {\n try {\n const validator = new OpenAPISchemaValidator({\n version:\n (obj as unknown as OpenAPIV2.Document).swagger || // '2.0'\n (obj as unknown as OpenAPIV3.Document).openapi, // '3.X.X'\n });\n const { errors } = validator.validate(obj as OpenAPI.Document);\n if (errors.length > 0) {\n throw new Error(stringify(errors));\n }\n return obj as OpenAPI.Document;\n } catch (error) {\n throw new Error(`Invalid OpenAPI spec: ${(error as Error).message}`);\n }\n}\n","import { Path } from 'path-parser';\nimport url from 'url';\nimport { inspect } from 'util';\nimport type { ActualRequest } from '../classes/AbstractResponse';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { depth: null });\n\n/**\n * Excludes the query because path = pathname + query\n */\nexport const getPathname = (request: ActualRequest): string =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n url.parse(request.path).pathname!;\n\n/**\n * Converts all {foo} to :foo\n */\nconst convertOpenApiPathToColonForm = (openApiPath: string): string =>\n openApiPath.replace(/{/g, ':').replace(/}/g, '');\n\nconst doesColonPathMatchPathname = (\n pathInColonForm: string,\n pathname: string,\n): boolean => {\n /*\n * By default, OpenAPI path parameters have `style: simple; explode: false` (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object)\n * So array path parameters in the pathname of the actual request should be in the form: `/pathParams/a,b,c`\n * `path-parser` fails to match parameter patterns to parameters containing commas.\n * So we remove the commas.\n */\n const pathWithoutCommas = pathname.replace(/,/g, '');\n const pathParamsInPathname = new Path(pathInColonForm).test(\n pathWithoutCommas,\n ); // => one of: null, {}, {exampleParam: 'foo'}\n return Boolean(pathParamsInPathname);\n};\n\nconst doesOpenApiPathMatchPathname = (\n openApiPath: string,\n pathname: string,\n): boolean => {\n const pathInColonForm = convertOpenApiPathToColonForm(openApiPath);\n return doesColonPathMatchPathname(pathInColonForm, pathname);\n};\n\nexport const findOpenApiPathMatchingPossiblePathnames = (\n possiblePathnames: string[],\n OAPaths: string[],\n): string | undefined => {\n let openApiPath: string | undefined;\n // eslint-disable-next-line no-restricted-syntax\n for (const pathname of possiblePathnames) {\n // eslint-disable-next-line no-restricted-syntax\n for (const OAPath of OAPaths) {\n if (OAPath === pathname) {\n return OAPath;\n }\n if (doesOpenApiPathMatchPathname(OAPath, pathname)) {\n openApiPath = OAPath;\n }\n }\n }\n return openApiPath;\n};\n\nexport const defaultBasePath = '/';\n\nexport const getPathnameWithoutBasePath = (\n basePath: string,\n pathname: string,\n): string =>\n basePath === defaultBasePath ? pathname : pathname.replace(basePath, '');\n","import OpenAPIResponseValidator, {\n type OpenAPIResponseValidatorArgs,\n} from 'openapi-response-validator';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { getPathname } from '../utils/common.utils';\nimport type { ActualRequest, ActualResponse } from './AbstractResponse';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\ntype Document = OpenAPIV2.Document | OpenAPIV3.Document;\n\ntype Operation = OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;\n\ntype HttpMethods = OpenAPIV2.HttpMethods;\n\ntype PathItemObject = OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject;\n\nexport type ResponseObjectWithSchema =\n | (OpenAPIV2.ResponseObject & { schema: OpenAPIV2.Schema })\n | (OpenAPIV3.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3.MediaTypeObject & {\n schema: OpenAPIV3.SchemaObject;\n };\n };\n })\n | (OpenAPIV3_1.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3_1.MediaTypeObject & {\n schema: OpenAPIV3_1.SchemaObject;\n };\n };\n });\n\nexport type Schema = OpenAPIV2.Schema | OpenAPIV3.SchemaObject;\n\nexport default abstract class OpenApiSpec {\n protected abstract getSchemaObjects(): Record<string, Schema> | undefined;\n\n protected abstract findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined;\n\n protected abstract findOpenApiPathMatchingPathname(pathname: string): string;\n\n protected abstract getComponentDefinitionsProperty():\n | {\n definitions: OpenAPIV2.Document['definitions'];\n }\n | {\n components: OpenAPIV3.Document['components'];\n };\n\n constructor(protected spec: Document) {}\n\n pathsObject(): Document['paths'] {\n return this.spec.paths;\n }\n\n getPathItem(openApiPath: string): PathItemObject {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.pathsObject()[openApiPath]!;\n }\n\n paths(): string[] {\n return Object.keys(this.pathsObject());\n }\n\n getSchemaObject(schemaName: string): Schema | undefined {\n return this.getSchemaObjects()?.[schemaName];\n }\n\n getExpectedResponse(\n responseOperation: Operation,\n status: ActualResponse['status'],\n ): ResponseObjectWithSchema | undefined {\n const response = responseOperation.responses[status];\n if (!response) {\n return undefined;\n }\n if ('$ref' in response) {\n return this.findResponseDefinition(response.$ref);\n }\n return response as ResponseObjectWithSchema;\n }\n\n findExpectedResponse(\n actualResponse: ActualResponse,\n ): Record<string, ResponseObjectWithSchema> {\n const actualRequest = actualResponse.req;\n const expectedResponseOperation =\n this.findExpectedResponseOperation(actualRequest);\n if (!expectedResponseOperation) {\n throw new ValidationError(ErrorCode.MethodNotFound);\n }\n\n const { status } = actualResponse;\n const expectedResponse = this.getExpectedResponse(\n expectedResponseOperation,\n status,\n );\n if (!expectedResponse) {\n throw new ValidationError(ErrorCode.StatusNotFound);\n }\n\n return { [status]: expectedResponse };\n }\n\n findOpenApiPathMatchingRequest(actualRequest: ActualRequest): string {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n return openApiPath;\n }\n\n findExpectedPathItem(actualRequest: ActualRequest): PathItemObject {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n const pathItemObject = this.getPathItem(openApiPath);\n return pathItemObject;\n }\n\n findExpectedResponseOperation(\n actualRequest: ActualRequest,\n ): Operation | undefined {\n const pathItemObject = this.findExpectedPathItem(actualRequest);\n const operationObject =\n pathItemObject[actualRequest.method.toLowerCase() as HttpMethods];\n return operationObject;\n }\n\n validateResponse(actualResponse: ActualResponse): ValidationError | null {\n let expectedResponse: Record<string, ResponseObjectWithSchema>;\n try {\n expectedResponse = this.findExpectedResponse(actualResponse);\n } catch (error) {\n if (error instanceof ValidationError) {\n return error;\n }\n throw error;\n }\n const validator = new OpenAPIResponseValidator({\n responses: expectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n } as OpenAPIResponseValidatorArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const expectedResStatus = Object.keys(expectedResponse)[0]!;\n const validationError = validator.validateResponse(\n expectedResStatus,\n actualResponse.getBodyForValidation(),\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidBody,\n validationError.errors!\n .map(({ path, message }: { path?: string; message: string }) => `${path} ${message}`)\n .join(', '),\n )\n : null;\n }\n\n /*\n * For consistency and to save maintaining another dependency,\n * we validate objects using our response validator:\n * We put the object inside a mock response, then validate\n * the whole response against a mock expected response.\n * The 2 mock responses are identical except for the body,\n * thus validating the object against its schema.\n */\n validateObject(\n actualObject: unknown,\n schema: Schema,\n ): ValidationError | null {\n const mockResStatus = '200';\n const mockExpectedResponse = { [mockResStatus]: { schema } };\n const validator = new OpenAPIResponseValidator({\n responses: mockExpectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n errorTransformer: ({ path, message }: { path?: string; message: string; errorCode: string }) => ({\n message: `${path!.replace('response', 'object')} ${message}`,\n }),\n } as OpenAPIResponseValidatorArgs);\n const validationError = validator.validateResponse(\n mockResStatus,\n actualObject,\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidObject,\n validationError.errors!.map((error: { message: string }) => error.message).join(', '),\n )\n : null;\n }\n}\n","import type { OpenAPIV2 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n getPathnameWithoutBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n} from '../utils/common.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nconst basePathPropertyNotProvided = (spec: OpenAPIV2.Document): boolean =>\n !spec.basePath;\n\nexport default class OpenApi2Spec extends AbstractOpenApiSpec {\n public didUserDefineBasePath: boolean;\n\n constructor(public override spec: OpenAPIV2.Document) {\n super(spec);\n this.didUserDefineBasePath = !basePathPropertyNotProvided(spec);\n }\n\n /**\n * \"If the basePath property is not provided, the API is served directly under the host\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields\n */\n findOpenApiPathMatchingPathname(pathname: string): string {\n const { basePath } = this.spec;\n if (basePath && !pathname.startsWith(basePath)) {\n throw new ValidationError(ErrorCode.BasePathNotFound);\n }\n const pathnameWithoutBasePath = basePath\n ? getPathnameWithoutBasePath(basePath, pathname)\n : pathname;\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n [pathnameWithoutBasePath],\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split('#/responses/')[1]!;\n return this.spec.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n definitions: OpenAPIV2.Document['definitions'];\n } {\n return { definitions: this.spec.definitions };\n }\n\n getSchemaObjects(): OpenAPIV2.Document['definitions'] {\n return this.spec.definitions;\n }\n}\n","import generateCombinations from 'combos';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport { defaultBasePath } from './common.utils';\n\ntype ServerVariables = OpenAPIV3.ServerObject['variables'];\n\nconst unique = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const serversPropertyNotProvidedOrIsEmptyArray = (\n spec: OpenAPIV3.Document,\n): boolean => !spec.servers || !spec.servers.length;\n\nconst getBasePath = (url: string): string => {\n const basePathStartIndex = url.replace('//', ' ').indexOf('/');\n return basePathStartIndex !== -1\n ? url.slice(basePathStartIndex)\n : defaultBasePath;\n};\n\nconst getPossibleValuesOfServerVariable = ({\n default: defaultValue,\n enum: enumMembers,\n}: OpenAPIV3.ServerVariableObject): string[] =>\n enumMembers ? unique([defaultValue].concat(enumMembers)) : [defaultValue];\n\nconst mapServerVariablesToPossibleValues = (\n serverVariables: NonNullable<ServerVariables>,\n): Record<string, string[]> =>\n Object.entries(serverVariables).reduce(\n (currentMap, [variableName, detailsOfPossibleValues]) => ({\n ...currentMap,\n [variableName]: getPossibleValuesOfServerVariable(\n detailsOfPossibleValues,\n ),\n }),\n {},\n );\n\nconst convertTemplateExpressionToConcreteExpression = (\n templateExpression: string,\n mapOfVariablesToValues: Record<string, string>,\n) =>\n Object.entries(mapOfVariablesToValues).reduce(\n (currentExpression, [variable, value]) =>\n currentExpression.replace(`{${variable}}`, value),\n templateExpression,\n );\n\nconst getPossibleConcreteBasePaths = (\n basePath: string,\n serverVariables: NonNullable<ServerVariables>,\n): string[] => {\n const mapOfServerVariablesToPossibleValues =\n mapServerVariablesToPossibleValues(serverVariables);\n const combinationsOfBasePathVariableValues = generateCombinations(\n mapOfServerVariablesToPossibleValues,\n );\n const possibleBasePaths = combinationsOfBasePathVariableValues.map(\n (mapOfVariablesToValues) =>\n convertTemplateExpressionToConcreteExpression(\n basePath,\n mapOfVariablesToValues,\n ),\n );\n return possibleBasePaths;\n};\n\nconst getPossibleBasePaths = (\n url: string,\n serverVariables: ServerVariables,\n): string[] => {\n const basePath = getBasePath(url);\n return serverVariables\n ? getPossibleConcreteBasePaths(basePath, serverVariables)\n : [basePath];\n};\n\nexport const getMatchingServerUrlsAndServerBasePaths = (\n servers: OpenAPIV3.ServerObject[],\n pathname: string,\n): { concreteUrl: string; matchingBasePath: string }[] => {\n const matchesPathname = (basePath: string): boolean =>\n pathname.startsWith(basePath);\n return servers\n .map(({ url: templatedUrl, variables }) => ({\n templatedUrl,\n possibleBasePaths: getPossibleBasePaths(templatedUrl, variables),\n }))\n .filter(({ possibleBasePaths }) => possibleBasePaths.some(matchesPathname))\n .map(({ templatedUrl, possibleBasePaths }) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const matchingBasePath = possibleBasePaths.find(matchesPathname)!;\n return {\n concreteUrl: templatedUrl.replace(\n getBasePath(templatedUrl),\n matchingBasePath,\n ),\n matchingBasePath,\n };\n });\n};\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n defaultBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n getPathnameWithoutBasePath,\n} from '../utils/common.utils';\nimport {\n serversPropertyNotProvidedOrIsEmptyArray,\n getMatchingServerUrlsAndServerBasePaths,\n} from '../utils/OpenApi3Spec.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nexport default class OpenApi3Spec extends AbstractOpenApiSpec {\n public didUserDefineServers: boolean;\n\n constructor(protected override spec: OpenAPIV3.Document) {\n super(spec);\n this.didUserDefineServers = !serversPropertyNotProvidedOrIsEmptyArray(spec);\n this.ensureDefaultServer();\n }\n\n /**\n * \"If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of '/'\"\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields\n */\n ensureDefaultServer(): void {\n if (serversPropertyNotProvidedOrIsEmptyArray(this.spec)) {\n this.spec.servers = [{ url: defaultBasePath }];\n }\n }\n\n servers(): OpenAPIV3.ServerObject[] {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.spec.servers!;\n }\n\n getServerUrls(): string[] {\n return this.servers().map((server) => server.url);\n }\n\n getMatchingServerUrls(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ concreteUrl }) => concreteUrl);\n }\n\n getMatchingServerBasePaths(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ matchingBasePath }) => matchingBasePath);\n }\n\n findOpenApiPathMatchingPathname(pathname: string): string {\n const matchingServerBasePaths = this.getMatchingServerBasePaths(pathname);\n if (!matchingServerBasePaths.length) {\n throw new ValidationError(ErrorCode.ServerNotFound);\n }\n const possiblePathnames = matchingServerBasePaths.map((basePath) =>\n getPathnameWithoutBasePath(basePath, pathname),\n );\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n possiblePathnames,\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split(\n '#/components/responses/',\n )[1]!;\n return this.spec.components?.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n components: OpenAPIV3.Document['components'];\n } {\n return { components: this.spec.components };\n }\n\n getSchemaObjects(): OpenAPIV3.ComponentsObject['schemas'] {\n return this.spec.components?.schemas;\n }\n}\n","import { stringify } from '../utils/common.utils';\nimport type { RawAxiosResponse } from './AxiosResponse';\nimport type { RawSuperAgentResponse } from './SuperAgentResponse';\n\nexport type RawResponse =\n | RawAxiosResponse\n | RawSuperAgentResponse;\n\nexport default abstract class AbstractResponse {\n declare public status: number;\n\n declare public req: { method: string; path: string };\n\n public abstract getBodyForValidation(): unknown;\n\n protected body: unknown;\n\n declare protected bodyHasNoContent: boolean;\n\n constructor(protected res: RawResponse) {}\n\n summary(): { body: unknown } {\n return {\n body: this.body,\n };\n }\n\n toString(): string {\n return stringify(this.summary());\n }\n}\n\nexport type ActualResponse = AbstractResponse;\n\nexport type ActualRequest = AbstractResponse['req'];\n","import type { AxiosResponse as AxiosResponseType } from 'axios';\nimport AbstractResponse from './AbstractResponse';\n\nexport type RawAxiosResponse = AxiosResponseType;\n\nexport default class AxiosResponse extends AbstractResponse {\n constructor(protected override res: RawAxiosResponse) {\n super(res);\n this.status = res.status;\n this.body = res.data;\n this.req = res.request;\n this.bodyHasNoContent = this.body === '';\n }\n\n getBodyForValidation(): AxiosResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n return this.body;\n }\n}\n","import type { Response, SuperAgentRequest } from 'superagent';\nimport AbstractResponse from './AbstractResponse';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isEmptyObj = (obj: any): obj is Record<string, never> =>\n !!obj && Object.entries(obj).length === 0 && obj.constructor === Object;\n\nexport type RawSuperAgentResponse = Response & {\n req: SuperAgentRequest & { path: string };\n};\n\nexport default class SuperAgentResponse extends AbstractResponse {\n private isResTextPopulatedInsteadOfResBody: boolean;\n\n constructor(protected override res: RawSuperAgentResponse) {\n super(res);\n this.status = res.status;\n this.body = res.body;\n this.req = res.req;\n this.isResTextPopulatedInsteadOfResBody =\n res.text !== '{}' && isEmptyObj(this.body);\n this.bodyHasNoContent = res.text === '';\n }\n\n getBodyForValidation(): SuperAgentResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n if (this.isResTextPopulatedInsteadOfResBody) {\n return this.res.text;\n }\n return this.body;\n }\n\n override summary(): ReturnType<AbstractResponse['summary']> & {\n text?: string;\n } {\n return {\n ...super.summary(),\n ...(this.isResTextPopulatedInsteadOfResBody && { text: this.res.text }),\n };\n }\n}\n","import { RawResponse } from './classes/AbstractResponse';\nimport AxiosResponse from './classes/AxiosResponse';\nimport SuperAgentResponse from './classes/SuperAgentResponse';\n\nexport default function makeResponse(\n res: RawResponse,\n): AxiosResponse | SuperAgentResponse {\n if ('data' in res) {\n return new AxiosResponse(res);\n }\n if ('status' in res) {\n return new SuperAgentResponse(res);\n }\n throw new Error(\n 'Unsupported response object: expected axios, supertest, superagent, or chai-http response shape.',\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAPU,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AK;AAAA,EACd;AACF;;;AChBA,IAAM,aAAa,CAAC,QAClB,CAAC,CAAC,OAAO,OAAO,QAAQ,GAAG,EAAE,WAAW,KAAK,IAAI,gBAAgB;AAMnE,IAAqB,qBAArB,cAAgD,iBAAiB;AAAA,EAG/D,YAA+B,KAA4B;AACzD,UAAM,GAAG;AADoB;AAE7B,SAAK,SAAS,IAAI;AAClB,SAAK,OAAO,IAAI;AAChB,SAAK,MAAM,IAAI;AACf,SAAK,qCACH,IAAI,SAAS,QAAQ,WAAW,KAAK,IAAI;AAC3C,SAAK,mBAAmB,IAAI,SAAS;AAAA,EACvC;AAAA,EAEA,uBAAmD;AACjD,QAAI,KAAK,kBAAkB;AACzB,aAAO;AAAA,IACT;AACA,QAAI,KAAK,oCAAoC;AAC3C,aAAO,KAAK,IAAI;AAAA,IAClB;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAES,UAEP;AACA,WAAO;AAAA,MACL,GAAG,MAAM,QAAQ;AAAA,MACjB,GAAI,KAAK,sCAAsC,EAAE,MAAM,KAAK,IAAI,KAAK;AAAA,IACvE;AAAA,EACF;AACF;;;ACtCe,SAAR,aACL,KACoC;AACpC,MAAI,UAAU,KAAK;AACjB,WAAO,IAAI,cAAc,GAAG;AAAA,EAC9B;AACA,MAAI,YAAY,KAAK;AACnB,WAAO,IAAI,mBAAmB,GAAG;AAAA,EACnC;AACA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":["ErrorCode","url","_a","OpenAPIResponseValidator","path","_a","url","generateCombinations","_a","OpenAPISchemaValidatorModule","typeOf","path","fs","yaml"]}
1
+ {"version":3,"sources":["../lib/index.ts","../lib/classes/errors/ValidationError.ts","../lib/openApiSpecFactory.ts","../lib/utils/common.utils.ts","../lib/classes/AbstractOpenApiSpec.ts","../lib/classes/OpenApi2Spec.ts","../lib/utils/OpenApi3Spec.utils.ts","../lib/classes/OpenApi3Spec.ts","../lib/classes/AbstractResponse.ts","../lib/classes/AxiosResponse.ts","../lib/classes/SuperAgentResponse.ts","../lib/responseFactory.ts"],"sourcesContent":["import type { OpenAPI } from 'openapi-types';\nimport type OpenApi2Spec from './classes/OpenApi2Spec';\nimport type OpenApi3Spec from './classes/OpenApi3Spec';\n\nexport type { Schema } from './classes/AbstractOpenApiSpec';\nexport type {\n ActualRequest,\n ActualResponse,\n RawResponse,\n} from './classes/AbstractResponse';\nexport type { default as ValidationError } from './classes/errors/ValidationError';\nexport { ErrorCode } from './classes/errors/ValidationError';\nexport type { default as OpenApi2Spec } from './classes/OpenApi2Spec';\nexport type { default as OpenApi3Spec } from './classes/OpenApi3Spec';\nexport { default as makeApiSpec } from './openApiSpecFactory';\nexport { default as makeResponse } from './responseFactory';\n\nexport type OpenApiSpec = OpenApi2Spec | OpenApi3Spec;\nexport type OpenAPISpecObject = OpenAPI.Document;\n","export enum ErrorCode {\n ServerNotFound,\n BasePathNotFound,\n PathNotFound,\n MethodNotFound,\n StatusNotFound,\n InvalidBody,\n InvalidObject,\n}\n\nexport default class ValidationError extends Error {\n constructor(\n public code: ErrorCode,\n message?: string,\n ) {\n super(message);\n }\n\n override toString(): string {\n return this.message;\n }\n}\n","import fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport OpenAPISchemaValidatorModule from 'openapi-schema-validator';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport path from 'path';\nimport typeOf from 'typeof';\nimport OpenApi2Spec from './classes/OpenApi2Spec';\nimport OpenApi3Spec from './classes/OpenApi3Spec';\nimport { stringify } from './utils/common.utils';\n\n// openapi-schema-validator is a CommonJS module that sets `exports.__esModule = true`\n// and exports the class via `exports.default`. When imported natively as ESM, Node.js\n// exposes the whole `module.exports` object as the default, so we must unwrap `.default`\n// to get the actual constructor. The `??` fallback covers the CJS build context where\n// the bundler (esbuild/__toESM) has already unwrapped it for us.\nconst OpenAPISchemaValidator = (\n (\n OpenAPISchemaValidatorModule as unknown as {\n default?: typeof OpenAPISchemaValidatorModule;\n }\n ).default ?? OpenAPISchemaValidatorModule\n);\n\ntype AnyObject = Record<string, unknown>;\n\nconst isObject = (arg: unknown): arg is AnyObject =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg);\n\nexport default function makeApiSpec(\n filepathOrObject: string | OpenAPI.Document,\n): OpenApi2Spec | OpenApi3Spec {\n const spec = loadSpec(filepathOrObject);\n validateSpec(spec);\n const validSpec = spec as OpenAPI.Document;\n if ('swagger' in validSpec) {\n return new OpenApi2Spec(validSpec);\n }\n return new OpenApi3Spec(validSpec as OpenAPIV3.Document);\n}\n\nfunction loadSpec(arg: unknown): AnyObject {\n try {\n if (typeof arg === 'string') {\n return loadFile(arg);\n }\n if (isObject(arg)) {\n return arg;\n }\n throw new Error(`Received type '${typeOf(arg)}'`);\n } catch (error) {\n throw new Error(\n `The provided argument must be either an absolute filepath or an object representing an OpenAPI specification.\\nError details: ${\n (error as Error).message\n }`,\n );\n }\n}\n\nfunction loadFile(filepath: string): AnyObject {\n if (!path.isAbsolute(filepath)) {\n throw new Error(`'${filepath}' is not an absolute filepath`);\n }\n const fileData = fs.readFileSync(filepath, { encoding: 'utf8' });\n try {\n return yaml.load(fileData) as AnyObject;\n } catch (error) {\n throw new Error(`Invalid YAML or JSON:\\n${(error as Error).message}`);\n }\n}\n\nfunction validateSpec(obj: AnyObject): OpenAPI.Document {\n try {\n const validator = new OpenAPISchemaValidator({\n version:\n (obj as unknown as OpenAPIV2.Document).swagger || // '2.0'\n (obj as unknown as OpenAPIV3.Document).openapi, // '3.X.X'\n });\n const { errors } = validator.validate(obj as OpenAPI.Document);\n if (errors.length > 0) {\n throw new Error(stringify(errors));\n }\n return obj as OpenAPI.Document;\n } catch (error) {\n throw new Error(`Invalid OpenAPI spec: ${(error as Error).message}`);\n }\n}\n","import { Path } from 'path-parser';\nimport url from 'url';\nimport { inspect } from 'util';\nimport type { ActualRequest } from '../classes/AbstractResponse';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { depth: null });\n\n/**\n * Excludes the query because path = pathname + query\n */\nexport const getPathname = (request: ActualRequest): string =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n url.parse(request.path).pathname!;\n\n/**\n * Converts all {foo} to :foo\n */\nconst convertOpenApiPathToColonForm = (openApiPath: string): string =>\n openApiPath.replace(/{/g, ':').replace(/}/g, '');\n\nconst doesColonPathMatchPathname = (\n pathInColonForm: string,\n pathname: string,\n): boolean => {\n /*\n * By default, OpenAPI path parameters have `style: simple; explode: false` (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object)\n * So array path parameters in the pathname of the actual request should be in the form: `/pathParams/a,b,c`\n * `path-parser` fails to match parameter patterns to parameters containing commas.\n * So we remove the commas.\n */\n const pathWithoutCommas = pathname.replace(/,/g, '');\n const pathParamsInPathname = new Path(pathInColonForm).test(\n pathWithoutCommas,\n ); // => one of: null, {}, {exampleParam: 'foo'}\n return Boolean(pathParamsInPathname);\n};\n\nconst doesOpenApiPathMatchPathname = (\n openApiPath: string,\n pathname: string,\n): boolean => {\n const pathInColonForm = convertOpenApiPathToColonForm(openApiPath);\n return doesColonPathMatchPathname(pathInColonForm, pathname);\n};\n\nexport const findOpenApiPathMatchingPossiblePathnames = (\n possiblePathnames: string[],\n OAPaths: string[],\n): string | undefined => {\n let openApiPath: string | undefined;\n // eslint-disable-next-line no-restricted-syntax\n for (const pathname of possiblePathnames) {\n // eslint-disable-next-line no-restricted-syntax\n for (const OAPath of OAPaths) {\n if (OAPath === pathname) {\n return OAPath;\n }\n if (doesOpenApiPathMatchPathname(OAPath, pathname)) {\n openApiPath = OAPath;\n }\n }\n }\n return openApiPath;\n};\n\nexport const defaultBasePath = '/';\n\nexport const getPathnameWithoutBasePath = (\n basePath: string,\n pathname: string,\n): string =>\n basePath === defaultBasePath ? pathname : pathname.replace(basePath, '');\n","import OpenAPIResponseValidatorModule, {\n type OpenAPIResponseValidatorArgs,\n} from 'openapi-response-validator';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { getPathname } from '../utils/common.utils';\nimport type { ActualRequest, ActualResponse } from './AbstractResponse';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\ntype Document = OpenAPIV2.Document | OpenAPIV3.Document;\n\ntype Operation = OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;\n\ntype HttpMethods = OpenAPIV2.HttpMethods;\n\ntype PathItemObject = OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject;\n\nconst OpenAPIResponseValidator = (\n OpenAPIResponseValidatorModule as unknown as {\n default?: typeof OpenAPIResponseValidatorModule;\n }\n).default ?? OpenAPIResponseValidatorModule;\n\nexport type ResponseObjectWithSchema =\n | (OpenAPIV2.ResponseObject & { schema: OpenAPIV2.Schema })\n | (OpenAPIV3.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3.MediaTypeObject & {\n schema: OpenAPIV3.SchemaObject;\n };\n };\n })\n | (OpenAPIV3_1.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3_1.MediaTypeObject & {\n schema: OpenAPIV3_1.SchemaObject;\n };\n };\n });\n\nexport type Schema = OpenAPIV2.Schema | OpenAPIV3.SchemaObject;\n\nexport default abstract class OpenApiSpec {\n protected abstract getSchemaObjects(): Record<string, Schema> | undefined;\n\n protected abstract findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined;\n\n protected abstract findOpenApiPathMatchingPathname(pathname: string): string;\n\n protected abstract getComponentDefinitionsProperty():\n | {\n definitions: OpenAPIV2.Document['definitions'];\n }\n | {\n components: OpenAPIV3.Document['components'];\n };\n\n constructor(protected spec: Document) {}\n\n pathsObject(): Document['paths'] {\n return this.spec.paths;\n }\n\n getPathItem(openApiPath: string): PathItemObject {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.pathsObject()[openApiPath]!;\n }\n\n paths(): string[] {\n return Object.keys(this.pathsObject());\n }\n\n getSchemaObject(schemaName: string): Schema | undefined {\n return this.getSchemaObjects()?.[schemaName];\n }\n\n getExpectedResponse(\n responseOperation: Operation,\n status: ActualResponse['status'],\n ): ResponseObjectWithSchema | undefined {\n const response = responseOperation.responses[status];\n if (!response) {\n return undefined;\n }\n if ('$ref' in response) {\n return this.findResponseDefinition(response.$ref);\n }\n return response as ResponseObjectWithSchema;\n }\n\n findExpectedResponse(\n actualResponse: ActualResponse,\n ): Record<string, ResponseObjectWithSchema> {\n const actualRequest = actualResponse.req;\n const expectedResponseOperation =\n this.findExpectedResponseOperation(actualRequest);\n if (!expectedResponseOperation) {\n throw new ValidationError(ErrorCode.MethodNotFound);\n }\n\n const { status } = actualResponse;\n const expectedResponse = this.getExpectedResponse(\n expectedResponseOperation,\n status,\n );\n if (!expectedResponse) {\n throw new ValidationError(ErrorCode.StatusNotFound);\n }\n\n return { [status]: expectedResponse };\n }\n\n findOpenApiPathMatchingRequest(actualRequest: ActualRequest): string {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n return openApiPath;\n }\n\n findExpectedPathItem(actualRequest: ActualRequest): PathItemObject {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n const pathItemObject = this.getPathItem(openApiPath);\n return pathItemObject;\n }\n\n findExpectedResponseOperation(\n actualRequest: ActualRequest,\n ): Operation | undefined {\n const pathItemObject = this.findExpectedPathItem(actualRequest);\n const operationObject =\n pathItemObject[actualRequest.method.toLowerCase() as HttpMethods];\n return operationObject;\n }\n\n validateResponse(actualResponse: ActualResponse): ValidationError | null {\n let expectedResponse: Record<string, ResponseObjectWithSchema>;\n try {\n expectedResponse = this.findExpectedResponse(actualResponse);\n } catch (error) {\n if (error instanceof ValidationError) {\n return error;\n }\n throw error;\n }\n const validator = new OpenAPIResponseValidator({\n responses: expectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n } as OpenAPIResponseValidatorArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const expectedResStatus = Object.keys(expectedResponse)[0]!;\n const validationError = validator.validateResponse(\n expectedResStatus,\n actualResponse.getBodyForValidation(),\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidBody,\n validationError.errors!\n .map(({ path, message }: { path?: string; message: string }) => `${path} ${message}`)\n .join(', '),\n )\n : null;\n }\n\n /*\n * For consistency and to save maintaining another dependency,\n * we validate objects using our response validator:\n * We put the object inside a mock response, then validate\n * the whole response against a mock expected response.\n * The 2 mock responses are identical except for the body,\n * thus validating the object against its schema.\n */\n validateObject(\n actualObject: unknown,\n schema: Schema,\n ): ValidationError | null {\n const mockResStatus = '200';\n const mockExpectedResponse = { [mockResStatus]: { schema } };\n const validator = new OpenAPIResponseValidator({\n responses: mockExpectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n errorTransformer: ({ path, message }: { path?: string; message: string; errorCode: string }) => ({\n message: `${path!.replace('response', 'object')} ${message}`,\n }),\n } as OpenAPIResponseValidatorArgs);\n const validationError = validator.validateResponse(\n mockResStatus,\n actualObject,\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidObject,\n validationError.errors!.map((error: { message: string }) => error.message).join(', '),\n )\n : null;\n }\n}\n","import type { OpenAPIV2 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n getPathnameWithoutBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n} from '../utils/common.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nconst basePathPropertyNotProvided = (spec: OpenAPIV2.Document): boolean =>\n !spec.basePath;\n\nexport default class OpenApi2Spec extends AbstractOpenApiSpec {\n public didUserDefineBasePath: boolean;\n\n constructor(public override spec: OpenAPIV2.Document) {\n super(spec);\n this.didUserDefineBasePath = !basePathPropertyNotProvided(spec);\n }\n\n /**\n * \"If the basePath property is not provided, the API is served directly under the host\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields\n */\n findOpenApiPathMatchingPathname(pathname: string): string {\n const { basePath } = this.spec;\n if (basePath && !pathname.startsWith(basePath)) {\n throw new ValidationError(ErrorCode.BasePathNotFound);\n }\n const pathnameWithoutBasePath = basePath\n ? getPathnameWithoutBasePath(basePath, pathname)\n : pathname;\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n [pathnameWithoutBasePath],\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split('#/responses/')[1]!;\n return this.spec.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n definitions: OpenAPIV2.Document['definitions'];\n } {\n return { definitions: this.spec.definitions };\n }\n\n getSchemaObjects(): OpenAPIV2.Document['definitions'] {\n return this.spec.definitions;\n }\n}\n","import generateCombinations from 'combos';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport { defaultBasePath } from './common.utils';\n\ntype ServerVariables = OpenAPIV3.ServerObject['variables'];\n\nconst unique = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const serversPropertyNotProvidedOrIsEmptyArray = (\n spec: OpenAPIV3.Document,\n): boolean => !spec.servers || !spec.servers.length;\n\nconst getBasePath = (url: string): string => {\n const basePathStartIndex = url.replace('//', ' ').indexOf('/');\n return basePathStartIndex !== -1\n ? url.slice(basePathStartIndex)\n : defaultBasePath;\n};\n\nconst getPossibleValuesOfServerVariable = ({\n default: defaultValue,\n enum: enumMembers,\n}: OpenAPIV3.ServerVariableObject): string[] =>\n enumMembers ? unique([defaultValue].concat(enumMembers)) : [defaultValue];\n\nconst mapServerVariablesToPossibleValues = (\n serverVariables: NonNullable<ServerVariables>,\n): Record<string, string[]> =>\n Object.entries(serverVariables).reduce(\n (currentMap, [variableName, detailsOfPossibleValues]) => ({\n ...currentMap,\n [variableName]: getPossibleValuesOfServerVariable(\n detailsOfPossibleValues,\n ),\n }),\n {},\n );\n\nconst convertTemplateExpressionToConcreteExpression = (\n templateExpression: string,\n mapOfVariablesToValues: Record<string, string>,\n) =>\n Object.entries(mapOfVariablesToValues).reduce(\n (currentExpression, [variable, value]) =>\n currentExpression.replace(`{${variable}}`, value),\n templateExpression,\n );\n\nconst getPossibleConcreteBasePaths = (\n basePath: string,\n serverVariables: NonNullable<ServerVariables>,\n): string[] => {\n const mapOfServerVariablesToPossibleValues =\n mapServerVariablesToPossibleValues(serverVariables);\n const combinationsOfBasePathVariableValues = generateCombinations(\n mapOfServerVariablesToPossibleValues,\n );\n const possibleBasePaths = combinationsOfBasePathVariableValues.map(\n (mapOfVariablesToValues) =>\n convertTemplateExpressionToConcreteExpression(\n basePath,\n mapOfVariablesToValues,\n ),\n );\n return possibleBasePaths;\n};\n\nconst getPossibleBasePaths = (\n url: string,\n serverVariables: ServerVariables,\n): string[] => {\n const basePath = getBasePath(url);\n return serverVariables\n ? getPossibleConcreteBasePaths(basePath, serverVariables)\n : [basePath];\n};\n\nexport const getMatchingServerUrlsAndServerBasePaths = (\n servers: OpenAPIV3.ServerObject[],\n pathname: string,\n): { concreteUrl: string; matchingBasePath: string }[] => {\n const matchesPathname = (basePath: string): boolean =>\n pathname.startsWith(basePath);\n return servers\n .map(({ url: templatedUrl, variables }) => ({\n templatedUrl,\n possibleBasePaths: getPossibleBasePaths(templatedUrl, variables),\n }))\n .filter(({ possibleBasePaths }) => possibleBasePaths.some(matchesPathname))\n .map(({ templatedUrl, possibleBasePaths }) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const matchingBasePath = possibleBasePaths.find(matchesPathname)!;\n return {\n concreteUrl: templatedUrl.replace(\n getBasePath(templatedUrl),\n matchingBasePath,\n ),\n matchingBasePath,\n };\n });\n};\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n defaultBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n getPathnameWithoutBasePath,\n} from '../utils/common.utils';\nimport {\n serversPropertyNotProvidedOrIsEmptyArray,\n getMatchingServerUrlsAndServerBasePaths,\n} from '../utils/OpenApi3Spec.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nexport default class OpenApi3Spec extends AbstractOpenApiSpec {\n public didUserDefineServers: boolean;\n\n constructor(protected override spec: OpenAPIV3.Document) {\n super(spec);\n this.didUserDefineServers = !serversPropertyNotProvidedOrIsEmptyArray(spec);\n this.ensureDefaultServer();\n }\n\n /**\n * \"If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of '/'\"\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields\n */\n ensureDefaultServer(): void {\n if (serversPropertyNotProvidedOrIsEmptyArray(this.spec)) {\n this.spec.servers = [{ url: defaultBasePath }];\n }\n }\n\n servers(): OpenAPIV3.ServerObject[] {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.spec.servers!;\n }\n\n getServerUrls(): string[] {\n return this.servers().map((server) => server.url);\n }\n\n getMatchingServerUrls(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ concreteUrl }) => concreteUrl);\n }\n\n getMatchingServerBasePaths(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ matchingBasePath }) => matchingBasePath);\n }\n\n findOpenApiPathMatchingPathname(pathname: string): string {\n const matchingServerBasePaths = this.getMatchingServerBasePaths(pathname);\n if (!matchingServerBasePaths.length) {\n throw new ValidationError(ErrorCode.ServerNotFound);\n }\n const possiblePathnames = matchingServerBasePaths.map((basePath) =>\n getPathnameWithoutBasePath(basePath, pathname),\n );\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n possiblePathnames,\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split(\n '#/components/responses/',\n )[1]!;\n return this.spec.components?.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n components: OpenAPIV3.Document['components'];\n } {\n return { components: this.spec.components };\n }\n\n getSchemaObjects(): OpenAPIV3.ComponentsObject['schemas'] {\n return this.spec.components?.schemas;\n }\n}\n","import { stringify } from '../utils/common.utils';\nimport type { RawAxiosResponse } from './AxiosResponse';\nimport type { RawSuperAgentResponse } from './SuperAgentResponse';\n\nexport type RawResponse =\n | RawAxiosResponse\n | RawSuperAgentResponse;\n\nexport default abstract class AbstractResponse {\n declare public status: number;\n\n declare public req: { method: string; path: string };\n\n public abstract getBodyForValidation(): unknown;\n\n protected body: unknown;\n\n declare protected bodyHasNoContent: boolean;\n\n constructor(protected res: RawResponse) {}\n\n summary(): { body: unknown } {\n return {\n body: this.body,\n };\n }\n\n toString(): string {\n return stringify(this.summary());\n }\n}\n\nexport type ActualResponse = AbstractResponse;\n\nexport type ActualRequest = AbstractResponse['req'];\n","import type { AxiosResponse as AxiosResponseType } from 'axios';\nimport AbstractResponse from './AbstractResponse';\n\nexport type RawAxiosResponse = AxiosResponseType;\n\nexport default class AxiosResponse extends AbstractResponse {\n constructor(protected override res: RawAxiosResponse) {\n super(res);\n this.status = res.status;\n this.body = res.data;\n this.req = res.request;\n this.bodyHasNoContent = this.body === '';\n }\n\n getBodyForValidation(): AxiosResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n return this.body;\n }\n}\n","import type { Response, SuperAgentRequest } from 'superagent';\nimport AbstractResponse from './AbstractResponse';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isEmptyObj = (obj: any): obj is Record<string, never> =>\n !!obj && Object.entries(obj).length === 0 && obj.constructor === Object;\n\nexport type RawSuperAgentResponse = Response & {\n req: SuperAgentRequest & { path: string };\n};\n\nexport default class SuperAgentResponse extends AbstractResponse {\n private isResTextPopulatedInsteadOfResBody: boolean;\n\n constructor(protected override res: RawSuperAgentResponse) {\n super(res);\n this.status = res.status;\n this.body = res.body;\n this.req = res.req;\n this.isResTextPopulatedInsteadOfResBody =\n res.text !== '{}' && isEmptyObj(this.body);\n this.bodyHasNoContent = res.text === '';\n }\n\n getBodyForValidation(): SuperAgentResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n if (this.isResTextPopulatedInsteadOfResBody) {\n return this.res.text;\n }\n return this.body;\n }\n\n override summary(): ReturnType<AbstractResponse['summary']> & {\n text?: string;\n } {\n return {\n ...super.summary(),\n ...(this.isResTextPopulatedInsteadOfResBody && { text: this.res.text }),\n };\n }\n}\n","import { RawResponse } from './classes/AbstractResponse';\nimport AxiosResponse from './classes/AxiosResponse';\nimport SuperAgentResponse from './classes/SuperAgentResponse';\n\nexport default function makeResponse(\n res: RawResponse,\n): AxiosResponse | SuperAgentResponse {\n if ('data' in res) {\n return new AxiosResponse(res);\n }\n if ('status' in res) {\n return new SuperAgentResponse(res);\n }\n throw new Error(\n 'Unsupported response object: expected axios, supertest, superagent, or chai-http response shape.',\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAPU,SAAAA;AAAA,GA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I,KAAK,kBAAkB;AACzB,aAAO;AAAA,IACT;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;AChBA,IAAM,aAAa,CAAC,QAClB,CAAC,CAAC,OAAO,OAAO,QAAQ,GAAG,EAAE,WAAW,KAAK,IAAI,gBAAgB;AAMnE,IAAqB,qBAArB,cAAgD,iBAAiB;AAAA,EAG/D,YAA+B,KAA4B;AACzD,UAAM,GAAG;AADoB;AAE7B,SAAK,SAAS,IAAI;AAClB,SAAK,OAAO,IAAI;AAChB,SAAK,MAAM,IAAI;AACf,SAAK,qCACH,IAAI,SAAS,QAAQ,WAAW,KAAK,IAAI;AAC3C,SAAK,mBAAmB,IAAI,SAAS;AAAA,EACvC;AAAA,EAEA,uBAAmD;AACjD,QAAI,KAAK,kBAAkB;AACzB,aAAO;AAAA,IACT;AACA,QAAI,KAAK,oCAAoC;AAC3C,aAAO,KAAK,IAAI;AAAA,IAClB;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAES,UAEP;AACA,WAAO;AAAA,MACL,GAAG,MAAM,QAAQ;AAAA,MACjB,GAAI,KAAK,sCAAsC,EAAE,MAAM,KAAK,IAAI,KAAK;AAAA,IACvE;AAAA,EACF;AACF;;;ACtCe,SAAR,aACL,KACoC;AACpC,MAAI,UAAU,KAAK;AACjB,WAAO,IAAI,cAAc,GAAG;AAAA,EAC9B;AACA,MAAI,YAAY,KAAK;AACnB,WAAO,IAAI,mBAAmB,GAAG;AAAA,EACnC;AACA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":["ErrorCode","url","OpenAPIResponseValidatorModule","_a","path","_a","url","generateCombinations","_a","_a","OpenAPISchemaValidatorModule","typeOf","path","fs","yaml"]}
package/dist/index.mjs CHANGED
@@ -65,7 +65,9 @@ var defaultBasePath = "/";
65
65
  var getPathnameWithoutBasePath = (basePath, pathname) => basePath === defaultBasePath ? pathname : pathname.replace(basePath, "");
66
66
 
67
67
  // lib/classes/AbstractOpenApiSpec.ts
68
- import OpenAPIResponseValidator from "openapi-response-validator";
68
+ import OpenAPIResponseValidatorModule from "openapi-response-validator";
69
+ var _a;
70
+ var OpenAPIResponseValidator = (_a = OpenAPIResponseValidatorModule.default) != null ? _a : OpenAPIResponseValidatorModule;
69
71
  var OpenApiSpec = class {
70
72
  constructor(spec) {
71
73
  this.spec = spec;
@@ -80,8 +82,8 @@ var OpenApiSpec = class {
80
82
  return Object.keys(this.pathsObject());
81
83
  }
82
84
  getSchemaObject(schemaName) {
83
- var _a2;
84
- return (_a2 = this.getSchemaObjects()) == null ? void 0 : _a2[schemaName];
85
+ var _a3;
86
+ return (_a3 = this.getSchemaObjects()) == null ? void 0 : _a3[schemaName];
85
87
  }
86
88
  getExpectedResponse(responseOperation, status) {
87
89
  const response = responseOperation.responses[status];
@@ -207,9 +209,9 @@ var OpenApi2Spec = class extends OpenApiSpec {
207
209
  return openApiPath;
208
210
  }
209
211
  findResponseDefinition(referenceString) {
210
- var _a2;
212
+ var _a3;
211
213
  const nameOfResponseDefinition = referenceString.split("#/responses/")[1];
212
- return (_a2 = this.spec.responses) == null ? void 0 : _a2[nameOfResponseDefinition];
214
+ return (_a3 = this.spec.responses) == null ? void 0 : _a3[nameOfResponseDefinition];
213
215
  }
214
216
  getComponentDefinitionsProperty() {
215
217
  return { definitions: this.spec.definitions };
@@ -331,24 +333,24 @@ var OpenApi3Spec = class extends OpenApiSpec {
331
333
  return openApiPath;
332
334
  }
333
335
  findResponseDefinition(referenceString) {
334
- var _a2, _b;
336
+ var _a3, _b;
335
337
  const nameOfResponseDefinition = referenceString.split(
336
338
  "#/components/responses/"
337
339
  )[1];
338
- return (_b = (_a2 = this.spec.components) == null ? void 0 : _a2.responses) == null ? void 0 : _b[nameOfResponseDefinition];
340
+ return (_b = (_a3 = this.spec.components) == null ? void 0 : _a3.responses) == null ? void 0 : _b[nameOfResponseDefinition];
339
341
  }
340
342
  getComponentDefinitionsProperty() {
341
343
  return { components: this.spec.components };
342
344
  }
343
345
  getSchemaObjects() {
344
- var _a2;
345
- return (_a2 = this.spec.components) == null ? void 0 : _a2.schemas;
346
+ var _a3;
347
+ return (_a3 = this.spec.components) == null ? void 0 : _a3.schemas;
346
348
  }
347
349
  };
348
350
 
349
351
  // lib/openApiSpecFactory.ts
350
- var _a;
351
- var OpenAPISchemaValidator = (_a = OpenAPISchemaValidatorModule.default) != null ? _a : OpenAPISchemaValidatorModule;
352
+ var _a2;
353
+ var OpenAPISchemaValidator = (_a2 = OpenAPISchemaValidatorModule.default) != null ? _a2 : OpenAPISchemaValidatorModule;
352
354
  var isObject = (arg) => typeof arg === "object" && arg !== null && !Array.isArray(arg);
353
355
  function makeApiSpec(filepathOrObject) {
354
356
  const spec = loadSpec(filepathOrObject);
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/classes/errors/ValidationError.ts","../lib/openApiSpecFactory.ts","../lib/utils/common.utils.ts","../lib/classes/AbstractOpenApiSpec.ts","../lib/classes/OpenApi2Spec.ts","../lib/utils/OpenApi3Spec.utils.ts","../lib/classes/OpenApi3Spec.ts","../lib/classes/AbstractResponse.ts","../lib/classes/AxiosResponse.ts","../lib/classes/SuperAgentResponse.ts","../lib/responseFactory.ts"],"sourcesContent":["export enum ErrorCode {\n ServerNotFound,\n BasePathNotFound,\n PathNotFound,\n MethodNotFound,\n StatusNotFound,\n InvalidBody,\n InvalidObject,\n}\n\nexport default class ValidationError extends Error {\n constructor(\n public code: ErrorCode,\n message?: string,\n ) {\n super(message);\n }\n\n override toString(): string {\n return this.message;\n }\n}\n","import fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport OpenAPISchemaValidatorModule from 'openapi-schema-validator';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport path from 'path';\nimport typeOf from 'typeof';\nimport OpenApi2Spec from './classes/OpenApi2Spec';\nimport OpenApi3Spec from './classes/OpenApi3Spec';\nimport { stringify } from './utils/common.utils';\n\n// openapi-schema-validator is a CommonJS module that sets `exports.__esModule = true`\n// and exports the class via `exports.default`. When imported natively as ESM, Node.js\n// exposes the whole `module.exports` object as the default, so we must unwrap `.default`\n// to get the actual constructor. The `??` fallback covers the CJS build context where\n// the bundler (esbuild/__toESM) has already unwrapped it for us.\nconst OpenAPISchemaValidator = (\n (\n OpenAPISchemaValidatorModule as unknown as {\n default?: typeof OpenAPISchemaValidatorModule;\n }\n ).default ?? OpenAPISchemaValidatorModule\n);\n\ntype AnyObject = Record<string, unknown>;\n\nconst isObject = (arg: unknown): arg is AnyObject =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg);\n\nexport default function makeApiSpec(\n filepathOrObject: string | OpenAPI.Document,\n): OpenApi2Spec | OpenApi3Spec {\n const spec = loadSpec(filepathOrObject);\n validateSpec(spec);\n const validSpec = spec as OpenAPI.Document;\n if ('swagger' in validSpec) {\n return new OpenApi2Spec(validSpec);\n }\n return new OpenApi3Spec(validSpec as OpenAPIV3.Document);\n}\n\nfunction loadSpec(arg: unknown): AnyObject {\n try {\n if (typeof arg === 'string') {\n return loadFile(arg);\n }\n if (isObject(arg)) {\n return arg;\n }\n throw new Error(`Received type '${typeOf(arg)}'`);\n } catch (error) {\n throw new Error(\n `The provided argument must be either an absolute filepath or an object representing an OpenAPI specification.\\nError details: ${\n (error as Error).message\n }`,\n );\n }\n}\n\nfunction loadFile(filepath: string): AnyObject {\n if (!path.isAbsolute(filepath)) {\n throw new Error(`'${filepath}' is not an absolute filepath`);\n }\n const fileData = fs.readFileSync(filepath, { encoding: 'utf8' });\n try {\n return yaml.load(fileData) as AnyObject;\n } catch (error) {\n throw new Error(`Invalid YAML or JSON:\\n${(error as Error).message}`);\n }\n}\n\nfunction validateSpec(obj: AnyObject): OpenAPI.Document {\n try {\n const validator = new OpenAPISchemaValidator({\n version:\n (obj as unknown as OpenAPIV2.Document).swagger || // '2.0'\n (obj as unknown as OpenAPIV3.Document).openapi, // '3.X.X'\n });\n const { errors } = validator.validate(obj as OpenAPI.Document);\n if (errors.length > 0) {\n throw new Error(stringify(errors));\n }\n return obj as OpenAPI.Document;\n } catch (error) {\n throw new Error(`Invalid OpenAPI spec: ${(error as Error).message}`);\n }\n}\n","import { Path } from 'path-parser';\nimport url from 'url';\nimport { inspect } from 'util';\nimport type { ActualRequest } from '../classes/AbstractResponse';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { depth: null });\n\n/**\n * Excludes the query because path = pathname + query\n */\nexport const getPathname = (request: ActualRequest): string =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n url.parse(request.path).pathname!;\n\n/**\n * Converts all {foo} to :foo\n */\nconst convertOpenApiPathToColonForm = (openApiPath: string): string =>\n openApiPath.replace(/{/g, ':').replace(/}/g, '');\n\nconst doesColonPathMatchPathname = (\n pathInColonForm: string,\n pathname: string,\n): boolean => {\n /*\n * By default, OpenAPI path parameters have `style: simple; explode: false` (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object)\n * So array path parameters in the pathname of the actual request should be in the form: `/pathParams/a,b,c`\n * `path-parser` fails to match parameter patterns to parameters containing commas.\n * So we remove the commas.\n */\n const pathWithoutCommas = pathname.replace(/,/g, '');\n const pathParamsInPathname = new Path(pathInColonForm).test(\n pathWithoutCommas,\n ); // => one of: null, {}, {exampleParam: 'foo'}\n return Boolean(pathParamsInPathname);\n};\n\nconst doesOpenApiPathMatchPathname = (\n openApiPath: string,\n pathname: string,\n): boolean => {\n const pathInColonForm = convertOpenApiPathToColonForm(openApiPath);\n return doesColonPathMatchPathname(pathInColonForm, pathname);\n};\n\nexport const findOpenApiPathMatchingPossiblePathnames = (\n possiblePathnames: string[],\n OAPaths: string[],\n): string | undefined => {\n let openApiPath: string | undefined;\n // eslint-disable-next-line no-restricted-syntax\n for (const pathname of possiblePathnames) {\n // eslint-disable-next-line no-restricted-syntax\n for (const OAPath of OAPaths) {\n if (OAPath === pathname) {\n return OAPath;\n }\n if (doesOpenApiPathMatchPathname(OAPath, pathname)) {\n openApiPath = OAPath;\n }\n }\n }\n return openApiPath;\n};\n\nexport const defaultBasePath = '/';\n\nexport const getPathnameWithoutBasePath = (\n basePath: string,\n pathname: string,\n): string =>\n basePath === defaultBasePath ? pathname : pathname.replace(basePath, '');\n","import OpenAPIResponseValidator, {\n type OpenAPIResponseValidatorArgs,\n} from 'openapi-response-validator';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { getPathname } from '../utils/common.utils';\nimport type { ActualRequest, ActualResponse } from './AbstractResponse';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\ntype Document = OpenAPIV2.Document | OpenAPIV3.Document;\n\ntype Operation = OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;\n\ntype HttpMethods = OpenAPIV2.HttpMethods;\n\ntype PathItemObject = OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject;\n\nexport type ResponseObjectWithSchema =\n | (OpenAPIV2.ResponseObject & { schema: OpenAPIV2.Schema })\n | (OpenAPIV3.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3.MediaTypeObject & {\n schema: OpenAPIV3.SchemaObject;\n };\n };\n })\n | (OpenAPIV3_1.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3_1.MediaTypeObject & {\n schema: OpenAPIV3_1.SchemaObject;\n };\n };\n });\n\nexport type Schema = OpenAPIV2.Schema | OpenAPIV3.SchemaObject;\n\nexport default abstract class OpenApiSpec {\n protected abstract getSchemaObjects(): Record<string, Schema> | undefined;\n\n protected abstract findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined;\n\n protected abstract findOpenApiPathMatchingPathname(pathname: string): string;\n\n protected abstract getComponentDefinitionsProperty():\n | {\n definitions: OpenAPIV2.Document['definitions'];\n }\n | {\n components: OpenAPIV3.Document['components'];\n };\n\n constructor(protected spec: Document) {}\n\n pathsObject(): Document['paths'] {\n return this.spec.paths;\n }\n\n getPathItem(openApiPath: string): PathItemObject {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.pathsObject()[openApiPath]!;\n }\n\n paths(): string[] {\n return Object.keys(this.pathsObject());\n }\n\n getSchemaObject(schemaName: string): Schema | undefined {\n return this.getSchemaObjects()?.[schemaName];\n }\n\n getExpectedResponse(\n responseOperation: Operation,\n status: ActualResponse['status'],\n ): ResponseObjectWithSchema | undefined {\n const response = responseOperation.responses[status];\n if (!response) {\n return undefined;\n }\n if ('$ref' in response) {\n return this.findResponseDefinition(response.$ref);\n }\n return response as ResponseObjectWithSchema;\n }\n\n findExpectedResponse(\n actualResponse: ActualResponse,\n ): Record<string, ResponseObjectWithSchema> {\n const actualRequest = actualResponse.req;\n const expectedResponseOperation =\n this.findExpectedResponseOperation(actualRequest);\n if (!expectedResponseOperation) {\n throw new ValidationError(ErrorCode.MethodNotFound);\n }\n\n const { status } = actualResponse;\n const expectedResponse = this.getExpectedResponse(\n expectedResponseOperation,\n status,\n );\n if (!expectedResponse) {\n throw new ValidationError(ErrorCode.StatusNotFound);\n }\n\n return { [status]: expectedResponse };\n }\n\n findOpenApiPathMatchingRequest(actualRequest: ActualRequest): string {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n return openApiPath;\n }\n\n findExpectedPathItem(actualRequest: ActualRequest): PathItemObject {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n const pathItemObject = this.getPathItem(openApiPath);\n return pathItemObject;\n }\n\n findExpectedResponseOperation(\n actualRequest: ActualRequest,\n ): Operation | undefined {\n const pathItemObject = this.findExpectedPathItem(actualRequest);\n const operationObject =\n pathItemObject[actualRequest.method.toLowerCase() as HttpMethods];\n return operationObject;\n }\n\n validateResponse(actualResponse: ActualResponse): ValidationError | null {\n let expectedResponse: Record<string, ResponseObjectWithSchema>;\n try {\n expectedResponse = this.findExpectedResponse(actualResponse);\n } catch (error) {\n if (error instanceof ValidationError) {\n return error;\n }\n throw error;\n }\n const validator = new OpenAPIResponseValidator({\n responses: expectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n } as OpenAPIResponseValidatorArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const expectedResStatus = Object.keys(expectedResponse)[0]!;\n const validationError = validator.validateResponse(\n expectedResStatus,\n actualResponse.getBodyForValidation(),\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidBody,\n validationError.errors!\n .map(({ path, message }: { path?: string; message: string }) => `${path} ${message}`)\n .join(', '),\n )\n : null;\n }\n\n /*\n * For consistency and to save maintaining another dependency,\n * we validate objects using our response validator:\n * We put the object inside a mock response, then validate\n * the whole response against a mock expected response.\n * The 2 mock responses are identical except for the body,\n * thus validating the object against its schema.\n */\n validateObject(\n actualObject: unknown,\n schema: Schema,\n ): ValidationError | null {\n const mockResStatus = '200';\n const mockExpectedResponse = { [mockResStatus]: { schema } };\n const validator = new OpenAPIResponseValidator({\n responses: mockExpectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n errorTransformer: ({ path, message }: { path?: string; message: string; errorCode: string }) => ({\n message: `${path!.replace('response', 'object')} ${message}`,\n }),\n } as OpenAPIResponseValidatorArgs);\n const validationError = validator.validateResponse(\n mockResStatus,\n actualObject,\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidObject,\n validationError.errors!.map((error: { message: string }) => error.message).join(', '),\n )\n : null;\n }\n}\n","import type { OpenAPIV2 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n getPathnameWithoutBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n} from '../utils/common.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nconst basePathPropertyNotProvided = (spec: OpenAPIV2.Document): boolean =>\n !spec.basePath;\n\nexport default class OpenApi2Spec extends AbstractOpenApiSpec {\n public didUserDefineBasePath: boolean;\n\n constructor(public override spec: OpenAPIV2.Document) {\n super(spec);\n this.didUserDefineBasePath = !basePathPropertyNotProvided(spec);\n }\n\n /**\n * \"If the basePath property is not provided, the API is served directly under the host\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields\n */\n findOpenApiPathMatchingPathname(pathname: string): string {\n const { basePath } = this.spec;\n if (basePath && !pathname.startsWith(basePath)) {\n throw new ValidationError(ErrorCode.BasePathNotFound);\n }\n const pathnameWithoutBasePath = basePath\n ? getPathnameWithoutBasePath(basePath, pathname)\n : pathname;\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n [pathnameWithoutBasePath],\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split('#/responses/')[1]!;\n return this.spec.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n definitions: OpenAPIV2.Document['definitions'];\n } {\n return { definitions: this.spec.definitions };\n }\n\n getSchemaObjects(): OpenAPIV2.Document['definitions'] {\n return this.spec.definitions;\n }\n}\n","import generateCombinations from 'combos';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport { defaultBasePath } from './common.utils';\n\ntype ServerVariables = OpenAPIV3.ServerObject['variables'];\n\nconst unique = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const serversPropertyNotProvidedOrIsEmptyArray = (\n spec: OpenAPIV3.Document,\n): boolean => !spec.servers || !spec.servers.length;\n\nconst getBasePath = (url: string): string => {\n const basePathStartIndex = url.replace('//', ' ').indexOf('/');\n return basePathStartIndex !== -1\n ? url.slice(basePathStartIndex)\n : defaultBasePath;\n};\n\nconst getPossibleValuesOfServerVariable = ({\n default: defaultValue,\n enum: enumMembers,\n}: OpenAPIV3.ServerVariableObject): string[] =>\n enumMembers ? unique([defaultValue].concat(enumMembers)) : [defaultValue];\n\nconst mapServerVariablesToPossibleValues = (\n serverVariables: NonNullable<ServerVariables>,\n): Record<string, string[]> =>\n Object.entries(serverVariables).reduce(\n (currentMap, [variableName, detailsOfPossibleValues]) => ({\n ...currentMap,\n [variableName]: getPossibleValuesOfServerVariable(\n detailsOfPossibleValues,\n ),\n }),\n {},\n );\n\nconst convertTemplateExpressionToConcreteExpression = (\n templateExpression: string,\n mapOfVariablesToValues: Record<string, string>,\n) =>\n Object.entries(mapOfVariablesToValues).reduce(\n (currentExpression, [variable, value]) =>\n currentExpression.replace(`{${variable}}`, value),\n templateExpression,\n );\n\nconst getPossibleConcreteBasePaths = (\n basePath: string,\n serverVariables: NonNullable<ServerVariables>,\n): string[] => {\n const mapOfServerVariablesToPossibleValues =\n mapServerVariablesToPossibleValues(serverVariables);\n const combinationsOfBasePathVariableValues = generateCombinations(\n mapOfServerVariablesToPossibleValues,\n );\n const possibleBasePaths = combinationsOfBasePathVariableValues.map(\n (mapOfVariablesToValues) =>\n convertTemplateExpressionToConcreteExpression(\n basePath,\n mapOfVariablesToValues,\n ),\n );\n return possibleBasePaths;\n};\n\nconst getPossibleBasePaths = (\n url: string,\n serverVariables: ServerVariables,\n): string[] => {\n const basePath = getBasePath(url);\n return serverVariables\n ? getPossibleConcreteBasePaths(basePath, serverVariables)\n : [basePath];\n};\n\nexport const getMatchingServerUrlsAndServerBasePaths = (\n servers: OpenAPIV3.ServerObject[],\n pathname: string,\n): { concreteUrl: string; matchingBasePath: string }[] => {\n const matchesPathname = (basePath: string): boolean =>\n pathname.startsWith(basePath);\n return servers\n .map(({ url: templatedUrl, variables }) => ({\n templatedUrl,\n possibleBasePaths: getPossibleBasePaths(templatedUrl, variables),\n }))\n .filter(({ possibleBasePaths }) => possibleBasePaths.some(matchesPathname))\n .map(({ templatedUrl, possibleBasePaths }) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const matchingBasePath = possibleBasePaths.find(matchesPathname)!;\n return {\n concreteUrl: templatedUrl.replace(\n getBasePath(templatedUrl),\n matchingBasePath,\n ),\n matchingBasePath,\n };\n });\n};\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n defaultBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n getPathnameWithoutBasePath,\n} from '../utils/common.utils';\nimport {\n serversPropertyNotProvidedOrIsEmptyArray,\n getMatchingServerUrlsAndServerBasePaths,\n} from '../utils/OpenApi3Spec.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nexport default class OpenApi3Spec extends AbstractOpenApiSpec {\n public didUserDefineServers: boolean;\n\n constructor(protected override spec: OpenAPIV3.Document) {\n super(spec);\n this.didUserDefineServers = !serversPropertyNotProvidedOrIsEmptyArray(spec);\n this.ensureDefaultServer();\n }\n\n /**\n * \"If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of '/'\"\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields\n */\n ensureDefaultServer(): void {\n if (serversPropertyNotProvidedOrIsEmptyArray(this.spec)) {\n this.spec.servers = [{ url: defaultBasePath }];\n }\n }\n\n servers(): OpenAPIV3.ServerObject[] {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.spec.servers!;\n }\n\n getServerUrls(): string[] {\n return this.servers().map((server) => server.url);\n }\n\n getMatchingServerUrls(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ concreteUrl }) => concreteUrl);\n }\n\n getMatchingServerBasePaths(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ matchingBasePath }) => matchingBasePath);\n }\n\n findOpenApiPathMatchingPathname(pathname: string): string {\n const matchingServerBasePaths = this.getMatchingServerBasePaths(pathname);\n if (!matchingServerBasePaths.length) {\n throw new ValidationError(ErrorCode.ServerNotFound);\n }\n const possiblePathnames = matchingServerBasePaths.map((basePath) =>\n getPathnameWithoutBasePath(basePath, pathname),\n );\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n possiblePathnames,\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split(\n '#/components/responses/',\n )[1]!;\n return this.spec.components?.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n components: OpenAPIV3.Document['components'];\n } {\n return { components: this.spec.components };\n }\n\n getSchemaObjects(): OpenAPIV3.ComponentsObject['schemas'] {\n return this.spec.components?.schemas;\n }\n}\n","import { stringify } from '../utils/common.utils';\nimport type { RawAxiosResponse } from './AxiosResponse';\nimport type { RawSuperAgentResponse } from './SuperAgentResponse';\n\nexport type RawResponse =\n | RawAxiosResponse\n | RawSuperAgentResponse;\n\nexport default abstract class AbstractResponse {\n declare public status: number;\n\n declare public req: { method: string; path: string };\n\n public abstract getBodyForValidation(): unknown;\n\n protected body: unknown;\n\n declare protected bodyHasNoContent: boolean;\n\n constructor(protected res: RawResponse) {}\n\n summary(): { body: unknown } {\n return {\n body: this.body,\n };\n }\n\n toString(): string {\n return stringify(this.summary());\n }\n}\n\nexport type ActualResponse = AbstractResponse;\n\nexport type ActualRequest = AbstractResponse['req'];\n","import type { AxiosResponse as AxiosResponseType } from 'axios';\nimport AbstractResponse from './AbstractResponse';\n\nexport type RawAxiosResponse = AxiosResponseType;\n\nexport default class AxiosResponse extends AbstractResponse {\n constructor(protected override res: RawAxiosResponse) {\n super(res);\n this.status = res.status;\n this.body = res.data;\n this.req = res.request;\n this.bodyHasNoContent = this.body === '';\n }\n\n getBodyForValidation(): AxiosResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n return this.body;\n }\n}\n","import type { Response, SuperAgentRequest } from 'superagent';\nimport AbstractResponse from './AbstractResponse';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isEmptyObj = (obj: any): obj is Record<string, never> =>\n !!obj && Object.entries(obj).length === 0 && obj.constructor === Object;\n\nexport type RawSuperAgentResponse = Response & {\n req: SuperAgentRequest & { path: string };\n};\n\nexport default class SuperAgentResponse extends AbstractResponse {\n private isResTextPopulatedInsteadOfResBody: boolean;\n\n constructor(protected override res: RawSuperAgentResponse) {\n super(res);\n this.status = res.status;\n this.body = res.body;\n this.req = res.req;\n this.isResTextPopulatedInsteadOfResBody =\n res.text !== '{}' && isEmptyObj(this.body);\n this.bodyHasNoContent = res.text === '';\n }\n\n getBodyForValidation(): SuperAgentResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n if (this.isResTextPopulatedInsteadOfResBody) {\n return this.res.text;\n }\n return this.body;\n }\n\n override summary(): ReturnType<AbstractResponse['summary']> & {\n text?: string;\n } {\n return {\n ...super.summary(),\n ...(this.isResTextPopulatedInsteadOfResBody && { text: this.res.text }),\n };\n }\n}\n","import { RawResponse } from './classes/AbstractResponse';\nimport AxiosResponse from './classes/AxiosResponse';\nimport SuperAgentResponse from './classes/SuperAgentResponse';\n\nexport default function makeResponse(\n res: RawResponse,\n): AxiosResponse | SuperAgentResponse {\n if ('data' in res) {\n return new AxiosResponse(res);\n }\n if ('status' in res) {\n return new SuperAgentResponse(res);\n }\n throw new Error(\n 'Unsupported response object: expected axios, supertest, superagent, or chai-http response shape.',\n );\n}\n"],"mappings":";AAAO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sB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;AChBA,IAAM,aAAa,CAAC,QAClB,CAAC,CAAC,OAAO,OAAO,QAAQ,GAAG,EAAE,WAAW,KAAK,IAAI,gBAAgB;AAMnE,IAAqB,qBAArB,cAAgD,iBAAiB;AAAA,EAG/D,YAA+B,KAA4B;AACzD,UAAM,GAAG;AADoB;AAE7B,SAAK,SAAS,IAAI;AAClB,SAAK,OAAO,IAAI;AAChB,SAAK,MAAM,IAAI;AACf,SAAK,qCACH,IAAI,SAAS,QAAQ,WAAW,KAAK,IAAI;AAC3C,SAAK,mBAAmB,IAAI,SAAS;AAAA,EACvC;AAAA,EAEA,uBAAmD;AACjD,QAAI,KAAK,kBAAkB;AACzB,aAAO;AAAA,IACT;AACA,QAAI,KAAK,oCAAoC;AAC3C,aAAO,KAAK,IAAI;AAAA,IAClB;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAES,UAEP;AACA,WAAO;AAAA,MACL,GAAG,MAAM,QAAQ;AAAA,MACjB,GAAI,KAAK,sCAAsC,EAAE,MAAM,KAAK,IAAI,KAAK;AAAA,IACvE;AAAA,EACF;AACF;;;ACtCe,SAAR,aACL,KACoC;AACpC,MAAI,UAAU,KAAK;AACjB,WAAO,IAAI,cAAc,GAAG;AAAA,EAC9B;AACA,MAAI,YAAY,KAAK;AACnB,WAAO,IAAI,mBAAmB,GAAG;AAAA,EACnC;AACA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":["ErrorCode","_a","path","_a","url","_a"]}
1
+ {"version":3,"sources":["../lib/classes/errors/ValidationError.ts","../lib/openApiSpecFactory.ts","../lib/utils/common.utils.ts","../lib/classes/AbstractOpenApiSpec.ts","../lib/classes/OpenApi2Spec.ts","../lib/utils/OpenApi3Spec.utils.ts","../lib/classes/OpenApi3Spec.ts","../lib/classes/AbstractResponse.ts","../lib/classes/AxiosResponse.ts","../lib/classes/SuperAgentResponse.ts","../lib/responseFactory.ts"],"sourcesContent":["export enum ErrorCode {\n ServerNotFound,\n BasePathNotFound,\n PathNotFound,\n MethodNotFound,\n StatusNotFound,\n InvalidBody,\n InvalidObject,\n}\n\nexport default class ValidationError extends Error {\n constructor(\n public code: ErrorCode,\n message?: string,\n ) {\n super(message);\n }\n\n override toString(): string {\n return this.message;\n }\n}\n","import fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport OpenAPISchemaValidatorModule from 'openapi-schema-validator';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport path from 'path';\nimport typeOf from 'typeof';\nimport OpenApi2Spec from './classes/OpenApi2Spec';\nimport OpenApi3Spec from './classes/OpenApi3Spec';\nimport { stringify } from './utils/common.utils';\n\n// openapi-schema-validator is a CommonJS module that sets `exports.__esModule = true`\n// and exports the class via `exports.default`. When imported natively as ESM, Node.js\n// exposes the whole `module.exports` object as the default, so we must unwrap `.default`\n// to get the actual constructor. The `??` fallback covers the CJS build context where\n// the bundler (esbuild/__toESM) has already unwrapped it for us.\nconst OpenAPISchemaValidator = (\n (\n OpenAPISchemaValidatorModule as unknown as {\n default?: typeof OpenAPISchemaValidatorModule;\n }\n ).default ?? OpenAPISchemaValidatorModule\n);\n\ntype AnyObject = Record<string, unknown>;\n\nconst isObject = (arg: unknown): arg is AnyObject =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg);\n\nexport default function makeApiSpec(\n filepathOrObject: string | OpenAPI.Document,\n): OpenApi2Spec | OpenApi3Spec {\n const spec = loadSpec(filepathOrObject);\n validateSpec(spec);\n const validSpec = spec as OpenAPI.Document;\n if ('swagger' in validSpec) {\n return new OpenApi2Spec(validSpec);\n }\n return new OpenApi3Spec(validSpec as OpenAPIV3.Document);\n}\n\nfunction loadSpec(arg: unknown): AnyObject {\n try {\n if (typeof arg === 'string') {\n return loadFile(arg);\n }\n if (isObject(arg)) {\n return arg;\n }\n throw new Error(`Received type '${typeOf(arg)}'`);\n } catch (error) {\n throw new Error(\n `The provided argument must be either an absolute filepath or an object representing an OpenAPI specification.\\nError details: ${\n (error as Error).message\n }`,\n );\n }\n}\n\nfunction loadFile(filepath: string): AnyObject {\n if (!path.isAbsolute(filepath)) {\n throw new Error(`'${filepath}' is not an absolute filepath`);\n }\n const fileData = fs.readFileSync(filepath, { encoding: 'utf8' });\n try {\n return yaml.load(fileData) as AnyObject;\n } catch (error) {\n throw new Error(`Invalid YAML or JSON:\\n${(error as Error).message}`);\n }\n}\n\nfunction validateSpec(obj: AnyObject): OpenAPI.Document {\n try {\n const validator = new OpenAPISchemaValidator({\n version:\n (obj as unknown as OpenAPIV2.Document).swagger || // '2.0'\n (obj as unknown as OpenAPIV3.Document).openapi, // '3.X.X'\n });\n const { errors } = validator.validate(obj as OpenAPI.Document);\n if (errors.length > 0) {\n throw new Error(stringify(errors));\n }\n return obj as OpenAPI.Document;\n } catch (error) {\n throw new Error(`Invalid OpenAPI spec: ${(error as Error).message}`);\n }\n}\n","import { Path } from 'path-parser';\nimport url from 'url';\nimport { inspect } from 'util';\nimport type { ActualRequest } from '../classes/AbstractResponse';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { depth: null });\n\n/**\n * Excludes the query because path = pathname + query\n */\nexport const getPathname = (request: ActualRequest): string =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n url.parse(request.path).pathname!;\n\n/**\n * Converts all {foo} to :foo\n */\nconst convertOpenApiPathToColonForm = (openApiPath: string): string =>\n openApiPath.replace(/{/g, ':').replace(/}/g, '');\n\nconst doesColonPathMatchPathname = (\n pathInColonForm: string,\n pathname: string,\n): boolean => {\n /*\n * By default, OpenAPI path parameters have `style: simple; explode: false` (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object)\n * So array path parameters in the pathname of the actual request should be in the form: `/pathParams/a,b,c`\n * `path-parser` fails to match parameter patterns to parameters containing commas.\n * So we remove the commas.\n */\n const pathWithoutCommas = pathname.replace(/,/g, '');\n const pathParamsInPathname = new Path(pathInColonForm).test(\n pathWithoutCommas,\n ); // => one of: null, {}, {exampleParam: 'foo'}\n return Boolean(pathParamsInPathname);\n};\n\nconst doesOpenApiPathMatchPathname = (\n openApiPath: string,\n pathname: string,\n): boolean => {\n const pathInColonForm = convertOpenApiPathToColonForm(openApiPath);\n return doesColonPathMatchPathname(pathInColonForm, pathname);\n};\n\nexport const findOpenApiPathMatchingPossiblePathnames = (\n possiblePathnames: string[],\n OAPaths: string[],\n): string | undefined => {\n let openApiPath: string | undefined;\n // eslint-disable-next-line no-restricted-syntax\n for (const pathname of possiblePathnames) {\n // eslint-disable-next-line no-restricted-syntax\n for (const OAPath of OAPaths) {\n if (OAPath === pathname) {\n return OAPath;\n }\n if (doesOpenApiPathMatchPathname(OAPath, pathname)) {\n openApiPath = OAPath;\n }\n }\n }\n return openApiPath;\n};\n\nexport const defaultBasePath = '/';\n\nexport const getPathnameWithoutBasePath = (\n basePath: string,\n pathname: string,\n): string =>\n basePath === defaultBasePath ? pathname : pathname.replace(basePath, '');\n","import OpenAPIResponseValidatorModule, {\n type OpenAPIResponseValidatorArgs,\n} from 'openapi-response-validator';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { getPathname } from '../utils/common.utils';\nimport type { ActualRequest, ActualResponse } from './AbstractResponse';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\ntype Document = OpenAPIV2.Document | OpenAPIV3.Document;\n\ntype Operation = OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;\n\ntype HttpMethods = OpenAPIV2.HttpMethods;\n\ntype PathItemObject = OpenAPIV2.PathItemObject | OpenAPIV3.PathItemObject;\n\nconst OpenAPIResponseValidator = (\n OpenAPIResponseValidatorModule as unknown as {\n default?: typeof OpenAPIResponseValidatorModule;\n }\n).default ?? OpenAPIResponseValidatorModule;\n\nexport type ResponseObjectWithSchema =\n | (OpenAPIV2.ResponseObject & { schema: OpenAPIV2.Schema })\n | (OpenAPIV3.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3.MediaTypeObject & {\n schema: OpenAPIV3.SchemaObject;\n };\n };\n })\n | (OpenAPIV3_1.ResponseObject & {\n content: {\n [media: string]: OpenAPIV3_1.MediaTypeObject & {\n schema: OpenAPIV3_1.SchemaObject;\n };\n };\n });\n\nexport type Schema = OpenAPIV2.Schema | OpenAPIV3.SchemaObject;\n\nexport default abstract class OpenApiSpec {\n protected abstract getSchemaObjects(): Record<string, Schema> | undefined;\n\n protected abstract findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined;\n\n protected abstract findOpenApiPathMatchingPathname(pathname: string): string;\n\n protected abstract getComponentDefinitionsProperty():\n | {\n definitions: OpenAPIV2.Document['definitions'];\n }\n | {\n components: OpenAPIV3.Document['components'];\n };\n\n constructor(protected spec: Document) {}\n\n pathsObject(): Document['paths'] {\n return this.spec.paths;\n }\n\n getPathItem(openApiPath: string): PathItemObject {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.pathsObject()[openApiPath]!;\n }\n\n paths(): string[] {\n return Object.keys(this.pathsObject());\n }\n\n getSchemaObject(schemaName: string): Schema | undefined {\n return this.getSchemaObjects()?.[schemaName];\n }\n\n getExpectedResponse(\n responseOperation: Operation,\n status: ActualResponse['status'],\n ): ResponseObjectWithSchema | undefined {\n const response = responseOperation.responses[status];\n if (!response) {\n return undefined;\n }\n if ('$ref' in response) {\n return this.findResponseDefinition(response.$ref);\n }\n return response as ResponseObjectWithSchema;\n }\n\n findExpectedResponse(\n actualResponse: ActualResponse,\n ): Record<string, ResponseObjectWithSchema> {\n const actualRequest = actualResponse.req;\n const expectedResponseOperation =\n this.findExpectedResponseOperation(actualRequest);\n if (!expectedResponseOperation) {\n throw new ValidationError(ErrorCode.MethodNotFound);\n }\n\n const { status } = actualResponse;\n const expectedResponse = this.getExpectedResponse(\n expectedResponseOperation,\n status,\n );\n if (!expectedResponse) {\n throw new ValidationError(ErrorCode.StatusNotFound);\n }\n\n return { [status]: expectedResponse };\n }\n\n findOpenApiPathMatchingRequest(actualRequest: ActualRequest): string {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n return openApiPath;\n }\n\n findExpectedPathItem(actualRequest: ActualRequest): PathItemObject {\n const actualPathname = getPathname(actualRequest);\n const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname);\n const pathItemObject = this.getPathItem(openApiPath);\n return pathItemObject;\n }\n\n findExpectedResponseOperation(\n actualRequest: ActualRequest,\n ): Operation | undefined {\n const pathItemObject = this.findExpectedPathItem(actualRequest);\n const operationObject =\n pathItemObject[actualRequest.method.toLowerCase() as HttpMethods];\n return operationObject;\n }\n\n validateResponse(actualResponse: ActualResponse): ValidationError | null {\n let expectedResponse: Record<string, ResponseObjectWithSchema>;\n try {\n expectedResponse = this.findExpectedResponse(actualResponse);\n } catch (error) {\n if (error instanceof ValidationError) {\n return error;\n }\n throw error;\n }\n const validator = new OpenAPIResponseValidator({\n responses: expectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n } as OpenAPIResponseValidatorArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const expectedResStatus = Object.keys(expectedResponse)[0]!;\n const validationError = validator.validateResponse(\n expectedResStatus,\n actualResponse.getBodyForValidation(),\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidBody,\n validationError.errors!\n .map(({ path, message }: { path?: string; message: string }) => `${path} ${message}`)\n .join(', '),\n )\n : null;\n }\n\n /*\n * For consistency and to save maintaining another dependency,\n * we validate objects using our response validator:\n * We put the object inside a mock response, then validate\n * the whole response against a mock expected response.\n * The 2 mock responses are identical except for the body,\n * thus validating the object against its schema.\n */\n validateObject(\n actualObject: unknown,\n schema: Schema,\n ): ValidationError | null {\n const mockResStatus = '200';\n const mockExpectedResponse = { [mockResStatus]: { schema } };\n const validator = new OpenAPIResponseValidator({\n responses: mockExpectedResponse as OpenAPIResponseValidatorArgs['responses'],\n ...this.getComponentDefinitionsProperty(),\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n errorTransformer: ({ path, message }: { path?: string; message: string; errorCode: string }) => ({\n message: `${path!.replace('response', 'object')} ${message}`,\n }),\n } as OpenAPIResponseValidatorArgs);\n const validationError = validator.validateResponse(\n mockResStatus,\n actualObject,\n );\n return validationError\n ? new ValidationError(\n ErrorCode.InvalidObject,\n validationError.errors!.map((error: { message: string }) => error.message).join(', '),\n )\n : null;\n }\n}\n","import type { OpenAPIV2 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n getPathnameWithoutBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n} from '../utils/common.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nconst basePathPropertyNotProvided = (spec: OpenAPIV2.Document): boolean =>\n !spec.basePath;\n\nexport default class OpenApi2Spec extends AbstractOpenApiSpec {\n public didUserDefineBasePath: boolean;\n\n constructor(public override spec: OpenAPIV2.Document) {\n super(spec);\n this.didUserDefineBasePath = !basePathPropertyNotProvided(spec);\n }\n\n /**\n * \"If the basePath property is not provided, the API is served directly under the host\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields\n */\n findOpenApiPathMatchingPathname(pathname: string): string {\n const { basePath } = this.spec;\n if (basePath && !pathname.startsWith(basePath)) {\n throw new ValidationError(ErrorCode.BasePathNotFound);\n }\n const pathnameWithoutBasePath = basePath\n ? getPathnameWithoutBasePath(basePath, pathname)\n : pathname;\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n [pathnameWithoutBasePath],\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split('#/responses/')[1]!;\n return this.spec.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n definitions: OpenAPIV2.Document['definitions'];\n } {\n return { definitions: this.spec.definitions };\n }\n\n getSchemaObjects(): OpenAPIV2.Document['definitions'] {\n return this.spec.definitions;\n }\n}\n","import generateCombinations from 'combos';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport { defaultBasePath } from './common.utils';\n\ntype ServerVariables = OpenAPIV3.ServerObject['variables'];\n\nconst unique = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const serversPropertyNotProvidedOrIsEmptyArray = (\n spec: OpenAPIV3.Document,\n): boolean => !spec.servers || !spec.servers.length;\n\nconst getBasePath = (url: string): string => {\n const basePathStartIndex = url.replace('//', ' ').indexOf('/');\n return basePathStartIndex !== -1\n ? url.slice(basePathStartIndex)\n : defaultBasePath;\n};\n\nconst getPossibleValuesOfServerVariable = ({\n default: defaultValue,\n enum: enumMembers,\n}: OpenAPIV3.ServerVariableObject): string[] =>\n enumMembers ? unique([defaultValue].concat(enumMembers)) : [defaultValue];\n\nconst mapServerVariablesToPossibleValues = (\n serverVariables: NonNullable<ServerVariables>,\n): Record<string, string[]> =>\n Object.entries(serverVariables).reduce(\n (currentMap, [variableName, detailsOfPossibleValues]) => ({\n ...currentMap,\n [variableName]: getPossibleValuesOfServerVariable(\n detailsOfPossibleValues,\n ),\n }),\n {},\n );\n\nconst convertTemplateExpressionToConcreteExpression = (\n templateExpression: string,\n mapOfVariablesToValues: Record<string, string>,\n) =>\n Object.entries(mapOfVariablesToValues).reduce(\n (currentExpression, [variable, value]) =>\n currentExpression.replace(`{${variable}}`, value),\n templateExpression,\n );\n\nconst getPossibleConcreteBasePaths = (\n basePath: string,\n serverVariables: NonNullable<ServerVariables>,\n): string[] => {\n const mapOfServerVariablesToPossibleValues =\n mapServerVariablesToPossibleValues(serverVariables);\n const combinationsOfBasePathVariableValues = generateCombinations(\n mapOfServerVariablesToPossibleValues,\n );\n const possibleBasePaths = combinationsOfBasePathVariableValues.map(\n (mapOfVariablesToValues) =>\n convertTemplateExpressionToConcreteExpression(\n basePath,\n mapOfVariablesToValues,\n ),\n );\n return possibleBasePaths;\n};\n\nconst getPossibleBasePaths = (\n url: string,\n serverVariables: ServerVariables,\n): string[] => {\n const basePath = getBasePath(url);\n return serverVariables\n ? getPossibleConcreteBasePaths(basePath, serverVariables)\n : [basePath];\n};\n\nexport const getMatchingServerUrlsAndServerBasePaths = (\n servers: OpenAPIV3.ServerObject[],\n pathname: string,\n): { concreteUrl: string; matchingBasePath: string }[] => {\n const matchesPathname = (basePath: string): boolean =>\n pathname.startsWith(basePath);\n return servers\n .map(({ url: templatedUrl, variables }) => ({\n templatedUrl,\n possibleBasePaths: getPossibleBasePaths(templatedUrl, variables),\n }))\n .filter(({ possibleBasePaths }) => possibleBasePaths.some(matchesPathname))\n .map(({ templatedUrl, possibleBasePaths }) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const matchingBasePath = possibleBasePaths.find(matchesPathname)!;\n return {\n concreteUrl: templatedUrl.replace(\n getBasePath(templatedUrl),\n matchingBasePath,\n ),\n matchingBasePath,\n };\n });\n};\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { ResponseObjectWithSchema } from './AbstractOpenApiSpec';\nimport {\n defaultBasePath,\n findOpenApiPathMatchingPossiblePathnames,\n getPathnameWithoutBasePath,\n} from '../utils/common.utils';\nimport {\n serversPropertyNotProvidedOrIsEmptyArray,\n getMatchingServerUrlsAndServerBasePaths,\n} from '../utils/OpenApi3Spec.utils';\nimport AbstractOpenApiSpec from './AbstractOpenApiSpec';\nimport ValidationError, { ErrorCode } from './errors/ValidationError';\n\nexport default class OpenApi3Spec extends AbstractOpenApiSpec {\n public didUserDefineServers: boolean;\n\n constructor(protected override spec: OpenAPIV3.Document) {\n super(spec);\n this.didUserDefineServers = !serversPropertyNotProvidedOrIsEmptyArray(spec);\n this.ensureDefaultServer();\n }\n\n /**\n * \"If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of '/'\"\n * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields\n */\n ensureDefaultServer(): void {\n if (serversPropertyNotProvidedOrIsEmptyArray(this.spec)) {\n this.spec.servers = [{ url: defaultBasePath }];\n }\n }\n\n servers(): OpenAPIV3.ServerObject[] {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.spec.servers!;\n }\n\n getServerUrls(): string[] {\n return this.servers().map((server) => server.url);\n }\n\n getMatchingServerUrls(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ concreteUrl }) => concreteUrl);\n }\n\n getMatchingServerBasePaths(pathname: string): string[] {\n return getMatchingServerUrlsAndServerBasePaths(\n this.servers(),\n pathname,\n ).map(({ matchingBasePath }) => matchingBasePath);\n }\n\n findOpenApiPathMatchingPathname(pathname: string): string {\n const matchingServerBasePaths = this.getMatchingServerBasePaths(pathname);\n if (!matchingServerBasePaths.length) {\n throw new ValidationError(ErrorCode.ServerNotFound);\n }\n const possiblePathnames = matchingServerBasePaths.map((basePath) =>\n getPathnameWithoutBasePath(basePath, pathname),\n );\n const openApiPath = findOpenApiPathMatchingPossiblePathnames(\n possiblePathnames,\n this.paths(),\n );\n if (!openApiPath) {\n throw new ValidationError(ErrorCode.PathNotFound);\n }\n return openApiPath;\n }\n\n findResponseDefinition(\n referenceString: string,\n ): ResponseObjectWithSchema | undefined {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nameOfResponseDefinition = referenceString.split(\n '#/components/responses/',\n )[1]!;\n return this.spec.components?.responses?.[nameOfResponseDefinition] as\n | ResponseObjectWithSchema\n | undefined;\n }\n\n getComponentDefinitionsProperty(): {\n components: OpenAPIV3.Document['components'];\n } {\n return { components: this.spec.components };\n }\n\n getSchemaObjects(): OpenAPIV3.ComponentsObject['schemas'] {\n return this.spec.components?.schemas;\n }\n}\n","import { stringify } from '../utils/common.utils';\nimport type { RawAxiosResponse } from './AxiosResponse';\nimport type { RawSuperAgentResponse } from './SuperAgentResponse';\n\nexport type RawResponse =\n | RawAxiosResponse\n | RawSuperAgentResponse;\n\nexport default abstract class AbstractResponse {\n declare public status: number;\n\n declare public req: { method: string; path: string };\n\n public abstract getBodyForValidation(): unknown;\n\n protected body: unknown;\n\n declare protected bodyHasNoContent: boolean;\n\n constructor(protected res: RawResponse) {}\n\n summary(): { body: unknown } {\n return {\n body: this.body,\n };\n }\n\n toString(): string {\n return stringify(this.summary());\n }\n}\n\nexport type ActualResponse = AbstractResponse;\n\nexport type ActualRequest = AbstractResponse['req'];\n","import type { AxiosResponse as AxiosResponseType } from 'axios';\nimport AbstractResponse from './AbstractResponse';\n\nexport type RawAxiosResponse = AxiosResponseType;\n\nexport default class AxiosResponse extends AbstractResponse {\n constructor(protected override res: RawAxiosResponse) {\n super(res);\n this.status = res.status;\n this.body = res.data;\n this.req = res.request;\n this.bodyHasNoContent = this.body === '';\n }\n\n getBodyForValidation(): AxiosResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n return this.body;\n }\n}\n","import type { Response, SuperAgentRequest } from 'superagent';\nimport AbstractResponse from './AbstractResponse';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isEmptyObj = (obj: any): obj is Record<string, never> =>\n !!obj && Object.entries(obj).length === 0 && obj.constructor === Object;\n\nexport type RawSuperAgentResponse = Response & {\n req: SuperAgentRequest & { path: string };\n};\n\nexport default class SuperAgentResponse extends AbstractResponse {\n private isResTextPopulatedInsteadOfResBody: boolean;\n\n constructor(protected override res: RawSuperAgentResponse) {\n super(res);\n this.status = res.status;\n this.body = res.body;\n this.req = res.req;\n this.isResTextPopulatedInsteadOfResBody =\n res.text !== '{}' && isEmptyObj(this.body);\n this.bodyHasNoContent = res.text === '';\n }\n\n getBodyForValidation(): SuperAgentResponse['body'] {\n if (this.bodyHasNoContent) {\n return null;\n }\n if (this.isResTextPopulatedInsteadOfResBody) {\n return this.res.text;\n }\n return this.body;\n }\n\n override summary(): ReturnType<AbstractResponse['summary']> & {\n text?: string;\n } {\n return {\n ...super.summary(),\n ...(this.isResTextPopulatedInsteadOfResBody && { text: this.res.text }),\n };\n }\n}\n","import { RawResponse } from './classes/AbstractResponse';\nimport AxiosResponse from './classes/AxiosResponse';\nimport SuperAgentResponse from './classes/SuperAgentResponse';\n\nexport default function makeResponse(\n res: RawResponse,\n): AxiosResponse | SuperAgentResponse {\n if ('data' in res) {\n return new AxiosResponse(res);\n }\n if ('status' in res) {\n return new SuperAgentResponse(res);\n }\n throw new Error(\n 'Unsupported response object: expected axios, supertest, superagent, or chai-http response shape.',\n );\n}\n"],"mappings":";AAAO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAPU,SAAAA;AAAA,GAAA;AAUZ,IAAqB,kBAArB,cAA6C,MAAM;AAAA,EACjD,YACS,MACP,SACA;AACA,UAAM,OAAO;AAHN;AAAA,EAIT;AAAA,EAES,WAAmB;AAC1B,WAAO,KAAK;AAAA,EACd;AACF;;;ACrBA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,kCAAkC;AAEzC,OAAO,UAAU;AACjB,OAAO,YAAY;;;ACLnB,SAAS,YAAY;AACrB,OAAO,SAAS;AAChB,SAAS,eAAe;AAGjB,IAAM,YAAY,CAAC,QACxB,QAAQ,KAAK,EAAE,OAAO,KAAK,CAAC;AAKvB,IAAM,cAAc,CAAC;AAAA;AAAA,EAE1B,IAAI,MAAM,QAAQ,IAAI,EAAE;AAAA;AAK1B,IAAM,gCAAgC,CAAC,gBACrC,YAAY,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,EAAE;AAEjD,IAAM,6BAA6B,CACjC,iBACA,aACY;AAOZ,QAAM,oBAAoB,SAAS,QAAQ,MAAM,EAAE;AACnD,QAAM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KAAK,sCAAsC,EAAE,MAAM,KAAK,IAAI,KAAK;AAAA,IACvE;AAAA,EACF;AACF;;;ACtCe,SAAR,aACL,KACoC;AACpC,MAAI,UAAU,KAAK;AACjB,WAAO,IAAI,cAAc,GAAG;AAAA,EAC9B;AACA,MAAI,YAAY,KAAK;AACnB,WAAO,IAAI,mBAAmB,GAAG;AAAA,EACnC;AACA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":["ErrorCode","_a","path","_a","url","_a","_a"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ehuelsmann/openapi-validator",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "Common code for jest-openapi and Chai OpenAPI Response Validator",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",