Registry / testing / openapi-response-validator

openapi-response-validator

JSON →
library12.1.3jsnpmunverified

A library to validate HTTP responses against OpenAPI (Swagger) schemas. v12.1.3 is the current stable release, maintained as part of the open-api monorepo. It uses jsonschema under the hood and supports $ref in response definitions, custom error transformers, and custom formats. Lightweight and focused solely on response validation, unlike full OpenAPI validators like express-openapi-validator. Released on GitHub with consistent versioning.

npm install openapi-response-validator
INSTALL
IMPORT
SIG · OPENAPI-RESPONSE-V
O
openapi-response-validator
testingjavascriptv12.1.3
harness data pending
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.
fix
Upgrade Node.js to 18 or later.
affects: >=12.0.0
gotchaThe constructor expects an object with 'responses' key, not raw schema.
fix
Pass { responses: { ... } } as shown in docs.
affects: >=0.0.0
deprecatedUsing 'errorTransformer' is deprecated in favor of 'errorFormatter' since v10.
fix
Use 'errorFormatter' instead in newer versions.
affects: >=10.0.0 <12.0.0
gotchaIf no response schema matches, validateResponse returns null silently.
fix
Check 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.
fix
Run 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.
fix
Use const OpenAPIResponseValidator = require('openapi-response-validator'); without destructuring.
Schema validation error: unknown format "email"
Using a format not defined in jsonschema or customFormats.
fix
Add the format to the customFormats option in the constructor.
Upgrade
Version history
12.1.3latest on npm
Audit
Dependencies
jsonschemarequiredSchema validation engine used internally
Agent activity
4 hits · last 30 days
node
4
Resources
openapi-response-validator — npm install openapi-response-validator · libregistry