@ehuelsmann/chai-openapi-response-validator 0.16.3 → 0.17.0
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 +1 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -108,10 +108,7 @@ function getExpectedResToSatisfyApiSpecMsg(actualResponse, openApiSpec, validati
|
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
if (validationError.code === import_openapi_validator.ErrorCode.StatusNotFound) {
|
|
111
|
-
const expectedResponseOperation = (
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
113
|
-
openApiSpec.findExpectedResponseOperation(req)
|
|
114
|
-
);
|
|
111
|
+
const expectedResponseOperation = openApiSpec.findExpectedResponseOperation(req);
|
|
115
112
|
const expectedResponseStatuses = Object.keys(
|
|
116
113
|
expectedResponseOperation.responses
|
|
117
114
|
).join(", ");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/index.ts","../lib/assertions/satisfyApiSpec.ts","../lib/utils.ts","../lib/assertions/satisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport satisfyApiSpec from './assertions/satisfyApiSpec';\nimport satisfySchemaInApiSpec from './assertions/satisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n satisfyApiSpec: Assertion;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n satisfySchemaInApiSpec(schemaName: string): Assertion;\n }\n }\n}\n\nexport default function (\n filepathOrObject: string | OpenAPISpecObject,\n): Chai.ChaiPlugin {\n const openApiSpec = makeApiSpec(filepathOrObject);\n return function (chai) {\n satisfyApiSpec(chai, openApiSpec);\n satisfySchemaInApiSpec(chai, openApiSpec);\n };\n}\n","import {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion } = chai;\n\n Assertion.addProperty('satisfyApiSpec', function () {\n const actualResponse = makeResponse(this._obj); // eslint-disable-line no-underscore-dangle\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectedResToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n ),\n pass\n ? getExpectedResNotToSatisfyApiSpecMsg(actualResponse, openApiSpec)\n : '',\n null,\n );\n });\n}\n\nfunction getExpectedResToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n): string {\n const hint = 'expected res to satisfy API spec';\n\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching servers`,\n `Servers found in API spec: ${(openApiSpec as OpenApi3Spec)\n .getServerUrls()\n .join(', ')}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has basePath '${\n (openApiSpec as OpenApi2Spec).spec.basePath\n }'`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching path`,\n `Paths found in API spec: ${openApiSpec.paths().join(', ')}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had request method '${method}', but your API spec has no '${method}' operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${expectedRequestOperations}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had status '${status}', but your API spec has no '${status}' response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${expectedResponseStatuses}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n return joinWithNewLines(\n hint,\n `expected res to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res did not satisfy it because: ${validationError}`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n\nfunction getExpectedResNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n return joinWithNewLines(\n `expected res not to satisfy API spec`,\n `expected res not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { stringify, joinWithNewLines } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion, AssertionError } = chai;\n\n Assertion.addMethod('satisfySchemaInApiSpec', function (schemaName) {\n const actualObject = this._obj; // eslint-disable-line no-underscore-dangle\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new AssertionError(\n 'The argument to satisfySchemaInApiSpec must match a schema in your API spec',\n );\n }\n\n const validationError = openApiSpec.validateObject(actualObject, schema);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectReceivedToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n validationError,\n ),\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n ),\n null,\n );\n });\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n) {\n return joinWithNewLines(\n `expected object to satisfy the '${schemaName}' schema defined in your API spec`,\n `object did not satisfy it because: ${validationError}`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n) {\n return joinWithNewLines(\n `expected object not to satisfy the '${schemaName}' schema defined in your API spec`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAA+C;;;ACA/C,+BAQO;;;ACRP,kBAAwB;AAEjB,IAAM,YAAY,CAAC,YACxB,qBAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADKJ,SAAR,uBACL,MACA,aACM;AACN,QAAM,EAAE,UAAU,IAAI;AAEtB,YAAU,YAAY,kBAAkB,WAAY;AAClD,UAAM,qBAAiB,uCAAa,KAAK,IAAI;AAE7C,UAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,UAAM,OAAO,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kBAAc,uCAAY,gBAAgB;AAChD,SAAO,SAAU,MAAM;AACrB,2BAAe,MAAM,WAAW;AAChC,mCAAuB,MAAM,WAAW;AAAA,EAC1C;AACF;","names":["import_openapi_validator"]}
|
|
1
|
+
{"version":3,"sources":["../lib/index.ts","../lib/assertions/satisfyApiSpec.ts","../lib/utils.ts","../lib/assertions/satisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport satisfyApiSpec from './assertions/satisfyApiSpec';\nimport satisfySchemaInApiSpec from './assertions/satisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n satisfyApiSpec: Assertion;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n satisfySchemaInApiSpec(schemaName: string): Assertion;\n }\n }\n}\n\nexport default function (\n filepathOrObject: string | OpenAPISpecObject,\n): Chai.ChaiPlugin {\n const openApiSpec = makeApiSpec(filepathOrObject);\n return function (chai) {\n satisfyApiSpec(chai, openApiSpec);\n satisfySchemaInApiSpec(chai, openApiSpec);\n };\n}\n","import {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion } = chai;\n\n Assertion.addProperty('satisfyApiSpec', function () {\n const actualResponse = makeResponse(this._obj); // eslint-disable-line no-underscore-dangle\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectedResToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n ),\n pass\n ? getExpectedResNotToSatisfyApiSpecMsg(actualResponse, openApiSpec)\n : '',\n null,\n );\n });\n}\n\nfunction getExpectedResToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n): string {\n const hint = 'expected res to satisfy API spec';\n\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching servers`,\n `Servers found in API spec: ${(openApiSpec as OpenApi3Spec)\n .getServerUrls()\n .join(', ')}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has basePath '${\n (openApiSpec as OpenApi2Spec).spec.basePath\n }'`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching path`,\n `Paths found in API spec: ${openApiSpec.paths().join(', ')}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had request method '${method}', but your API spec has no '${method}' operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${expectedRequestOperations}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n \n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had status '${status}', but your API spec has no '${status}' response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${expectedResponseStatuses}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n return joinWithNewLines(\n hint,\n `expected res to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res did not satisfy it because: ${validationError}`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n\nfunction getExpectedResNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n return joinWithNewLines(\n `expected res not to satisfy API spec`,\n `expected res not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { stringify, joinWithNewLines } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion, AssertionError } = chai;\n\n Assertion.addMethod('satisfySchemaInApiSpec', function (schemaName) {\n const actualObject = this._obj; // eslint-disable-line no-underscore-dangle\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n throw new AssertionError(\n 'The argument to satisfySchemaInApiSpec must match a schema in your API spec',\n );\n }\n\n const validationError = openApiSpec.validateObject(actualObject, schema);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectReceivedToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n validationError,\n ),\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n ),\n null,\n );\n });\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n) {\n return joinWithNewLines(\n `expected object to satisfy the '${schemaName}' schema defined in your API spec`,\n `object did not satisfy it because: ${validationError}`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n) {\n return joinWithNewLines(\n `expected object not to satisfy the '${schemaName}' schema defined in your API spec`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAA+C;;;ACA/C,+BAQO;;;ACRP,kBAAwB;AAEjB,IAAM,YAAY,CAAC,YACxB,qBAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADKJ,SAAR,uBACL,MACA,aACM;AACN,QAAM,EAAE,UAAU,IAAI;AAEtB,YAAU,YAAY,kBAAkB,WAAY;AAClD,UAAM,qBAAiB,uCAAa,KAAK,IAAI;AAE7C,UAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,UAAM,OAAO,CAAC;AACd,SAAK;AAAA,MACH;AAAA,MACA,OACI,KACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACJ,OACI,qCAAqC,gBAAgB,WAAW,IAChE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,kCACP,gBACA,aACA,iBACQ;AACR,QAAM,OAAO;AAEb,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,QAAQ,MAAM,YAAY,IAAI;AACtC,QAAM,oBAAoB,GAAG,MAAM,IAAI,WAAW;AAElD,MAAI,gBAAgB,SAAS,mCAAU,gBAAgB;AACrD,WAAO;AAAA,MACL;AAAA,MACA,8BAA8B,MAAM,oCAAoC,iBAAiB;AAAA,MACzF,yBAAyB,WAAW;AAAA,MACpC,8BAA+B,YAC5B,cAAc,EACd,KAAK,IAAI,CAAC;AAAA,IACf;AAAA,EACF;AAEA,MAAI,gBAAgB,SAAS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d,SAAK;AAAA,MACH;AAAA,MACA,OACI,KACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACJ;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,6CACP,UACA,YACA,QACA,iBACA;AACA,SAAO;AAAA,IACL,mCAAmC,UAAU;AAAA,IAC7C,sCAAsC,eAAe;AAAA,IACrD,eAAe,UAAU,QAAQ,CAAC;AAAA,IAClC,QAAQ,UAAU,yBAAyB,UAAU,MAAM,CAAC;AAAA,EAC9D;AACF;AAEA,SAAS,gDACP,UACA,YACA,QACA;AACA,SAAO;AAAA,IACL,uCAAuC,UAAU;AAAA,IACjD,eAAe,UAAU,QAAQ,CAAC;AAAA,IAClC,QAAQ,UAAU,yBAAyB,UAAU,MAAM,CAAC;AAAA,EAC9D;AACF;;;AH7Ce,SAAR,cACL,kBACiB;AACjB,QAAM,kBAAc,uCAAY,gBAAgB;AAChD,SAAO,SAAU,MAAM;AACrB,2BAAe,MAAM,WAAW;AAChC,mCAAuB,MAAM,WAAW;AAAA,EAC1C;AACF;","names":["import_openapi_validator"]}
|
package/dist/index.mjs
CHANGED
|
@@ -87,10 +87,7 @@ function getExpectedResToSatisfyApiSpecMsg(actualResponse, openApiSpec, validati
|
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
if (validationError.code === ErrorCode.StatusNotFound) {
|
|
90
|
-
const expectedResponseOperation = (
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
92
|
-
openApiSpec.findExpectedResponseOperation(req)
|
|
93
|
-
);
|
|
90
|
+
const expectedResponseOperation = openApiSpec.findExpectedResponseOperation(req);
|
|
94
91
|
const expectedResponseStatuses = Object.keys(
|
|
95
92
|
expectedResponseOperation.responses
|
|
96
93
|
).join(", ");
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/index.ts","../lib/assertions/satisfyApiSpec.ts","../lib/utils.ts","../lib/assertions/satisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport satisfyApiSpec from './assertions/satisfyApiSpec';\nimport satisfySchemaInApiSpec from './assertions/satisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n satisfyApiSpec: Assertion;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n satisfySchemaInApiSpec(schemaName: string): Assertion;\n }\n }\n}\n\nexport default function (\n filepathOrObject: string | OpenAPISpecObject,\n): Chai.ChaiPlugin {\n const openApiSpec = makeApiSpec(filepathOrObject);\n return function (chai) {\n satisfyApiSpec(chai, openApiSpec);\n satisfySchemaInApiSpec(chai, openApiSpec);\n };\n}\n","import {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion } = chai;\n\n Assertion.addProperty('satisfyApiSpec', function () {\n const actualResponse = makeResponse(this._obj); // eslint-disable-line no-underscore-dangle\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectedResToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n ),\n pass\n ? getExpectedResNotToSatisfyApiSpecMsg(actualResponse, openApiSpec)\n : '',\n null,\n );\n });\n}\n\nfunction getExpectedResToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n): string {\n const hint = 'expected res to satisfy API spec';\n\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching servers`,\n `Servers found in API spec: ${(openApiSpec as OpenApi3Spec)\n .getServerUrls()\n .join(', ')}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has basePath '${\n (openApiSpec as OpenApi2Spec).spec.basePath\n }'`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching path`,\n `Paths found in API spec: ${openApiSpec.paths().join(', ')}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had request method '${method}', but your API spec has no '${method}' operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${expectedRequestOperations}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had status '${status}', but your API spec has no '${status}' response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${expectedResponseStatuses}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n return joinWithNewLines(\n hint,\n `expected res to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res did not satisfy it because: ${validationError}`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n\nfunction getExpectedResNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n return joinWithNewLines(\n `expected res not to satisfy API spec`,\n `expected res not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { stringify, joinWithNewLines } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion, AssertionError } = chai;\n\n Assertion.addMethod('satisfySchemaInApiSpec', function (schemaName) {\n const actualObject = this._obj; // eslint-disable-line no-underscore-dangle\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new AssertionError(\n 'The argument to satisfySchemaInApiSpec must match a schema in your API spec',\n );\n }\n\n const validationError = openApiSpec.validateObject(actualObject, schema);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectReceivedToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n validationError,\n ),\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n ),\n null,\n );\n });\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n) {\n return joinWithNewLines(\n `expected object to satisfy the '${schemaName}' schema defined in your API spec`,\n `object did not satisfy it because: ${validationError}`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n) {\n return joinWithNewLines(\n `expected object not to satisfy the '${schemaName}' schema defined in your API spec`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n"],"mappings":";AAAA,SAAS,mBAAsC;;;ACA/C;AAAA,EAEE;AAAA,EACA;AAAA,OAKK;;;ACRP,SAAS,eAAe;AAEjB,IAAM,YAAY,CAAC,QACxB,QAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADKJ,SAAR,uBACL,MACA,aACM;AACN,QAAM,EAAE,UAAU,IAAI;AAEtB,YAAU,YAAY,kBAAkB,WAAY;AAClD,UAAM,iBAAiB,aAAa,KAAK,IAAI;AAE7C,UAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,UAAM,OAAO,CAAC;AACd,SAAK;AAAA,MACH;AAAA,MACA,OACI,KACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACJ,OACI,qCAAqC,gBAAgB,WAAW,IAChE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,kCACP,gBACA,aACA,iBACQ;AACR,QAAM,OAAO;AAEb,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,QAAQ,MAAM,YAAY,IAAI;AACtC,QAAM,oBAAoB,GAAG,MAAM,IAAI,WAAW;AAElD,MAAI,gBAAgB,SAAS,UAAU,gBAAgB;AACrD,WAAO;AAAA,MACL;AAAA,MACA,8BAA8B,MAAM,oCAAoC,iBAAiB;AAAA,MACzF,yBAAyB,WAAW;AAAA,MACpC,8BAA+B,YAC5B,cAAc,EACd,KAAK,IAAI,CAAC;AAAA,IACf;AAAA,EACF;AAEA,MAAI,gBAAgB,SAAS,UAAU,kBAAkB;AACvD,WAAO;AAAA,MACL;AAAA,MACA,8BAA8B,MAAM,oCAAoC,iBAAiB;AAAA,MACzF,yBAAyB,WAAW,sCACjC,YAA6B,KAAK,QACrC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A,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,6CACP,UACA,YACA,QACA,iBACA;AACA,SAAO;AAAA,IACL,mCAAmC,UAAU;AAAA,IAC7C,sCAAsC,eAAe;AAAA,IACrD,eAAe,UAAU,QAAQ,CAAC;AAAA,IAClC,QAAQ,UAAU,yBAAyB,UAAU,MAAM,CAAC;AAAA,EAC9D;AACF;AAEA,SAAS,gDACP,UACA,YACA,QACA;AACA,SAAO;AAAA,IACL,uCAAuC,UAAU;AAAA,IACjD,eAAe,UAAU,QAAQ,CAAC;AAAA,IAClC,QAAQ,UAAU,yBAAyB,UAAU,MAAM,CAAC;AAAA,EAC9D;AACF;;;AH7Ce,SAAR,cACL,kBACiB;AACjB,QAAM,cAAc,YAAY,gBAAgB;AAChD,SAAO,SAAU,MAAM;AACrB,2BAAe,MAAM,WAAW;AAChC,mCAAuB,MAAM,WAAW;AAAA,EAC1C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../lib/index.ts","../lib/assertions/satisfyApiSpec.ts","../lib/utils.ts","../lib/assertions/satisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport satisfyApiSpec from './assertions/satisfyApiSpec';\nimport satisfySchemaInApiSpec from './assertions/satisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n satisfyApiSpec: Assertion;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/chai-openapi-response-validator#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n satisfySchemaInApiSpec(schemaName: string): Assertion;\n }\n }\n}\n\nexport default function (\n filepathOrObject: string | OpenAPISpecObject,\n): Chai.ChaiPlugin {\n const openApiSpec = makeApiSpec(filepathOrObject);\n return function (chai) {\n satisfyApiSpec(chai, openApiSpec);\n satisfySchemaInApiSpec(chai, openApiSpec);\n };\n}\n","import {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion } = chai;\n\n Assertion.addProperty('satisfyApiSpec', function () {\n const actualResponse = makeResponse(this._obj); // eslint-disable-line no-underscore-dangle\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectedResToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n ),\n pass\n ? getExpectedResNotToSatisfyApiSpecMsg(actualResponse, openApiSpec)\n : '',\n null,\n );\n });\n}\n\nfunction getExpectedResToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n): string {\n const hint = 'expected res to satisfy API spec';\n\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching servers`,\n `Servers found in API spec: ${(openApiSpec as OpenApi3Spec)\n .getServerUrls()\n .join(', ')}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has basePath '${\n (openApiSpec as OpenApi2Spec).spec.basePath\n }'`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `res had request path '${requestPath}', but your API spec has no matching path`,\n `Paths found in API spec: ${openApiSpec.paths().join(', ')}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had request method '${method}', but your API spec has no '${method}' operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${expectedRequestOperations}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n \n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n return joinWithNewLines(\n hint,\n `expected res to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res had status '${status}', but your API spec has no '${status}' response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${expectedResponseStatuses}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n return joinWithNewLines(\n hint,\n `expected res to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res did not satisfy it because: ${validationError}`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n\nfunction getExpectedResNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n return joinWithNewLines(\n `expected res not to satisfy API spec`,\n `expected res not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `res contained: ${actualResponse.toString()}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${stringify(\n responseDefinition,\n )}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { stringify, joinWithNewLines } from '../utils';\n\nexport default function (\n chai: Chai.ChaiStatic,\n openApiSpec: OpenApiSpec,\n): void {\n const { Assertion, AssertionError } = chai;\n\n Assertion.addMethod('satisfySchemaInApiSpec', function (schemaName) {\n const actualObject = this._obj; // eslint-disable-line no-underscore-dangle\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n throw new AssertionError(\n 'The argument to satisfySchemaInApiSpec must match a schema in your API spec',\n );\n }\n\n const validationError = openApiSpec.validateObject(actualObject, schema);\n const pass = !validationError;\n this.assert(\n pass,\n pass\n ? ''\n : getExpectReceivedToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n validationError,\n ),\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n actualObject,\n schemaName,\n schema,\n ),\n null,\n );\n });\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n) {\n return joinWithNewLines(\n `expected object to satisfy the '${schemaName}' schema defined in your API spec`,\n `object did not satisfy it because: ${validationError}`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n) {\n return joinWithNewLines(\n `expected object not to satisfy the '${schemaName}' schema defined in your API spec`,\n `object was: ${stringify(received)}`,\n `The '${schemaName}' schema in API spec: ${stringify(schema)}`,\n );\n}\n"],"mappings":";AAAA,SAAS,mBAAsC;;;ACA/C;AAAA,EAEE;AAAA,EACA;AAAA,OAKK;;;ACRP,SAAS,eAAe;AAEjB,IAAM,YAAY,CAAC,QACxB,QAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADKJ,SAAR,uBACL,MACA,aACM;AACN,QAAM,EAAE,UAAU,IAAI;AAEtB,YAAU,YAAY,kBAAkB,WAAY;AAClD,UAAM,iBAAiB,aAAa,KAAK,IAAI;AAE7C,UAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,UAAM,OAAO,CAAC;AACd,SAAK;AAAA,MACH;AAAA,MACA,OACI,KACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACJ,OACI,qCAAqC,gBAAgB,WAAW,IAChE;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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ehuelsmann/chai-openapi-response-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Use Chai to assert that HTTP responses satisfy an OpenAPI spec",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"clean:openapi-validator": "cd ../openapi-validator && yarn clean",
|
|
23
23
|
"build:openapi-validator": "cd ../openapi-validator && yarn build",
|
|
24
24
|
"format": "prettier --write ../../ --ignore-path ../../.prettierignore",
|
|
25
|
-
"lint": "tsc --noEmit --project tsconfig.eslint.json && eslint .",
|
|
25
|
+
"lint": "yarn build:openapi-validator && tsc --noEmit --project tsconfig.eslint.json && eslint .",
|
|
26
26
|
"lint:fix": "yarn lint --fix",
|
|
27
|
-
"build": "tsup",
|
|
28
|
-
"test": "mocha --require ts-node/register --extension ts --recursive",
|
|
27
|
+
"build": "yarn build:openapi-validator && tsup",
|
|
28
|
+
"test": "yarn build:openapi-validator && mocha --require ts-node/register --extension ts --recursive",
|
|
29
29
|
"test:watch": "yarn test --watch",
|
|
30
30
|
"test:coverage": "yarn clean && yarn clean:openapi-validator && yarn build && yarn build:openapi-validator && nyc yarn test && nyc report --reporter=lcov && nyc check-coverage",
|
|
31
31
|
"test:coverage:browse": "yarn test:coverage; open ../coverage/lcov-report/index.html",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"axios": "^1.15.2",
|
|
69
69
|
"chai": "^6.2.2",
|
|
70
70
|
"chai-http": "^5.1.2",
|
|
71
|
-
"eslint": "^
|
|
71
|
+
"eslint": "^10.0.0",
|
|
72
72
|
"eslint-plugin-chai-friendly": "^1.2.0",
|
|
73
73
|
"eslint-plugin-import": "^2.22.1",
|
|
74
|
-
"eslint-plugin-mocha": "^
|
|
74
|
+
"eslint-plugin-mocha": "^11.0.0",
|
|
75
75
|
"express": "^5.2.1",
|
|
76
76
|
"fs-extra": "^9.0.1",
|
|
77
77
|
"mocha": "^11.7.4",
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
"tsup": "^8.5.1"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@ehuelsmann/openapi-validator": "^0.
|
|
85
|
+
"@ehuelsmann/openapi-validator": "^0.17.0"
|
|
86
86
|
}
|
|
87
87
|
}
|