Swagger Express Middleware

Swagger 2.0 middlware and mocks for Express.js

The Middleware class

The Middleware class is the main class in Swagger Express Middleware. It’s role is simple: You give it a Swagger API, and it gives you Express middleware for that API. You can create multiple Middleware instances if you need to work with more than one Swagger API. Each Middleware instance is entirely isolated, so any Express middleware that is created by one instance will only know about its own Swagger API.

TIP: For most simple apps, you don’t need to worry about the Middleware class. The createMiddleware function — which is used in all the documentation examples — is a convenience function that automatically instantiates a Middleware object and calls its init() method for you.

Constructor

Middleware(router)

This is the constructor for the Middleware class.

Methods

init(swagger, callback)

Initializes the middleware with the given Swagger API. This method can be called again to re-initialize with a new or modified API.

files(router, options)

This method creates a new Files middleware instance.

metadata(router)

This method creates a new Metadata middleware instance.

CORS(router)

This method creates a new CORS middleware instance.

parseRequest(router, options)

This method creates a new Parse Request middleware instance.

validateRequest(router)

This method creates a new Validate Request middleware instance.

mock(router, dataStore)

This method creates a new Mock middleware instance.