This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.js
64 lines (60 loc) · 1.67 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
52
53
54
55
56
57
58
59
60
61
62
63
64
const NODE_ENV = process.env.NODE_ENV;
const NODE_ENV_IS_DEV = NODE_ENV === "development";
if (NODE_ENV_IS_DEV) {
require("dotenv").config();
}
const swaggerJsdoc = require("swagger-jsdoc");
const fs = require("fs");
const openapi_filename = "./dist/openapi_doc.json";
const options = {
definition: {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Aeolus API"
},
servers: [
{
url: NODE_ENV_IS_DEV ? "http://localhost:8080/" : "https://aeolus.se/api"
}
],
tags: [
{
name: "Simulator",
description: "Simulator related stuff"
},
{
name: "Alarms",
description: "Subscribe and create alarms"
},
{
name: "Social",
description: "Interact with other users and other user related things"
}
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT"
}
}
},
security: [
{
bearerAuth: []
}
]
},
apis: ["./dist/routes/*.js"]
};
const openapiSpecification = swaggerJsdoc(options);
fs.writeFile(openapi_filename, JSON.stringify(openapiSpecification), "utf-8", (err, data) => {
if (err) {
console.log(err);
process.exit(1);
} else {
console.log(`Openapi specification was sucesfully generated. Output location: "${openapi_filename}"`);
}
});