swaggerjsontoapidocs 1.9.0 → 1.10.0

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/README.md CHANGED
@@ -46,153 +46,158 @@ MSYS_NO_PATHCONV=1 npx swaggerjsontoapidocs [options]
46
46
  ### Example Usage
47
47
 
48
48
  ```bash
49
- npx swaggerjsontoapidocs -s http://localhost:5033/swagger/v1/swagger.json --bp /api/
49
+ npx swaggerjsontoapidocs -s http://localhost:5033/swagger/v1/swagger.json --bp /api/v1/
50
50
  ```
51
51
 
52
52
  In this example:
53
53
 
54
54
  - `-s` points to the URL of the Swagger JSON file.
55
- - `--bp` defines the base path `/api/` to be removed from the endpoints.
55
+ - `--bp` defines the base path `/api/v1/` to be removed from the endpoints.
56
56
 
57
57
  <details>
58
58
  <summary>Swagger.json (Click to expand)</summary>
59
59
 
60
60
  ```json
61
61
  {
62
- "openapi": "3.0.1",
62
+ "swagger": "2.0",
63
63
  "info": {
64
- "title": "fakeApi",
65
- "version": "1.0"
64
+ "version": "1.2.0",
65
+ "title": "Extended Sample API with Multiple Path Parameters",
66
+ "description": "Test Swagger specification including endpoints with multiple path parameters."
66
67
  },
67
68
  "paths": {
68
- "/api/Users": {
69
+ "/api/v1/users/{userId}/orders/{orderId}": {
69
70
  "get": {
70
- "tags": ["Users"],
71
- "responses": {
72
- "200": {
73
- "description": "OK",
74
- "content": {
75
- "text/plain": {
76
- "schema": {
77
- "type": "array",
78
- "items": {
79
- "$ref": "#/components/schemas/Usuario"
80
- }
81
- }
82
- },
83
- "application/json": {
84
- "schema": {
85
- "type": "array",
86
- "items": {
87
- "$ref": "#/components/schemas/Usuario"
88
- }
89
- }
90
- },
91
- "text/json": {
92
- "schema": {
93
- "type": "array",
94
- "items": {
95
- "$ref": "#/components/schemas/Usuario"
96
- }
97
- }
98
- }
99
- }
71
+ "tags": ["Order Processing"],
72
+ "summary": "Get a specific order for a user",
73
+ "parameters": [
74
+ {
75
+ "name": "userId",
76
+ "in": "path",
77
+ "required": true,
78
+ "type": "string"
79
+ },
80
+ {
81
+ "name": "orderId",
82
+ "in": "path",
83
+ "required": true,
84
+ "type": "string"
100
85
  }
86
+ ],
87
+ "responses": {
88
+ "200": { "description": "Order details" },
89
+ "404": { "description": "Order not found" }
101
90
  }
91
+ },
92
+ "put": {
93
+ "tags": ["Order Processing"],
94
+ "summary": "Update a specific order for a user",
95
+ "parameters": [
96
+ {
97
+ "name": "userId",
98
+ "in": "path",
99
+ "required": true,
100
+ "type": "string"
101
+ },
102
+ {
103
+ "name": "orderId",
104
+ "in": "path",
105
+ "required": true,
106
+ "type": "string"
107
+ },
108
+ {
109
+ "name": "body",
110
+ "in": "body",
111
+ "required": true,
112
+ "schema": { "$ref": "#/definitions/Order" }
113
+ }
114
+ ],
115
+ "responses": { "200": { "description": "Order updated" } }
102
116
  }
103
117
  },
104
- "/api/Users/{id}": {
105
- "get": {
106
- "tags": ["Users"],
118
+ "/api/v1/Products/{productId}/Reviews/{reviewId}/Comments/{commentId}": {
119
+ "delete": {
120
+ "tags": ["Reviews"],
121
+ "summary": "Delete a specific comment on a review",
107
122
  "parameters": [
108
123
  {
109
- "name": "id",
124
+ "name": "productId",
110
125
  "in": "path",
111
126
  "required": true,
112
- "schema": {
113
- "type": "string"
114
- }
127
+ "type": "string"
128
+ },
129
+ {
130
+ "name": "reviewId",
131
+ "in": "path",
132
+ "required": true,
133
+ "type": "string"
134
+ },
135
+ {
136
+ "name": "commentId",
137
+ "in": "path",
138
+ "required": true,
139
+ "type": "string"
115
140
  }
116
141
  ],
117
142
  "responses": {
118
- "200": {
119
- "description": "OK",
120
- "content": {
121
- "text/plain": {
122
- "schema": {
123
- "$ref": "#/components/schemas/Usuario"
124
- }
125
- },
126
- "application/json": {
127
- "schema": {
128
- "$ref": "#/components/schemas/Usuario"
129
- }
130
- },
131
- "text/json": {
132
- "schema": {
133
- "$ref": "#/components/schemas/Usuario"
134
- }
135
- }
136
- }
137
- }
143
+ "200": { "description": "Comment deleted" },
144
+ "404": { "description": "Comment not found" }
138
145
  }
139
- },
146
+ }
147
+ },
148
+ "/api/v1/admin/{section}/{entityId}/actions/{actionId}": {
140
149
  "post": {
141
- "tags": ["Users"],
150
+ "tags": ["Administration"],
151
+ "summary": "Perform an admin action on an entity",
142
152
  "parameters": [
143
153
  {
144
- "name": "id",
154
+ "name": "section",
155
+ "in": "path",
156
+ "required": true,
157
+ "type": "string"
158
+ },
159
+ {
160
+ "name": "entityId",
145
161
  "in": "path",
146
162
  "required": true,
163
+ "type": "string"
164
+ },
165
+ {
166
+ "name": "actionId",
167
+ "in": "path",
168
+ "required": true,
169
+ "type": "string"
170
+ },
171
+ {
172
+ "name": "body",
173
+ "in": "body",
174
+ "required": false,
147
175
  "schema": {
148
- "type": "string"
176
+ "type": "object",
177
+ "properties": {
178
+ "reason": { "type": "string" },
179
+ "timestamp": { "type": "string", "format": "date-time" }
180
+ }
149
181
  }
150
182
  }
151
183
  ],
152
184
  "responses": {
153
- "200": {
154
- "description": "OK",
155
- "content": {
156
- "text/plain": {
157
- "schema": {
158
- "$ref": "#/components/schemas/Usuario"
159
- }
160
- },
161
- "application/json": {
162
- "schema": {
163
- "$ref": "#/components/schemas/Usuario"
164
- }
165
- },
166
- "text/json": {
167
- "schema": {
168
- "$ref": "#/components/schemas/Usuario"
169
- }
170
- }
171
- }
172
- }
185
+ "200": { "description": "Action executed successfully" },
186
+ "400": { "description": "Invalid action" }
173
187
  }
174
188
  }
175
189
  }
176
190
  },
177
- "components": {
178
- "schemas": {
179
- "Usuario": {
180
- "type": "object",
181
- "properties": {
182
- "id": {
183
- "type": "string",
184
- "nullable": true
185
- },
186
- "nombre": {
187
- "type": "string",
188
- "nullable": true
189
- },
190
- "email": {
191
- "type": "string",
192
- "nullable": true
193
- }
194
- },
195
- "additionalProperties": false
191
+ "definitions": {
192
+ "Order": {
193
+ "type": "object",
194
+ "properties": {
195
+ "id": { "type": "string" },
196
+ "status": { "type": "string" },
197
+ "items": {
198
+ "type": "array",
199
+ "items": { "type": "string" }
200
+ }
196
201
  }
197
202
  }
198
203
  }
@@ -204,46 +209,52 @@ In this example:
204
209
  ### Result
205
210
 
206
211
  ```bash
