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
Over 1,000 unit tests and integration tests with 100% code coverage. Tested on over 100 Google APIs. All tests are run on Mac, Linux, and Windows using the past 3 versions of Node. But nothing's perfect, so if you find a bug, please report it.
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.
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
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.
Adds the appropriate CORS headers to each request and automatically responds to CORS preflight requests, all in compliance with your Swagger API definition.
Install using NPM.
npm install swagger-express-middleware
Then use it in your Node.js script like this:
var express = ;var middleware = ;var app = ;;
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.
To build/test the project locally on your computer:
Clone this repo
git clone https://github.com/bigstickcarpet/swagger-express-middleware.git
Run the build script
npm run build
Run the unit tests
npm run mocha (just the tests)
npm test (tests + code coverage)
Run the sample app
Swagger Express Middleware is 100% free and open-source, under the MIT license. Use it however you want.