-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
swagger.js
33 lines (28 loc) · 922 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
33
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const config = require('config');
const pjson = require('./package.json');
const signale = require('./utils/signale');
const serverConfig = config.get('server');
const swagger = (app, config) => {
const swaggerDefinition = {
info: {
title: `${pjson.name}`,
version: `${pjson.version}`,
description: `Swagger - ${pjson.description}`
},
basePath: config.context
};
const options = {
swaggerDefinition,
apis: ['./routes/*.js']
};
const swaggerSpec = swaggerJSDoc(options);
app.get('/swagger.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
signale.info(`Swagger is enabled in : ${serverConfig.url}/api-docs`);
};
module.exports = swagger;