207
- ├── api_docs
208
- ├── products
209
- └── products.ts
212
+ api_docs/
213
+ ├── admin
214
+ └── admin.ts
215
+ ├── products
216
+ │ └── products.ts
217
+ └── users
218
+ └── users.ts
210
219
  ```
211
220
 
212
221
  ```typescript
213
222
  // products.ts
214
223
  /**
215
- * @endpoint /api/products
216
- * @methods GET - POST
224
+ * ##### METHODS
225
+ * **DELETE**: Delete a specific comment on a review
226
+ *
227
+ * ---
228
+ * **Endpoint**: `/api/v1/Products/{productId}/Reviews/{reviewId}/Comments/{commentId}`
229
+ *
230
+ * ---
231
+ * ##### PATH PARAMETERS
232
+ * @param productId - any
233
+ * @param reviewId - any
234
+ * @param commentId - any
217
235
  */
218
- export const products = () => `products`;
219
- /**
220
- * @endpoint /api/products/{id}/category/{categoryId}
221
- * @methods GET - PUT - DELETE
222
- * @param id
223
- * @param categoryId
224
- */
225
- export const products_id_category_categoryId = (id: any, categoryId: any) =>
226
- `products/${id}/category/${categoryId}`;
236
+ export const Products_productId_Reviews_reviewId_Comments_commentId = (
237
+ productId: any,
238
+ reviewId: any,
239
+ commentId: any,
240
+ ) => `Products/${productId}/Reviews/${reviewId}/Comments/${commentId}`;
227
241
  ```
228
242
 
229
243
  ### Result --function-name-lowercase
230
244
 
231
245
  ```typescript
