-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.js
51 lines (48 loc) · 1.23 KB
/
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
48
49
50
51
const swaggerJsdoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "INTERCESSOR API",
description: "Intercessor endpoints documented on swagger",
contact: {
name: "Joshua Adesanya",
email: "[email protected]",
url: "https://github.com/Josh4324/Intercessor-BE",
},
version: "1.0.0",
},
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
servers: [
{
url: "http://localhost:3000",
description: "Local server",
},
{
url: "<your live url here>",
description: "Live server",
},
],
},
// looks for configuration in specified directories
apis: ["./routes/*.js"],
};
const swaggerSpec = swaggerJsdoc(options);
module.exports = (app, port) => {
// Swagger Page
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Documentation in JSON format
app.get("/api/docs.json", (req, res) => {
res.setHeader("Content-Type", "application/json");
res.send(swaggerSpec);
});
};