
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
openapi-data-validator
Advanced tools
Automatically validate API requests and responses with OpenAPI 3.
Lightweight OpenAPI complete request model validator. Fast, unopinionated, full featured validator for API requests that utilize OpenAPI docs for API documentation.
This is an open source project managed by the Authress Engineering team.
It is simple, and that's all there is to it!
npm install openapi-data-validator --save
const { OpenApiValidator } = require('openapi-data-validator');
const spec = require('./openapi.json');
const openApiValidator = new OpenApiValidator({ apiSpec: spec });
const validator = openApiValidator.createValidator();
// Configure this to the client's request. It will resolve the expected schema in the spec using the method and route defined, and validate the request parameters.
const newRequest = {
method: 'GET',
// Matched openapi specification generic route, this should be the generic `path` from the spec, such as `/resources/{resourceId}/`, it must match one of them exactly.
route: request.route
headers: { Authorization: 'Bearer Token' },
// Query string parameters from the request
query: { limit: 10 },
// Body already parsed to JSON
body: { field: true },
// Path parameters
path: { user: 'userId' }
};
await validator(newRequest);
For improved processing speed the validator can be pre-compiled from the spec
const openApiValidator = new OpenApiValidator({ apiSpec: spec, compiledFilePath: './compiledValidator.json' });
await openApiValidator.compileValidator();
// Later
const validator = await openApiValidator.loadValidation();
// ...
await validator(request);
Checkout the full: Async example
AJV is the best, but there are some things that just are very OpenAPI specific that don't make sense to be in the validator. Don't need them? Great, go use AJV.
FAQs
Automatically validate API requests and responses with OpenAPI 3.
The npm package openapi-data-validator receives a total of 4,039 weekly downloads. As such, openapi-data-validator popularity was classified as popular.
We found that openapi-data-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.