232
246
  // products.ts
233
- /**
234
- * @endpoint /api/products/{id}/category/{categoryId}
235
- * @methods GET - PUT - DELETE
236
- * @param id
237
- * @param categoryId
238
- */
239
- export const products_id_category_categoryid = (id: any, categoryId: any) =>
240
- `products/${id}/category/${categoryId}`;
247
+ export const products_productId_reviews_reviewId_comments_commentId = (
248
+ productId: any,
249
+ reviewId: any,
250
+ commentId: any,
251
+ ) => `Products/${productId}/Reviews/${reviewId}/Comments/${commentId}`;
241
252
  ```
242
253
 
243
254
  ### Advanced Usage
244
255
 
245
256
  ```bash
246
- npx swaggerjsontoapidocs -s http://localhost:5033/swagger/v1/swagger.json --bp /api/ -o ./docs/ --skip-folder
257
+ npx swaggerjsontoapidocs -s http://localhost:5033/swagger/v1/swagger.json --bp /api/v1/ -o ./docs/ --skip-folder
247
258
  ```
248
259
 
249
260
  In this example:
@@ -254,10 +265,11 @@ In this example:
254
265
  ### Result --skip-folder
255
266
 
256
267
  ```bash
257
- docs
268
+ docs/
258
269
  └── api_docs
270
+ ├── admin.ts
259
271
  ├── products.ts
260
- └── weatherforecast.ts
272
+ └── users.ts
261
273
  ```
262
274
 
263
275
  ## License
package/bin/index.js CHANGED
@@ -52,7 +52,7 @@ const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
52
52
  .alias('help', 'h')
53
53
  .strict()
54
54
  .parseSync();
55
- async function main() {
55
+ function main() {
56
56
  console.log(chalk_1.default.green('CONFIGURING THE SCRIPT WITH THE PROVIDED ARGUMENTS...'));
57
57
  const swaggerPath = argv.swagger;
58
58
  const basePath = argv.bp;
@@ -49,7 +49,7 @@ async function initScript(params) {
49
49
  chalk_1.default.red('Could not connect: The server is off or the URL is incorrect.'));
50
50
  }
51
51
  else {
52
- console.log(chalk_1.default.red(`✘ unknown error: ${error}`));
52
+ console.log(chalk_1.default.red(`unknown error: ${error}`));
53
53
  }
54
54
  await cleanFileAndConfig();
55
55
  return null;
@@ -82,7 +82,7 @@ async function filterPathsObject() {
82
82
  async function cleanFileAndConfig() {
83
83
  await cleanFile();
84
84
  await cleanConfig();
85
- console.log('🧹 Cleaned.');
85
+ console.log('Cleaned.');
86
86
  }
87
87
  async function cleanFile() {
88
88
  await (0, promises_1.rm)((0, node_path_1.join)(__dirname, 'paths.json'), { force: true });
@@ -134,21 +134,31 @@ const generateDocumentation = (endpoint, methods, apiEndpoint) => {
134
134
  })
135
135
  .join(', ');
136
136
  const paramsDoc = paramsMatch
137
- .map((p) => `* @param ${p.replace(/[{}]/g, '')}`)
137
+ .map((p) => `* @param ${p.replace(/[{}]/g, '')} - any`)
138
138
  .join('\n');
139
- const endpointLine = apiEndpoint ? `\n* @endpoint ${apiEndpoint}\n` : '';
139
+ const endpointLine = apiEndpoint
140
+ ? `*\n* ---\n* **Endpoint**: \`${apiEndpoint}\``
141
+ : '*';
140
142
  const methodsDoc = methods
