express-jsdoc-swagger
With this library, you can document your endpoints using swagger OpenAPI 3 Specification without writing YAML or JSON. You just have to write comments on your endpoints and swagger UI will be automatically generated.
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,
};
const app = express();
const PORT = 3000;
expressJSDocSwagger(app)(options);
app.get('/api/v1', (req, res) => res.json({
success: true,
}));
app.listen(PORT, () => logger.info(`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',
})
));
You can find more examples here, or visit our documentation (WIP)
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind welcome!