-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger.js
40 lines (33 loc) · 838 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
import swaggerJsdoc from 'swagger-jsdoc'
import swaggerUi from 'swagger-ui-express'
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'My Brand',
description: 'My personal brand API ',
version: '1.0.0',
},
components:{
securitySchemes:{
BearerAuth:{
type: "http",
scheme: "bearer"
}
}
}
},
// looks for configuration in specified directories
apis: ["./src/routers/*.js"],
}
const swaggerSpec = swaggerJsdoc(options)
function swaggerDocs(app, port) {
// Swagger Page
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec))
// Documentation in JSON format
app.get('/docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json')
res.send(swaggerSpec)
})
}
export default swaggerDocs