-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswagger.js
More file actions
41 lines (39 loc) · 1.04 KB
/
swagger.js
File metadata and controls
41 lines (39 loc) · 1.04 KB
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
import swaggerJsdoc from 'swagger-jsdoc'
import swaggerUi from 'swagger-ui-express'
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Joke API Swagger D0cs',
description: "API Endpoints For A Joke API Documented In Swagger",
contact: {
name: "Israel Adedamola KAMI",
email: "adedamolacopy@gmail.com",
url: "https://kamii.hashnode.dev"
},
version: '1.0.0',
},
servers: [
{
url: "http://localhost:5841",
description: "Local server"
},
{
url: "<your live url here>",
description: "Live server"
},
]
},
apis: ['./server/routes/*.js'], // Path to your API routes
}
const swaggerSpec = swaggerJsdoc(options)
function swaggerDocs(app, port) {
// Swagger Page
app.use('/jokeapi/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