zyket 1.0.25 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -26,6 +26,8 @@
26
26
  "prompts": "^2.4.2",
27
27
  "redis": "^5.9.0",
28
28
  "sequelize": "^6.37.7",
29
- "socket.io": "^4.8.1"
29
+ "socket.io": "^4.8.1",
30
+ "swagger-jsdoc": "^6.2.8",
31
+ "swagger-ui-express": "^5.0.1"
30
32
  }
31
33
  }
@@ -6,12 +6,24 @@ const fs = require("fs");
6
6
  const path = require("path");
7
7
  const fg = require('fast-glob');
8
8
  const Middleware = require("./Middleware");
9
+ const swaggerJsDoc = require("swagger-jsdoc");
10
+ const swaggerUi = require("swagger-ui-express");
9
11
 
10
12
 
11
13
  module.exports = class Express extends Service {
12
14
  #container;
13
15
  #app;
14
16
  #httpServer;
17
+ static swaggerConfig = {
18
+ info: {
19
+ title: process.env.API_DOCS_TITLE || "API Documentation",
20
+ version: version,
21
+ description: process.env.API_DOCS_DESCRIPTION || "API Documentation generated by Swagger",
22
+ },
23
+ servers: [
24
+ { url: `http://localhost:3000` }
25
+ ],
26
+ }
15
27
 
16
28
  constructor(container) {
17
29
  super("express");
@@ -30,6 +42,17 @@ module.exports = class Express extends Service {
30
42
  this.#app.use(cors({
31
43
  origin: '*'
32
44
  }))
45
+
46
+ // get version from package json
47
+ const version = require(path.join(process.cwd(), "package.json")).version;
48
+
49
+ // Swagger setup
50
+ const swaggerOptions = {
51
+ ...Express.swaggerConfig,
52
+ apis: [path.join(process.cwd(), "src", "routes", "**", "*.js")],
53
+ };
54
+ const swaggerDocs = swaggerJsDoc(swaggerOptions);
55
+ this.#app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
33
56
 
34
57
  const routes = await this.#loadRoutesFromFolder(path.join(process.cwd(), "src", "routes"));
35
58