Gathering detailed insights and metrics for swagger-express-validator
Gathering detailed insights and metrics for swagger-express-validator
Gathering detailed insights and metrics for swagger-express-validator
Gathering detailed insights and metrics for swagger-express-validator
@types/swagger-express-validator
TypeScript definitions for swagger-express-validator
swagger-express-validator-formats
swagger-express-validator, but with more supported Swagger formats passed to AJV
express-oas-validator
express openapi middleware validator
@jdes/swagger-express-validator
A Swagger validator and router for Express.js
Lightweight requrest/response validation middleware based on swagger/OpenAPI schema
npm install swagger-express-validator
Typescript
Module System
Min. Node Version
68.4
Supply Chain
98.3
Quality
77.5
Maintenance
50
Vulnerability
99.3
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
56 Stars
79 Commits
24 Forks
2 Watchers
10 Branches
8 Contributors
Updated on Oct 25, 2023
Latest Version
1.0.2
Package Id
swagger-express-validator@1.0.2
Unpacked Size
15.14 kB
Size
5.00 kB
File Count
5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
swagger-express-validator
is a lightweight middleware for request/response validation based on
OpenAPI v2.0 (aka swagger) specification.
The main difference of this package to alternatives like swagger-tools is that this package is very configurable and only concentrates on validation against provided schema. You can choose the behavior of invalid validation like returning a 500 or just logging an error to your logger.
x-nullable
attributeStart using this library with npm install swagger-express-validator --save
To set up simple validation for your requests and responses:
1const util = require('util'); 2const express = require('express'); 3const bodyParser = require('body-parser'); 4const validator = require('swagger-express-validator'); 5const schema = require('./api-schema.json'); 6 7const server = express(); 8server.use(bodyParser.json()); 9 10const opts = { 11 schema, // Swagger schema 12 preserveResponseContentType: false, // Do not override responses for validation errors to always be JSON, default is true 13 returnRequestErrors: true, // Include list of request validation errors with response, default is false 14 returnResponseErrors: true, // Include list of response validation errors with response, default is false 15 validateRequest: true, 16 validateResponse: true, 17 requestValidationFn: (req, data, errors) => { 18 console.log(`failed request validation: ${req.method} ${req.originalUrl}\n ${util.inspect(errors)}`) 19 }, 20 responseValidationFn: (req, data, errors) => { 21 console.log(`failed response validation: ${req.method} ${req.originalUrl}\n ${util.inspect(errors)}`) 22 }, 23}; 24server.use(validator(opts)); 25 26server.use('/status', (req, res) => { 27 res.json({ 28 status: 'OK', 29 }) 30}); 31server.use((err, req, res, next) => { 32 res.status(500); 33 res.json(err); 34}); 35 36return server.listen(3000); 37
swagger-express-validator
uses Ajv for schema validation under the hood. You can tweak many validation parameters by passing Ajv configuration overrides:
1server.use(validator({ 2 schema, 3 preserveResponseContentType: false, 4 returnRequestErrors: true, 5 returnResponseErrors: true, 6 validateRequest: true, 7 validateResponse: true, 8 ajvRequestOptions: { 9 coerceTypes: true, 10 }, 11 ajvResponseOptions: { 12 coerceTypes: true, 13 }, 14}));
See Ajv documentation for supported values.
To see debug output use DEBUG=swagger-express-validator
as an environmental variable when starting
your project, eg.: DEBUG=swagger-express-validator node server.js
. To gain more insights
on how this works see documentation of debug library
Special thanks to @bgaluszka for initial inspiration :)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/24 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
35 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More