Swagger Express Middleware

Swagger 2.0 middlware and mocks for Express.js

Swagger Express Middleware

Swagger 2.0 middleware and mocks for Express.js

:warning: No longer maintained This package has been abandoned for some time, and there are plenty of modern alternatives around which support OpenAPI v3.x listed on OpenAPI.Tools which you can use instead.

npm License Buy us a tree


Installation and Use

Install using npm.

npm install @apidevtools/swagger-express-middleware

Then use it in your Node.js script like this:

const express = require('express');
const createMiddleware = require('@apidevtools/swagger-express-middleware');

let app = express();

createMiddleware('PetStore.yaml', app, function(err, middleware) {
    // Add all the Swagger Express Middleware, or just the ones you need.
    // NOTE: Some of these accept optional options (omitted here for brevity)

    app.listen(8000, function() {
        console.log('The PetStore sample is now running at http://localhost:8000');

Samples & Walkthroughs

Swagger Express Middleware comes two samples that use the Swagger Pet Store API.

Sample 1

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.

Sample 2

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:

  1. Clone this repo
    git clone https://github.com/APIDevTools/swagger-express-middleware.git

  2. Install dependencies
    npm install

  3. Run the tests
    npm test

  4. 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.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

Travis CI SauceLabs Coveralls