@g1cloud/api-gen 1.0.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.
Files changed (86) hide show
  1. package/.claude/settings.local.json +22 -0
  2. package/CLAUDE.md +63 -0
  3. package/README.md +379 -0
  4. package/dist/analyzer/controllerAnalyzer.d.ts +20 -0
  5. package/dist/analyzer/controllerAnalyzer.d.ts.map +1 -0
  6. package/dist/analyzer/controllerAnalyzer.js +101 -0
  7. package/dist/analyzer/controllerAnalyzer.js.map +1 -0
  8. package/dist/analyzer/parameterAnalyzer.d.ts +19 -0
  9. package/dist/analyzer/parameterAnalyzer.d.ts.map +1 -0
  10. package/dist/analyzer/parameterAnalyzer.js +207 -0
  11. package/dist/analyzer/parameterAnalyzer.js.map +1 -0
  12. package/dist/analyzer/responseAnalyzer.d.ts +12 -0
  13. package/dist/analyzer/responseAnalyzer.d.ts.map +1 -0
  14. package/dist/analyzer/responseAnalyzer.js +116 -0
  15. package/dist/analyzer/responseAnalyzer.js.map +1 -0
  16. package/dist/analyzer/schemaGenerator.d.ts +6 -0
  17. package/dist/analyzer/schemaGenerator.d.ts.map +1 -0
  18. package/dist/analyzer/schemaGenerator.js +347 -0
  19. package/dist/analyzer/schemaGenerator.js.map +1 -0
  20. package/dist/analyzer/securityAnalyzer.d.ts +6 -0
  21. package/dist/analyzer/securityAnalyzer.d.ts.map +1 -0
  22. package/dist/analyzer/securityAnalyzer.js +177 -0
  23. package/dist/analyzer/securityAnalyzer.js.map +1 -0
  24. package/dist/generator/openapiGenerator.d.ts +14 -0
  25. package/dist/generator/openapiGenerator.d.ts.map +1 -0
  26. package/dist/generator/openapiGenerator.js +340 -0
  27. package/dist/generator/openapiGenerator.js.map +1 -0
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +218 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/lib.d.ts +61 -0
  33. package/dist/lib.d.ts.map +1 -0
  34. package/dist/lib.js +199 -0
  35. package/dist/lib.js.map +1 -0
  36. package/dist/mcp-server.d.ts +9 -0
  37. package/dist/mcp-server.d.ts.map +1 -0
  38. package/dist/mcp-server.js +257 -0
  39. package/dist/mcp-server.js.map +1 -0
  40. package/dist/mcp-server.mjs +45586 -0
  41. package/dist/parser/astAnalyzer.d.ts +87 -0
  42. package/dist/parser/astAnalyzer.d.ts.map +1 -0
  43. package/dist/parser/astAnalyzer.js +321 -0
  44. package/dist/parser/astAnalyzer.js.map +1 -0
  45. package/dist/parser/javaParser.d.ts +10 -0
  46. package/dist/parser/javaParser.d.ts.map +1 -0
  47. package/dist/parser/javaParser.js +805 -0
  48. package/dist/parser/javaParser.js.map +1 -0
  49. package/dist/types/index.d.ts +217 -0
  50. package/dist/types/index.d.ts.map +1 -0
  51. package/dist/types/index.js +3 -0
  52. package/dist/types/index.js.map +1 -0
  53. package/examples/CreateUserRequest.java +80 -0
  54. package/examples/DepartmentDTO.java +45 -0
  55. package/examples/Filter.java +39 -0
  56. package/examples/PaginatedList.java +71 -0
  57. package/examples/ProductController.java +136 -0
  58. package/examples/ProductDTO.java +129 -0
  59. package/examples/RoleDTO.java +47 -0
  60. package/examples/SearchParam.java +55 -0
  61. package/examples/Sort.java +70 -0
  62. package/examples/UpdateUserRequest.java +74 -0
  63. package/examples/UserController.java +98 -0
  64. package/examples/UserDTO.java +119 -0
  65. package/package.json +51 -0
  66. package/prompt/01_Initial.md +358 -0
  67. package/prompt/02_/354/266/224/352/260/200.md +31 -0
  68. package/src/analyzer/controllerAnalyzer.ts +125 -0
  69. package/src/analyzer/parameterAnalyzer.ts +259 -0
  70. package/src/analyzer/responseAnalyzer.ts +142 -0
  71. package/src/analyzer/schemaGenerator.ts +412 -0
  72. package/src/analyzer/securityAnalyzer.ts +200 -0
  73. package/src/generator/openapiGenerator.ts +378 -0
  74. package/src/index.ts +212 -0
  75. package/src/lib.ts +240 -0
  76. package/src/mcp-server.ts +310 -0
  77. package/src/parser/astAnalyzer.ts +373 -0
  78. package/src/parser/javaParser.ts +901 -0
  79. package/src/types/index.ts +238 -0
  80. package/test-boolean.yaml +607 -0
  81. package/test-filter.yaml +576 -0
  82. package/test-inner.ts +59 -0
  83. package/test-output.yaml +650 -0
  84. package/test-paginated.yaml +585 -0
  85. package/tsconfig.json +20 -0
  86. package/tsup.config.ts +30 -0
