@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,129 @@
1
+ package com.example.api.dto;
2
+
3
+ import javax.validation.constraints.*;
4
+ import java.math.BigDecimal;
5
+ import java.time.LocalDateTime;
6
+ import java.util.List;
7
+
8
+ /**
9
+ * Product Data Transfer Object
10
+ */
11
+ public class ProductDTO {
12
+
13
+ private Long id;
14
+
15
+ @NotBlank
16
+ @Size(min = 2, max = 100)
17
+ private String name;
18
+
19
+ @Size(max = 2000)
20
+ private String description;
21
+
22
+ @NotNull
23
+ @Min(0)
24
+ private BigDecimal price;
25
+
26
+ @Min(0)
27
+ private Integer stockQuantity;
28
+
29
+ private String sku;
30
+
31
+ private String category;
32
+
33
+ private List<String> tags;
34
+
35
+ private Boolean active;
36
+
37
+ private LocalDateTime createdAt;
38
+
39
+ private LocalDateTime updatedAt;
40
+
41
+ // Getters and setters
42
+ public Long getId() {
43
+ return id;
44
+ }
45
+
46
+ public void setId(Long id) {
47
+ this.id = id;
48
+ }
49
+
50
+ public String getName() {
51
+ return name;
52
+ }
53
+
54
+ public void setName(String name) {
55
+ this.name = name;
56
+ }
57
+
58
+ public String getDescription() {
59
+ return description;
60
+ }
61
+
62
+ public void setDescription(String description) {
63
+ this.description = description;
64
+ }
65
+
66
+ public BigDecimal getPrice() {
67
+ return price;
68
+ }
69
+
70
+ public void setPrice(BigDecimal price) {
71
+ this.price = price;
72
+ }
73
+
74
+ public Integer getStockQuantity() {
75
+ return stockQuantity;
76
+ }
77
+
78
+ public void setStockQuantity(Integer stockQuantity) {
79
+ this.stockQuantity = stockQuantity;
80
+ }
81
+
82
+ public String getSku() {
83
+ return sku;
84
+ }
85
+
86
+ public void setSku(String sku) {
87
+ this.sku = sku;
88
+ }
89
+
90
+ public String getCategory() {
91
+ return category;
92
+ }
93
+
94
+ public void setCategory(String category) {
95
+ this.category = category;
96
+ }
97
+
98
+ public List<String> getTags() {
99
+ return tags;
100
+ }
101
+
102
+ public void setTags(List<String> tags) {
103
+ this.tags = tags;
104
+ }
105
+
106
+ public Boolean getActive() {
107
+ return active;
108
+ }
109
+
110
+ public void setActive(Boolean active) {
111
+ this.active = active;
112
+ }
113
+
114
+ public LocalDateTime getCreatedAt() {
115
+ return createdAt;
116
+ }
117
+
118
+ public void setCreatedAt(LocalDateTime createdAt) {
119
+ this.createdAt = createdAt;
120
+ }
121
+
122
+ public LocalDateTime getUpdatedAt() {
123
+ return updatedAt;
124
+ }
125
+
126
+ public void setUpdatedAt(LocalDateTime updatedAt) {
127
+ this.updatedAt = updatedAt;
128
+ }
129
+ }
@@ -0,0 +1,47 @@
1
+ package com.example.api.dto;
2
+
3
+ import java.util.List;
4
+
5
+ /**
6
+ * Role Data Transfer Object
7
+ */
8
+ public class RoleDTO {
9
+
10
+ private Long id;
11
+ private String name;
12
+ private String description;
13
+ private List<String> permissions;
14
+
15
+ // Getters and setters
16
+ public Long getId() {
17
+ return id;
18
+ }
19
+
20
+ public void setId(Long id) {
21
+ this.id = id;
22
+ }
23
+
24
+ public String getName() {
25
+ return name;
26
+ }
27
+
28
+ public void setName(String name) {
29
+ this.name = name;
30
+ }
31
+
32
+ public String getDescription() {
33
+ return description;
34
+ }
35
+
36
+ public void setDescription(String description) {
37
+ this.description = description;
38
+ }
39
+
40
+ public List<String> getPermissions() {
41
+ return permissions;
42
+ }
43
+
44
+ public void setPermissions(List<String> permissions) {
45
+ this.permissions = permissions;
46
+ }
47
+ }
@@ -0,0 +1,55 @@
1
+ package com.example.api.common;
2
+
3
+ /**
4
+ * Search parameters for pagination and filtering
5
+ */
6
+ public class SearchParam {
7
+
8
+ private Integer offset;
9
+ private Integer limit;
10
+ private Filter filter;
11
+ private Sort sort;
12
+
13
+ public SearchParam() {
14
+ this.offset = 0;
15
+ this.limit = 20;
16
+ }
17
+
18
+ public SearchParam(Integer offset, Integer limit) {
19
+ this.offset = offset;
20
+ this.limit = limit;
21
+ }
22
+
23
+ // Getters and setters
24
+ public Integer getOffset() {
25
+ return offset;
26
+ }
27
+
28
+ public void setOffset(Integer offset) {
29
+ this.offset = offset;
30
+ }
31
+
32
+ public Integer getLimit() {
33
+ return limit;
34
+ }
35
+
36
+ public void setLimit(Integer limit) {
37
+ this.limit = limit;
38
+ }
39
+
40
+ public Filter getFilter() {
41
+ return filter;
42
+ }
43
+
44
+ public void setFilter(Filter filter) {
45
+ this.filter = filter;
46
+ }
47
+
48
+ public Sort getSort() {
49
+ return sort;
50
+ }
51
+
52
+ public void setSort(Sort sort) {
53
+ this.sort = sort;
54
+ }
55
+ }
@@ -0,0 +1,70 @@
1
+ package com.example.api.common;
2
+
3
+ /**
4
+ * Sort conditions for search queries
5
+ */
6
+ public class Sort {
7
+
8
+ private String field;
9
+ private Direction direction;
10
+
11
+ public enum Direction {
12
+ ASC,
13
+ DESC
14
+ }
15
+
16
+ public Sort() {
17
+ this.direction = Direction.ASC;
18
+ }
19
+
20
+ public Sort(String field) {
21
+ this.field = field;
22
+ this.direction = Direction.ASC;
23
+ }
24
+
25
+ public Sort(String field, Direction direction) {
26
+ this.field = field;
27
+ this.direction = direction;
28
+ }
29
+
30
+ // Static factory methods
31
+ public static Sort by(String field) {
32
+ return new Sort(field, Direction.ASC);
33
+ }
34
+
35
+ public static Sort asc(String field) {
36
+ return new Sort(field, Direction.ASC);
37
+ }
38
+
39
+ public static Sort desc(String field) {
40
+ return new Sort(field, Direction.DESC);
41
+ }
42
+
43
+ // Getters and setters
44
+ public String getField() {
45
+ return field;
46
+ }
47
+
48
+ public void setField(String field) {
49
+ this.field = field;
50
+ }
51
+
52
+ public Direction getDirection() {
53
+ return direction;
54
+ }
55
+
56
+ public void setDirection(Direction direction) {
57
+ this.direction = direction;
58
+ }
59
+
60
+ // Fluent API
61
+ public Sort ascending() {
62
+ this.direction = Direction.ASC;
63
+ return this;
64
+ }
65
+
66
+ public Sort descending() {
67
+ this.direction = Direction.DESC;
68
+ return this;
69
+ }
70
+ }
@@ -0,0 +1,74 @@
1
+ package com.example.api.dto;
2
+
3
+ import javax.validation.constraints.*;
4
+
5
+ /**
6
+ * Request object for updating an existing user
7
+ */
8
+ public class UpdateUserRequest {
9
+
10
+ @Size(min = 2, max = 50)
11
+ private String firstName;
12
+
13
+ @Size(min = 2, max = 50)
14
+ private String lastName;
15
+
16
+ @Email
17
+ private String email;
18
+
19
+ @Pattern(regexp = "^\\+?[1-9]\\d{1,14}$")
20
+ private String phoneNumber;
21
+
22
+ private Long departmentId;
23
+
24
+ private String status;
25
+
26
+ // Getters and setters
27
+ public String getFirstName() {
28
+ return firstName;
29
+ }
30
+
31
+ public void setFirstName(String firstName) {
32
+ this.firstName = firstName;
33
+ }
34
+
35
+ public String getLastName() {
36
+ return lastName;
37
+ }
38
+
39
+ public void setLastName(String lastName) {
40
+ this.lastName = lastName;
41
+ }
42
+
43
+ public String getEmail() {
44
+ return email;
45
+ }
46
+
47
+ public void setEmail(String email) {
48
+ this.email = email;
49
+ }
50
+
51
+ public String getPhoneNumber() {
52
+ return phoneNumber;
53
+ }
54
+
55
+ public void setPhoneNumber(String phoneNumber) {
56
+ this.phoneNumber = phoneNumber;
57
+ }
58
+
59
+ public Long getDepartmentId() {
60
+ return departmentId;
61
+ }
62
+
63
+ public void setDepartmentId(Long departmentId) {
64
+ this.departmentId = departmentId;
65
+ }
66
+
67
+ public String getStatus() {
68
+ return status;
69
+ }
70
+
71
+ public void setStatus(String status) {
72
+ this.status = status;
73
+ }
74
+ }
@@ -0,0 +1,98 @@
1
+ package com.example.api.controller;
2
+
3
+ import com.example.api.dto.UserDTO;
4
+ import com.example.api.dto.CreateUserRequest;
5
+ import com.example.api.dto.UpdateUserRequest;
6
+ import com.example.api.common.SearchParam;
7
+ import com.example.api.common.PaginatedList;
8
+ import org.springframework.http.ResponseEntity;
9
+ import org.springframework.security.access.prepost.PreAuthorize;
10
+ import org.springframework.web.bind.annotation.*;
11
+
12
+ import javax.validation.Valid;
13
+ import java.util.List;
14
+
15
+ /**
16
+ * User management REST controller
17
+ */
18
+ @RestController
19
+ @RequestMapping("/api/users")
20
+ public class UserController {
21
+
22
+ /**
23
+ * Search users with pagination
24
+ * Uses SearchParam for pagination and filtering
25
+ */
26
+ @GetMapping
27
+ @PreAuthorize("hasRole('USER')")
28
+ public ResponseEntity<PaginatedList<UserDTO>> searchUsers(SearchParam searchParam) {
29
+ // Implementation
30
+ return ResponseEntity.ok(new PaginatedList<>());
31
+ }
32
+
33
+ /**
34
+ * Get user by ID
35
+ */
36
+ @GetMapping("/{id}")
37
+ @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
38
+ public ResponseEntity<UserDTO> getUserById(@PathVariable Long id) {
39
+ // Implementation
40
+ return ResponseEntity.ok(new UserDTO());
41
+ }
42
+
43
+ /**
44
+ * Create new user
45
+ */
46
+ @PostMapping
47
+ @PreAuthorize("hasRole('ADMIN')")
48
+ public ResponseEntity<UserDTO> createUser(@Valid @RequestBody CreateUserRequest request) {
49
+ // Implementation
50
+ return ResponseEntity.ok(new UserDTO());
51
+ }
52
+
53
+ /**
54
+ * Update existing user
55
+ * Complex security: admin can update anyone, users can only update themselves
56
+ */
57
+ @PutMapping("/{id}")
58
+ @PreAuthorize("hasRole('ADMIN') or (#id == authentication.principal.id and hasRole('USER'))")
59
+ public ResponseEntity<UserDTO> updateUser(
60
+ @PathVariable Long id,
61
+ @Valid @RequestBody UpdateUserRequest request) {
62
+ // Implementation
63
+ return ResponseEntity.ok(new UserDTO());
64
+ }
65
+
66
+ /**
67
+ * Delete user
68
+ */
69
+ @DeleteMapping("/{id}")
70
+ @PreAuthorize("hasRole('ADMIN')")
71
+ public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
72
+ // Implementation
73
+ return ResponseEntity.ok().build();
74
+ }
75
+
76
+ /**
77
+ * Get users by department with optional status filter
78
+ */
79
+ @GetMapping("/department/{departmentId}")
80
+ @PreAuthorize("hasAuthority('READ_USERS')")
81
+ public ResponseEntity<List<UserDTO>> getUsersByDepartment(
82
+ @PathVariable Long departmentId,
83
+ @RequestParam(required = false, defaultValue = "ACTIVE") String status,
84
+ @RequestHeader("X-Tenant-ID") String tenantId) {
85
+ // Implementation
86
+ return ResponseEntity.ok(List.of());
87
+ }
88
+
89
+ /**
90
+ * Bulk import users
91
+ */
92
+ @PostMapping("/bulk")
93
+ @PreAuthorize("hasRole('ADMIN') and hasAuthority('BULK_IMPORT')")
94
+ public ResponseEntity<List<UserDTO>> bulkImportUsers(@RequestBody List<CreateUserRequest> requests) {
95
+ // Implementation
96
+ return ResponseEntity.ok(List.of());
97
+ }
98
+ }
@@ -0,0 +1,119 @@
1
+ package com.example.api.dto;
2
+
3
+ import javax.validation.constraints.*;
4
+ import java.time.LocalDateTime;
5
+ import java.util.List;
6
+
7
+ /**
8
+ * User Data Transfer Object
9
+ */
10
+ public class UserDTO {
11
+
12
+ private Long id;
13
+
14
+ @NotBlank
15
+ @Size(min = 2, max = 50)
16
+ private String firstName;
17
+
18
+ @NotBlank
19
+ @Size(min = 2, max = 50)
20
+ private String lastName;
21
+
22
+ @NotBlank
23
+ @Email
24
+ private String email;
25
+
26
+ @Pattern(regexp = "^\\+?[1-9]\\d{1,14}$")
27
+ private String phoneNumber;
28
+
29
+ private String status;
30
+
31
+ private LocalDateTime createdAt;
32
+
33
+ private LocalDateTime updatedAt;
34
+
35
+ private DepartmentDTO department;
36
+
37
+ private List<RoleDTO> roles;
38
+
39
+ // Getters and setters
40
+ public Long getId() {
41
+ return id;
42
+ }
43
+
44
+ public void setId(Long id) {
45
+ this.id = id;
46
+ }
47
+
48
+ public String getFirstName() {
49
+ return firstName;
50
+ }
51
+
52
+ public void setFirstName(String firstName) {
53
+ this.firstName = firstName;
54
+ }
55
+
56
+ public String getLastName() {
57
+ return lastName;
58
+ }
59
+
60
+ public void setLastName(String lastName) {
61
+ this.lastName = lastName;
62
+ }
63
+
64
+ public String getEmail() {
65
+ return email;
66
+ }
67
+
68
+ public void setEmail(String email) {
69
+ this.email = email;
70
+ }
71
+
72
+ public String getPhoneNumber() {
73
+ return phoneNumber;
74
+ }
75
+
76
+ public void setPhoneNumber(String phoneNumber) {
77
+ this.phoneNumber = phoneNumber;
78
+ }
79
+
80
+ public String getStatus() {
81
+ return status;
82
+ }
83
+
84
+ public void setStatus(String status) {
85
+ this.status = status;
86
+ }
87
+
88
+ public LocalDateTime getCreatedAt() {
89
+ return createdAt;
90
+ }
91
+
92
+ public void setCreatedAt(LocalDateTime createdAt) {
93
+ this.createdAt = createdAt;
94
+ }
95
+
96
+ public LocalDateTime getUpdatedAt() {
97
+ return updatedAt;
98
+ }
99
+
100
+ public void setUpdatedAt(LocalDateTime updatedAt) {
101
+ this.updatedAt = updatedAt;
102
+ }
103
+
104
+ public DepartmentDTO getDepartment() {
105
+ return department;
106
+ }
107
+
108
+ public void setDepartment(DepartmentDTO department) {
109
+ this.department = department;
110
+ }
111
+
112
+ public List<RoleDTO> getRoles() {
113
+ return roles;
114
+ }
115
+
116
+ public void setRoles(List<RoleDTO> roles) {
117
+ this.roles = roles;
118
+ }
119
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@g1cloud/api-gen",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool to generate OpenAPI v3 YAML from Spring Boot Java source code",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "api-gen": "./dist/index.js",
8
+ "spring-to-openapi": "./dist/index.js",
9
+ "spring-to-openapi-mcp": "./dist/mcp-server.mjs"
10
+ },
11
+ "keywords": [
12
+ "openapi",
13
+ "swagger",
14
+ "spring-boot",
15
+ "java",
16
+ "api",
17
+ "generator",
18
+ "cli",
19
+ "mcp",
20
+ "model-context-protocol"
21
+ ],
22
+ "author": "G1Cloud",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "@modelcontextprotocol/sdk": "^1.0.0",
26
+ "commander": "^12.1.0",
27
+ "java-parser": "^2.3.2",
28
+ "js-yaml": "^4.1.0",
29
+ "zod": "^3.25"
30
+ },
31
+ "devDependencies": {
32
+ "@types/js-yaml": "^4.0.9",
33
+ "@types/node": "^20.10.0",
34
+ "ts-node": "^10.9.2",
35
+ "tsup": "^8.5.1",
36
+ "tsx": "^4.7.0",
37
+ "typescript": "^5.3.0"
38
+ },
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "bundle": "tsup && chmod +x dist/index.js dist/mcp-server.mjs",
45
+ "start": "node dist/index.js",
46
+ "start:mcp": "node dist/mcp-server.mjs",
47
+ "dev": "ts-node src/index.ts",
48
+ "dev:mcp": "npx tsx src/mcp-server.ts",
49
+ "test": "ts-node src/index.ts --source ./examples --output ./test-output.yaml --title 'Test API' --api-version '1.0.0'"
50
+ }
51
+ }