zyket 1.0.24 → 1.0.26

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.24",
3
+ "version": "1.0.26",
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,6 +6,8 @@ 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 {
@@ -30,6 +32,26 @@ module.exports = class Express extends Service {
30
32
  this.#app.use(cors({
31
33
  origin: '*'
32
34
  }))
35
+
36
+ // get version from package json
37
+ const version = require(path.join(process.cwd(), "package.json")).version;
38
+
39
+ // Swagger setup
40
+ const swaggerOptions = {
41
+ swaggerDefinition: {
42
+ info: {
43
+ title: process.env.API_DOCS_TITLE || "API Documentation",
44
+ version: version,
45
+ description: process.env.API_DOCS_DESCRIPTION || "API Documentation generated by Swagger",
46
+ },
47
+ servers: [
48
+ { url: `http://localhost:3000` }
49
+ ],
50
+ },
51
+ apis: [path.join(process.cwd(), "src", "routes", "**", "*.js")],
52
+ };
53
+ const swaggerDocs = swaggerJsDoc(swaggerOptions);
54
+ this.#app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
33
55
 
34
56
  const routes = await this.#loadRoutesFromFolder(path.join(process.cwd(), "src", "routes"));
35
57
 
@@ -95,4 +117,8 @@ module.exports = class Express extends Service {
95
117
  fs.mkdirSync(path.join(process.cwd(), "src", "middlewares"));
96
118
  this.#container.get('template-manager').installFile('default/src/middlewares/default', path.join(process.cwd(), "src", "middlewares", "default.js"));
97
119
  }
120
+
121
+ app() {
122
+ return this.#app;
123
+ }
98
124
  }