141
- .map((method) => {
142
- let doc = '* @method ' + method.verb.toUpperCase();
143
- if (method.summary) {
144
- doc += ` - ${method.summary}`;
143
+ .map((method, index) => {
144
+ let doc = '* **' + method.verb.toUpperCase() + '**: ';
145
+ doc += method.summary ? `${method.summary}` : `without summary`;
146
+ if (index + 1 !== methods.length) {
147
+ doc += '\n*';
145
148
  }
146
149
  return doc;
147
150
  })
148
151
  .join('\n');
149
- const methodsLine = methodsDoc ? `${methodsDoc}\n` : '';
150
- const paramsLine = paramsDoc ? `${paramsDoc}\n` : '';
151
- const jsDoc = `/**${endpointLine}${methodsLine}${paramsLine}*/\n`;
152
+ const methodsLine = methodsDoc ? `* ##### METHODS\n${methodsDoc}` : '*';
153
+ const paramsLine = paramsDoc
154
+ ? `*\n* ---\n* ##### PATH PARAMETERS\n${paramsDoc}`
155
+ : '*';
156
+ const jsDoc = `
157
+ /**
158
+ ${methodsLine}
159
+ ${endpointLine}
160
+ ${paramsLine}
161
+ */\n`;
152
162
  return {
153
163
  args,
154
164
  jsDoc,
@@ -167,15 +177,15 @@ async function makeFileContainer(apiEndpoints, foldersName) {
167
177
  try {
168
178
  await (0, promises_1.appendFile)(filePath, line);
169
179
  await formatWithPrettier(filePath);
170
- console.log(`✅ Generated: ${name}`);
180
+ console.log(`Generated: ${name}`);
171
181
  }
172
182
  catch (error) {
173
- console.error(`❌ Error occurred while writing to ${filePath}:`, error);
183
+ console.error(`Error occurred while writing to ${filePath}:`, error);
174
184
  }
175
185
  }
176
186
  }
177
187
  async function destinationPath(fullPath) {
178
- console.log('💾 show result --->', fullPath);
188
+ console.log('show result --->', fullPath);
179
189
  }
180
190
  async function moveFolderToChoosePath() {
181
191
  await (0, fs_extra_1.move)(mainFolderOutPut, `${paramsConfig.output}${folderName}`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggerjsontoapidocs",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "script to convert swagger json to api docs, this help us to consume functions and center all endpoints in one place",
5
5
  "keywords": [
6
6
  "swagger",
@@ -31,7 +31,18 @@
31
31
  "api": "ts-node ./src/index.ts",
32
32
  "dist": "node ./bin/index.js",
33
33
  "lint": "eslint .",
34
- "prepublishOnly": "npm run build"
34
+ "prepublishOnly": "npm run build",
35
+ "prepare": "simple-git-hooks"
36
+ },
37
+ "simple-git-hooks": {
38
+ "pre-commit": "npx lint-staged",
39
+ "commit-msg": "npx commitlint --edit $1"
40
+ },
41
+ "lint-staged": {
42
+ "*.{js,jsx,ts,tsx}": [
43
+ "prettier --write",
44
+ "eslint --quiet"
45
+ ]
35
46
  },
36
47
  "bin": {
37
48
  "swaggerjsontoapidocs": "bin/index.js"
@@ -43,6 +54,8 @@
43
54
  "yargs": "18.0.0"
44
55
  },
45
56
  "devDependencies": {
57
+ "@commitlint/cli": "^20.4.1",
58
+ "@commitlint/config-conventional": "^20.4.1",
46
59
  "@eslint/js": "9.39.2",
47
60
  "@semantic-release/changelog": "^6.0.3",
48
61
  "@semantic-release/git": "^10.0.1",
@@ -54,7 +67,9 @@
54
67
  "eslint": "9.39.2",
55
68
  "globals": "17.0.0",
56
69
  "jiti": "2.6.1",
70
+ "lint-staged": "^16.2.7",
57
71
  "semantic-release": "^25.0.2",
72
+ "simple-git-hooks": "^2.13.1",
58
73
  "ts-node": "10.9.2",
59
74
  "typescript": "5.9.3",
60
75
  "typescript-eslint": "8.52.0"