-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswagger.js
More file actions
59 lines (54 loc) · 1.5 KB
/
swagger.js
File metadata and controls
59 lines (54 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-env node */
const swaggerJsdoc = require("swagger-jsdoc");
const fs = require("fs");
// When this script is run from the command line, the output will be written to this file.
const outputFile = "./dist/swagger.json";
exports.getOpenapiSpecification = additionalApis => {
if (additionalApis == undefined) {
additionalApis = [];
}
const apis = [
"./src/controllers/**/*.ts",
"./src/enums/**/*.ts",
"./src/@types/**/*.d.ts",
"./src/middleware/interceptors/**/*.ts",
...additionalApis,
];
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Hack the Lab 2024 API",
version: "1.0.0",
description:
"<a href='https://rb.gy/6xov18'>Hack The Lab (Details Handout)</a>.<br><a href='https://discord.gg/5sf8v4x3'>Join Hack the Lab Discord</a><br><a href='http://dash.milabs.xyz'>Hack-the-Lab Dashboard </a>",
},
security: [
{
apiKey: [],
},
],
components: {
securitySchemes: {
apiKey: {
type: "apiKey",
in: "header",
name: "X-API-KEY",
},
},
},
},
apis,
};
return swaggerJsdoc(options);
};
if (require.main === module) {
// File is being called directory, write the openapi spec.
// const additionalApis = ["./src/controllers/**/*.ts"];
const data = this.getOpenapiSpecification();
fs.writeFile(outputFile, JSON.stringify(data), err => {
if (err) {
process.exit(5);
}
});
}