Registry /
testing / openapi-response-validator
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OpenAPIResponseValidator
✓ import OpenAPIResponseValidator from 'openapi-response-validator'
✗ const OpenAPIResponseValidator = require('openapi-response-validator').default
Default export in ESM; CJS require works without .default
OpenAPIResponseValidator
✓ const OpenAPIResponseValidator = require('openapi-response-validator')
✗ const { OpenAPIResponseValidator } = require('openapi-response-validator')
CommonJS: destructure is wrong because it's a default export
OpenAPIResponseValidator
✓ import OpenAPIResponseValidator from 'openapi-response-validator'
TypeScript: import default, types are included from @types/openapi-response-validator or bundled?
Creates a validator with a 200 response schema and validates a response object.
import OpenAPIResponseValidator from 'openapi-response-validator';
const validator = new OpenAPIResponseValidator({
responses: {
200: {
description: 'Success',
schema: { type: 'object', properties: { id: { type: 'integer' } }, required: ['id'] }
}
}
});
const result = validator.validateResponse(200, { id: 123 });
console.log(result); // null if valid, else error object
Debug
Known issues
breakingVersion 12 dropped support for Node.js < 18.fixUpgrade Node.js to 18 or later.
affects: >=12.0.0
gotchaThe constructor expects an object with 'responses' key, not raw schema.fixPass { responses: { ... } } as shown in docs. affects: >=0.0.0
deprecatedUsing 'errorTransformer' is deprecated in favor of 'errorFormatter' since v10.fixUse 'errorFormatter' instead in newer versions.
affects: >=10.0.0 <12.0.0
gotchaIf no response schema matches, validateResponse returns null silently.fixCheck for undefined/null before assuming validation passed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'openapi-response-validator'
Package not installed or incorrect import path.
fixRun npm install openapi-response-validator and use correct import: const OpenAPIResponseValidator = require('openapi-response-validator'); TypeError: OpenAPIResponseValidator is not a constructor
Using destructured import in CommonJS.
fixUse const OpenAPIResponseValidator = require('openapi-response-validator'); without destructuring. Schema validation error: unknown format "email"
Using a format not defined in jsonschema or customFormats.
fixAdd the format to the customFormats option in the constructor.
Audit
Dependencies
jsonschemarequiredSchema validation engine used internally