express-jsdoc-swagger
With this library, you can document your express endpoints using swagger OpenAPI 3 Specification without writing YAML or JSON. You can write jsdoc comments on each endpoint, and the library is going to create the swagger UI.
Prerequisites
This library assumes you are using:
- NodeJS
- Express.js
Installation
npm i express-jsdoc-swagger
Usage
const express = require('express');
const expressJSDocSwagger = require('express-jsdoc-swagger');
const options = {
info: {
version: '1.0.0',
title: 'Albums store',
license: {
name: 'MIT',
},
},
security: {
BasicAuth: {
type: 'http',
scheme: 'basic',
},
},
filesPattern: './**/*.js',
swaggerUIPath: '/your-url',
baseDir: __dirname,
exposeSwaggerUI: true,
exposeApiDocs: false,
apiDocsPath: '/v3/api-docs',
};
const app = express();
const PORT = 3000;
expressJSDocSwagger(app)(options);
app.get('/api/v1', (req, res) => res.json({
success: true,
}));
app.listen(PORT, () => console.log(`Example app listening at http://localhost:${PORT}`));
Examples
- Basic configuration
const options = {
info: {
version: '1.0.0',
title: 'Albums store',
license: {
name: 'MIT',
},
},
security: {
BasicAuth: {
type: 'http',
scheme: 'basic',
},
},
filesPattern: './**/*.js',
baseDir: __dirname,
};
- Components definition
- Endpoint that returns a
Songs
model array
app.get('/api/v1/albums', (req, res) => (
res.json([{
title: 'abum 1',
}])
));
- Basic endpoint definition with tags, params and basic authentication
app.get('/api/v1/album', (req, res) => (
res.json({
title: 'abum 1',
})
));
- Basic endpoint definition with code example for response body
app.get('/api/v1/albums', (req, res) => (
res.json([{
title: 'track 1',
}])
));
You can find more examples here, or visit our documentation.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind welcome!