Gathering detailed insights and metrics for swagger-express-middleware
Gathering detailed insights and metrics for swagger-express-middleware
Gathering detailed insights and metrics for swagger-express-middleware
Gathering detailed insights and metrics for swagger-express-middleware
@apidevtools/swagger-express-middleware
Swagger middleware and mocks for Express
@types/swagger-express-middleware
TypeScript definitions for swagger-express-middleware
swagger-express-mw
Swagger loader and middleware for express
redoc-express
Express Middleware for OpenAPI/Swagger-generated API Reference Documentation
npm install swagger-express-middleware
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
575 Stars
335 Commits
197 Forks
20 Watchers
3 Branches
14 Contributors
Updated on Mar 09, 2025
Latest Version
4.0.2
Package Id
swagger-express-middleware@4.0.2
Size
4.94 kB
NPM Version
6.14.6
Node Version
10.22.0
Published on
Aug 01, 2020
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
1
Supports Swagger 2.0 specs in JSON or YAML
Swagger Express Middleware uses Swagger-Parser to parse, validate, and dereference Swagger files. You can even split your spec into multiple different files using $ref
pointers.
Thoroughly tested
Over 1,000 unit tests and integration tests with 100% code coverage. Tested on over 1,500 real-world APIs from Google, Microsoft, Facebook, Spotify, etc. All tests are run on Mac, Linux, and Windows using all LTS versions of Node.
Mock middleware
Fully-functional mock implementations for every operation in your API, including data persistence, all with zero code! This is a great way to test-drive your API as you write it, or for quick demos and POCs. You can even extend the mock middleware with your own logic and data to fill in any gaps.
Metadata middleware
Annotates each request with all the relevant information from the Swagger definition. The path, the operation, the parameters, the security requirements - they're all easily accessible at req.swagger
.
Parse Request middleware
Parses incoming requests and converts everything into the correct data types, according to your Swagger API definition.
Validate Request middleware
Ensures that every request complies with your Swagger API definition, or returns the appropriate HTTP error codes if needed. Of course, you can catch any validation errors and handle them however you want.
CORS middleware
Adds the appropriate CORS headers to each request and automatically responds to CORS preflight requests, all in compliance with your Swagger API definition.
Files middleware
Serves the Swagger API file(s) in JSON or YAML format so they can be used with front-end tools like Swagger UI, Swagger Editor, and Postman.
Install using npm.
1npm install @apidevtools/swagger-express-middleware
Then use it in your Node.js script like this:
1const express = require('express'); 2const createMiddleware = require('@apidevtools/swagger-express-middleware'); 3 4let app = express(); 5 6createMiddleware('PetStore.yaml', app, function(err, middleware) { 7 // Add all the Swagger Express Middleware, or just the ones you need. 8 // NOTE: Some of these accept optional options (omitted here for brevity) 9 app.use( 10 middleware.metadata(), 11 middleware.CORS(), 12 middleware.files(), 13 middleware.parseRequest(), 14 middleware.validateRequest(), 15 middleware.mock() 16 ); 17 18 app.listen(8000, function() { 19 console.log('The PetStore sample is now running at http://localhost:8000'); 20 }); 21});
Swagger Express Middleware comes two samples that use the Swagger Pet Store API.
This sample demonstrates the most simplistic usage of Swagger Express Middleware. It simply creates a new Express Application and adds all of the Swagger middleware without changing any options, and without adding any custom middleware.
This sample demonstrates a few more advanced features of Swagger Express Middleware, such as setting a few options, initializing the mock data store, and adding custom middleware logic.
I welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request.
To build/test the project locally on your computer:
Clone this repo
git clone https://github.com/APIDevTools/swagger-express-middleware.git
Install dependencies
npm install
Run the tests
npm test
Run the sample app
npm start
Swagger Express Middleware is 100% free and open-source, under the MIT license. Use it however you want.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Thanks to these awesome companies for their support of Open Source developers ❤
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/16 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
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
43 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