how to integrate swagger with my express application how to integrate swagger with my express application express express

how to integrate swagger with my express application


I have experience with documenting an Express API using an express module (swagger-node-express). I also have experience with documenting an Express API using manual Swagger JSON docs.

I would recommend not tying yourself down to a module for your Swagger docs. Most of the modules (and especially swagger-node-express) force you to write your Express code differently to handle the documentation. When manually writing your Swagger docs with JSON, you are able to write Express and decouple the documentation from your routing.

Use Swagger UI to style your documentation and add it to your web page.

Here are some resources you can use when starting out:

Swagger Editor - edit your swagger docs and see your changes live update
Swagger Docs - Swagger specs for JSON
Tutorial - This uses an older version of Swagger, be sure to check out Migrating Swagger to upgrade to the newest version

Also, take a look at this answer explaining the difference between manual and module-based swagger doc generation -> HERE.


I have recently come across implementing API documentation using swagger. I have used "swagger-ui-express" npm module to implement it.Created JSON at runtime i.e., once server starts running, I captured data and modified according to the swagger specifications like below file.

https://editor.swagger.io/ Here you can see the swagger specifications in JSON.

Require the "swagger-ui-express" module, create a JSON and feed the file to swaggerui as below.

const swaggerUi = require('swagger-ui-express');const swaggerDocument = require('./swagger.json');app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));


I am not completely clear on what your asking but I think you're looking for something like this: swagger-tools

I use this module and it has been great. It exposes some middleware which you can bind to the Express app that you create. For example, if you have your service documented and that documentation is Swagger compliant, then you can pass that document to the middleware. The middleware does some wonderful things like wiring up request handlers based on the definitions that are found in your documentation and validating requests against definitions found in your documentation.

It has a great tutorial and it is super easy to get setup. I hope this helps and is along the lines of what you were looking for.