-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.js
32 lines (26 loc) · 932 Bytes
/
swagger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const optionsV1 = {
definition: {
openapi: '3.0.0',
info: {
title: 'My Boilerplate API',
description: 'nodejs-express-mysql-api-boilerplate API ',
version: '1.0.0',
},
},
// looks for configuration in specified directories
apis: ['./route/v1/*.js', './controller/*.js', './middleware/*.js'],
}
const swaggerSpecV1 = swaggerJsdoc(optionsV1)
function swaggerDocs(app, port) {
console.log(`:::::::::::::::: SWAGGER RUNNING ON ${port}.`)
// Swagger Page For API V1
app.use('/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpecV1))
// Documentation in JSON format
app.get('/v1/docs-json', (req, res) => {
res.setHeader('Content-Type', 'application/json')
res.send(swaggerSpecV1)
})
}
module.exports = swaggerDocs