-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswagger.js
43 lines (38 loc) · 1.01 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
const swaggerJsdoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Node Blog App",
description:
"API endpoints for a blog web application documented on swagger",
contact: {
name: "Ali Talha ÇOBAN",
email: "cobanalitalha@gmail.com",
url: "https://github.com/carpodok/node-blog-app",
},
version: "1.0.0",
},
servers: [
{
url: "http://localhost:3000/",
description: "Local server",
},
{
url: "<your live url here>",
description: "Live server",
},
],
},
apis: ["./src/routes/*.js"],
};
const swaggerSpec = swaggerJsdoc(options);
function swaggerDocs(app, port) {
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.get("/api-docs.json", (req, res) => {
res.setHeader("Content-Type", "application/json");
res.send(swaggerSpec);
});
}
module.exports = swaggerDocs;