@@ -0,0 +1,576 @@
1
+ openapi: 3.0.0
2
+ info:
3
+ title: API Documentation
4
+ version: 1.0.0
5
+ paths:
6
+ /api/products:
7
+ get:
8
+ summary: Search Products
9
+ operationId: product_searchProducts
10
+ responses:
11
+ '200':
12
+ description: Successful response
13
+ headers:
14
+ X-Total-Count:
15
+ schema:
16
+ type: integer
17
+ description: Total number of items
18
+ X-Offset:
19
+ schema:
20
+ type: integer
21
+ description: Current offset
22
+ X-Limit:
23
+ schema:
24
+ type: integer
25
+ description: Current limit
26
+ content:
27
+ application/json:
28
+ schema:
29
+ type: array
30
+ items:
31
+ $ref: '#/components/schemas/ProductDTO'
32
+ description: Search products with pagination
33
+ parameters:
34
+ - name: offset
35
+ in: query
36
+ schema:
37
+ type: integer
38
+ description: Pagination offset
39
+ - name: limit
40
+ in: query
41
+ schema:
42
+ type: integer
43
+ description: Pagination limit
44
+ - name: filter
45
+ in: query
46
+ schema:
47
+ $ref: '#/components/schemas/Filter'
48
+ description: Filter conditions
49
+ - name: sort
50
+ in: query
51
+ schema:
52
+ $ref: '#/components/schemas/Sort'
53
+ description: Sort conditions
54
+ post:
55
+ summary: Create Product
56
+ operationId: product_createProduct
57
+ responses:
58
+ '200':
59
+ description: Successful response
60
+ content:
61
+ application/json:
62
+ schema:
63
+ $ref: '#/components/schemas/ProductDTO'
64
+ description: "Create new product\r\nUsing @Secured annotation"
65
+ requestBody:
66
+ required: true
67
+ content:
68
+ application/json:
69
+ schema:
70
+ $ref: '#/components/schemas/ProductDTO'
71
+ security:
72
+ - bearerAuth: []
73
+ x-required-roles:
74
+ - ROLE_ADMIN
75
+ /api/products/{id}:
76
+ get:
77
+ summary: Get Product By Id
78
+ operationId: product_getProductById
79
+ responses:
80
+ '200':
81
+ description: Successful response
82
+ content:
83
+ application/json:
84
+ schema:
85
+ $ref: '#/components/schemas/ProductDTO'
86
+ description: Get product by ID
87
+ parameters:
88
+ - name: id
89
+ in: path
90
+ schema:
91
+ type: integer
92
+ format: int64
93
+ required: true
94
+ put:
95
+ summary: Update Product
96
+ operationId: product_updateProduct
97
+ responses:
98
+ '200':
99
+ description: Successful response
100
+ content:
101
+ application/json:
102
+ schema:
103
+ $ref: '#/components/schemas/ProductDTO'
104
+ description: "Update product\r\nComplex security: admin can update any product, vendor can only update own products"
105
+ parameters:
106
+ - name: id
107
+ in: path
108
+ schema:
109
+ type: integer
110
+ format: int64
111
+ required: true
112
+ requestBody:
113
+ required: true
114
+ content:
115
+ application/json:
116
+ schema:
117
+ $ref: '#/components/schemas/ProductDTO'
118
+ security:
119
+ - bearerAuth: []
120
+ x-required-roles:
121
+ - ROLE_ADMIN
122
+ - ROLE_VENDOR
123
+ x-security-expression: hasRole('ADMIN') or (hasRole('VENDOR') and @productService.isOwner(#id, authentication.principal.id))
124
+ delete:
125
+ summary: Delete Product
126
+ operationId: product_deleteProduct
127
+ responses:
128
+ '200':
129
+ description: Successful response
130
+ description: Delete product
131
+ parameters:
132
+ - name: id
133
+ in: path
134
+ schema:
135
+ type: integer
136
+ format: int64
137
+ required: true
138
+ /api/products/category/{categoryId}:
139
+ get:
140
+ summary: Get Products By Category
141
+ operationId: product_getProductsByCategory
142
+ responses:
143
+ '200':
144
+ description: Successful response
145
+ content:
146
+ application/json:
147
+ schema:
148
+ type: array
149
+ items:
150
+ $ref: '#/components/schemas/ProductDTO'
151
+ description: Get products by category with price range filter
152
+ parameters:
153
+ - name: categoryId
154
+ in: path
155
+ schema:
156
+ type: integer
157
+ format: int64
158
+ required: true
159
+ - name: minPrice
160
+ in: query
161
+ schema:
162
+ type: number
163
+ - name: maxPrice
164
+ in: query
165
+ schema:
166
+ type: number
167
+ - name: limit
168
+ in: query
169
+ schema:
170
+ type: integer
171
+ format: int32
172
+ x-security-expression: isAuthenticated()
173
+ /api/products/search:
174
+ get:
175
+ summary: Search Products By Name
176
+ operationId: product_searchProductsByName
177
+ responses:
178
+ '200':
179
+ description: Successful response
180
+ content:
181
+ application/json:
182
+ schema:
183
+ type: array
184
+ items:
185
+ $ref: '#/components/schemas/ProductDTO'
186
+ description: Search products by name (partial match)
187
+ parameters:
188
+ - name: query
189
+ in: query
190
+ schema:
191
+ type: string
192
+ required: true
193
+ - name: sortBy
194
+ in: query
195
+ schema:
196
+ type: string
197
+ - name: sortDirection
198
+ in: query
199
+ schema:
200
+ type: string
201
+ /api/products/bulk-price-update:
202
+ post:
203
+ summary: Bulk Update Prices
204
+ operationId: product_bulkUpdatePrices
205
+ responses:
206
+ '200':
207
+ description: Successful response
208
+ content:
209
+ application/json:
210
+ schema:
211
+ type: array
212
+ items:
213
+ $ref: '#/components/schemas/ProductDTO'
214
+ description: "Bulk update product prices\r\nVery complex security expression with multiple conditions"
215
+ requestBody:
216
+ required: true
217
+ content:
218
+ application/json:
219
+ schema:
220
+ type: array
221
+ items:
222
+ $ref: '#/components/schemas/PriceUpdateRequest'
223
+ security:
224
+ - bearerAuth: []
225
+ x-required-roles:
226
+ - ROLE_ADMIN
227
+ x-security-expression: 'hasRole(''ADMIN'') and hasAuthority(''BULK_OPERATIONS'') and #request.size() <= 100'
228
+ /api/users:
229
+ get:
230
+ summary: Search Users
231
+ operationId: user_searchUsers
232
+ responses:
233
+ '200':
234
+ description: Successful response
235
+ headers:
236
+ X-Total-Count:
237
+ schema:
238
+ type: integer
239
+ description: Total number of items
240
+ X-Offset:
241
+ schema:
242
+ type: integer
243
+ description: Current offset
244
+ X-Limit:
245
+ schema:
246
+ type: integer
247
+ description: Current limit
248
+ content:
249
+ application/json:
250
+ schema:
251
+ type: array
252
+ items:
253
+ $ref: '#/components/schemas/UserDTO'
254
+ description: "Search users with pagination\r\nUses SearchParam for pagination and filtering"
255
+ parameters:
256
+ - name: offset
257
+ in: query
258
+ schema:
259
+ type: integer
260
+ description: Pagination offset
261
+ - name: limit
262
+ in: query
263
+ schema:
264
+ type: integer
265
+ description: Pagination limit
266
+ - name: filter
267
+ in: query
268
+ schema:
269
+ $ref: '#/components/schemas/Filter'
270
+ description: Filter conditions
271
+ - name: sort
272
+ in: query
273
+ schema:
274
+ $ref: '#/components/schemas/Sort'
275
+ description: Sort conditions
276
+ security:
277
+ - bearerAuth: []
278
+ x-required-roles:
279
+ - ROLE_USER
280
+ post:
281
+ summary: Create User
282
+ operationId: user_createUser
283
+ responses:
284
+ '200':
285
+ description: Successful response
286
+ content:
287
+ application/json:
288
+ schema:
289
+ $ref: '#/components/schemas/UserDTO'
290
+ description: Create new user
291
+ requestBody:
292
+ required: true
293
+ content:
294
+ application/json:
295
+ schema:
296
+ $ref: '#/components/schemas/CreateUserRequest'
297
+ security:
298
+ - bearerAuth: []
299
+ x-required-roles:
300
+ - ROLE_ADMIN
301
+ /api/users/{id}:
302
+ get:
303
+ summary: Get User By Id
304
+ operationId: user_getUserById
305
+ responses:
306
+ '200':
307
+ description: Successful response
308
+ content:
309
+ application/json:
310
+ schema:
311
+ $ref: '#/components/schemas/UserDTO'
312
+ description: Get user by ID
313
+ parameters:
314
+ - name: id
315
+ in: path
316
+ schema:
317
+ type: integer
318
+ format: int64
319
+ required: true
320
+ security:
321
+ - bearerAuth: []
322
+ x-required-roles:
323
+ - ROLE_USER
324
+ - ROLE_ADMIN
325
+ put:
326
+ summary: Update User
327
+ operationId: user_updateUser
328
+ responses:
329
+ '200':
330
+ description: Successful response
331
+ content:
332
+ application/json:
333
+ schema:
334
+ $ref: '#/components/schemas/UserDTO'
335
+ description: "Update existing user\r\nComplex security: admin can update anyone, users can only update themselves"
336
+ parameters:
337
+ - name: id
338
+ in: path
339
+ schema:
340
+ type: integer
341
+ format: int64
342
+ required: true
343
+ requestBody:
344
+ required: true
345
+ content:
346
+ application/json:
347
+ schema:
348
+ $ref: '#/components/schemas/UpdateUserRequest'
349
+ security:
350
+ - bearerAuth: []
351
+ x-required-roles:
352
+ - ROLE_ADMIN
353
+ - ROLE_USER
354
+ x-security-expression: hasRole('ADMIN') or (#id == authentication.principal.id and hasRole('USER'))
355
+ delete:
356
+ summary: Delete User
357
+ operationId: user_deleteUser
358
+ responses:
359
+ '200':
360
+ description: Successful response
361
+ description: Delete user
362
+ parameters:
363
+ - name: id
364
+ in: path
365
+ schema:
366
+ type: integer
367
+ format: int64
368
+ required: true
369
+ security:
370
+ - bearerAuth: []
371
+ x-required-roles:
372
+ - ROLE_ADMIN
373
+ /api/users/department/{departmentId}:
374
+ get:
375
+ summary: Get Users By Department
376
+ operationId: user_getUsersByDepartment
377
+ responses:
378
+ '200':
379
+ description: Successful response
380
+ content:
381
+ application/json:
382
+ schema:
383
+ type: array
384
+ items:
385
+ $ref: '#/components/schemas/UserDTO'
386
+ description: Get users by department with optional status filter
387
+ parameters:
388
+ - name: departmentId
389
+ in: path
390
+ schema:
391
+ type: integer
392
+ format: int64
393
+ required: true
394
+ - name: status
395
+ in: query
396
+ schema:
397
+ type: string
398
+ - name: X-Tenant-ID
399
+ in: header
400
+ schema:
401
+ type: string
402
+ security:
403
+ - bearerAuth: []
404
+ /api/users/bulk:
405
+ post:
406
+ summary: Bulk Import Users
407
+ operationId: user_bulkImportUsers
408
+ responses:
409
+ '200':
410
+ description: Successful response
411
+ content:
412
+ application/json:
413
+ schema:
414
+ type: array
415
+ items:
416
+ $ref: '#/components/schemas/UserDTO'
417
+ description: Bulk import users
418
+ requestBody:
419
+ required: true
420
+ content:
421
+ application/json:
422
+ schema:
423
+ type: array
424
+ items:
425
+ $ref: '#/components/schemas/CreateUserRequest'
426
+ security:
427
+ - bearerAuth: []
428
+ x-required-roles:
429
+ - ROLE_ADMIN
430
+ components:
431
+ schemas:
432
+ Filter:
433
+ type: object
434
+ description: Filter conditions
435
+ Sort:
436
+ type: object
437
+ description: Sort conditions
438
+ SearchParam:
439
+ type: object
440
+ description: Search parameters for pagination and filtering
441
+ properties:
442
+ offset:
443
+ type: integer
444
+ description: Pagination offset
445
+ limit:
446
+ type: integer
447
+ description: Pagination limit
448
+ filter:
449
+ $ref: '#/components/schemas/Filter'
450
+ sort:
451
+ $ref: '#/components/schemas/Sort'
452
+ UpdateUserRequest:
453
+ type: object
454
+ properties:
455
+ firstName:
456
+ type: string
457
+ lastName:
458
+ type: string
459
+ email:
460
+ type: string
461
+ phoneNumber:
462
+ type: string
463
+ departmentId:
464
+ type: integer
465
+ format: int64
466
+ status:
467
+ type: string
468
+ CreateUserRequest:
469
+ type: object
470
+ properties:
471
+ firstName:
472
+ type: string
473
+ lastName:
474
+ type: string
475
+ email:
476
+ type: string
477
+ password:
478
+ type: string
479
+ phoneNumber:
480
+ type: string
481
+ departmentId:
482
+ type: integer
483
+ format: int64
484
+ UserDTO:
485
+ type: object
486
+ properties:
487
+ id:
488
+ type: integer
489
+ format: int64
490
+ firstName:
491
+ type: string
492
+ lastName:
493
+ type: string
494
+ email:
495
+ type: string
496
+ phoneNumber:
497
+ type: string
498
+ status:
499
+ type: string
500
+ createdAt:
501
+ type: string
502
+ format: date-time
503
+ updatedAt:
504
+ type: string
505
+ format: date-time
506
+ department:
507
+ $ref: '#/components/schemas/DepartmentDTO'
508
+ roles:
509
+ type: array
510
+ items:
511
+ $ref: '#/components/schemas/RoleDTO'
512
+ RoleDTO:
513
+ type: object
514
+ properties:
515
+ id:
516
+ type: integer
517
+ format: int64
518
+ name:
519
+ type: string
520
+ description:
521
+ type: string
522
+ permissions:
523
+ type: array
524
+ items:
525
+ type: string
526
+ DepartmentDTO:
527
+ type: object
528
+ properties:
529
+ id:
530
+ type: integer
531
+ format: int64
532
+ name:
533
+ type: string
534
+ description:
535
+ type: string
536
+ code:
537
+ type: string
538
+ PriceUpdateRequest:
539
+ type: object
540
+ description: Schema for PriceUpdateRequest
541
+ ProductDTO:
542
+ type: object
543
+ properties:
544
+ id:
545
+ type: integer
546
+ format: int64
547
+ name:
548
+ type: string
549
+ description:
550
+ type: string
551
+ price:
552
+ type: number
553
+ stockQuantity:
554
+ type: integer
555
+ format: int32
556
+ sku:
557
+ type: string
558
+ category:
559
+ type: string
560
+ tags:
561
+ type: array
562
+ items:
563
+ type: string
564
+ active:
565
+ type: boolean
566
+ createdAt:
567
+ type: string
568
+ format: date-time
569
+ updatedAt:
570
+ type: string
571
+ format: date-time
572
+ securitySchemes:
573
+ bearerAuth:
574
+ type: http
575
+ scheme: bearer
576
+ bearerFormat: JWT
package/test-inner.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { parse, BaseJavaCstVisitorWithDefaults } from "java-parser";
2
+
3
+ const javaCode = `
4
+ package test;
5
+
6
+ public class OuterClass {
7
+ private String outerField;
8
+
9
+ public static class InnerDTO {
10
+ private String innerField;
11
+ private int count;
12
+ }
13
+
14
+ public static class AnotherInner {
15
+ private boolean active;
16
+ }
17
+ }
18
+ `;
19
+
20
+ const cst = parse(javaCode);
21
+
22
+ class TestVisitor extends BaseJavaCstVisitorWithDefaults {
23
+ private depth = 0;
24
+
25
+ constructor() {
26
+ super();
27
+ this.validateVisitor();
28
+ }
29
+
30
+ normalClassDeclaration(ctx: any): void {
31
+ const indent = " ".repeat(this.depth);
32
+
33
+ if (ctx.typeIdentifier?.[0]?.children?.Identifier?.[0]) {
34
+ const className = ctx.typeIdentifier[0].children.Identifier[0].image;
35
+ console.log(indent + "Class:", className);
36
+ }
37
+
38
+ this.depth++;
39
+ if (ctx.classBody) {
40
+ this.visit(ctx.classBody);
41
+ }
42
+ this.depth--;
43
+ }
44
+
45
+ fieldDeclaration(ctx: any): void {
46
+ const indent = " ".repeat(this.depth);
47
+ if (ctx.variableDeclaratorList?.[0]?.children?.variableDeclarator) {
48
+ for (const decl of ctx.variableDeclaratorList[0].children.variableDeclarator) {
49
+ if (decl.children?.variableDeclaratorId?.[0]?.children?.Identifier?.[0]) {
50
+ const fieldName = decl.children.variableDeclaratorId[0].children.Identifier[0].image;
51
+ console.log(indent + " Field:", fieldName);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ const visitor = new TestVisitor();
59
+ visitor.visit(cst);