swagger-ui-express
Serve Swagger UI from your Express app — auto-generate interactive API documentation from your OpenAPI spec.
swagger-ui-express
ExpressServe Swagger UI from your Express app — auto-generate interactive API documentation from your OpenAPI spec.
Fit
Bundle (gzip)
3.0 kB
7.4 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
API documentation that lives in a separate wiki gets out of sync with the actual API. Developers need interactive, up-to-date documentation that lets them test endpoints directly from the browser.
What It Does
swagger-ui-express serves the Swagger UI at a configurable route and renders your OpenAPI/Swagger JSON or YAML spec as an interactive documentation page. Combined with swagger-jsdoc, docs can be auto-generated from JSDoc comments in your route files.
Installation
npm install swagger-ui-express swagger-jsdoc
npm install -D @types/swagger-ui-expressUsage Example
import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc';
const spec = swaggerJsdoc({
definition: {
openapi: '3.0.0',
info: { title: 'My API', version: '1.0.0' },
},
apis: ['./src/routes/*.ts'],
});
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(spec));
// Visit http://localhost:3000/api-docs/**
* @openapi
* /users:
* get:
* summary: List all users
* responses:
* 200:
* description: Array of users
*/
app.get('/users', (req, res) => res.json(users));Related packages
Node.js body parsing middleware — populate `req.body` from JSON, urlencoded, text, and raw payloads.
compressionExpressHTTP response compression middleware for Express — gzip/deflate responses to reduce bandwidth and improve load times.
cookie-parserExpressCookie parsing middleware for Express — parse Cookie headers into `req.cookies` and support signed cookies for tamper detection.
corsExpressCORS middleware for Express — configure cross-origin resource sharing with a single line of code.
express-async-errorsExpressSimplify Express error handling by automatically passing thrown errors to `next()`.