Registry /
web-framework / express-openapi-validate
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OpenApiValidator
✓ import { OpenApiValidator } from 'express-openapi-validate'
✗ const OpenApiValidator = require('express-openapi-validate')
Default import not supported; must use named import. CommonJS require works with { OpenApiValidator } destructuring.
OpenApiDocument
✓ import type { OpenApiDocument } from 'express-openapi-validate'
✗ import { OpenApiDocument } from 'express-openapi-validate'
OpenApiDocument is a TypeScript type, only import as type to avoid runtime errors.
validator.validate
✓ import { OpenApiValidator } from 'express-openapi-validate';
const validator = new OpenApiValidator(doc);
router.post('/path', validator.validate('post', '/path'))
✗ validator.validate('post','/path')(req,res)
validator.validate returns middleware, not invoked directly.
Express server with OpenAPI validation using validator.validate() and custom Ajv options.
const fs = require('fs');
const express = require('express');
const { OpenApiValidator } = require('express-openapi-validate');
const YAML = require('js-yaml');
const app = express();
app.use(express.json());
const apiDoc = YAML.load(fs.readFileSync('./openapi.yaml', 'utf8'));
const validator = new OpenApiValidator(apiDoc, {
ajvOptions: { coerceTypes: true },
});
app.post('/echo', validator.validate('post', '/echo'), (req, res) => {
res.json({ output: req.body.input });
});
app.use((err, req, res, next) => {
res.status(err.statusCode || 500).json({ error: err.message });
});
app.listen(3000);
Errors
Common errors & fixes
SyntaxError: Unexpected token in JSON at position 0
Passing a JavaScript object instead of a JSON string to OpenApiValidator constructor.
fixEnsure the document is an object (already parsed from JSON/YAML). If using JSON.parse/require, it's already an object.
TypeError: Cannot destructure property 'OpenApiValidator' of ... undefined
Using default import instead of named import.
fixUse: import { OpenApiValidator } from 'express-openapi-validate' Error: No matching operation for POST /unknown
Validator.match() cannot find a matching route specification. Throw occurs if allowNoMatch is not set.
fixEither add the operation to your OpenAPI document or use: validator.match({ allowNoMatch: true }) ValidationError: request.body should have required property 'input'
Request body does not match schema defined in OpenAPI document.
fixEnsure request body includes all required properties as defined in the OpenAPI schema.
Audit
Dependencies
ajvrequiredUsed internally for JSON Schema validation. v8 used since v0.6.0, breaking changes from v6.
js-yamloptionalOften used to parse OpenAPI YAML documents, though not a direct dependency of this package.