-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswagger.js
47 lines (38 loc) · 917 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUI = require('swagger-ui-express');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Capstone Blog API',
version: '1.0.0',
},
components: {
securitySchemes: {
jwt: {
type: 'http',
scheme: 'bearer',
in: 'header',
bearerFormat: 'JWT',
},
},
},
security: [
{
jwt: [],
},
],
swagger: '3.0',
},
apis: ['./routes.js'],
};
const swaggerSpec = swaggerJsdoc(options);
const swaggerDocs = (app, port) => {
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerSpec));
app.get('/docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
console.log(`Read docs at http://localhost:${port}/api-docs`);
};
module.exports = swaggerDocs;