Commit 5fbaad1
authored
feat: add go-zero framework support (#8)
* docs: add go-zero framework support design and implementation plan
- Design doc with architecture and component details
- Implementation plan with 9 tasks (including goctl bug patches)
- Bug fixes for goctl issues #5426, #5427, #5428
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(gozero): add go-zero extractor package stubs
Add initial package structure for go-zero framework support:
- detector.go: Project detection with go.mod parsing (placeholder)
- generator.go: OpenAPI spec generation via goctl (placeholder)
- patcher.go: Project patching for goctl compatibility (placeholder)
- gozero.go: Constants for build tool and goctl versions
- Test files for all components verifying instantiation
Task: Task 1 - Create gozero package structure
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(gozero): implement Detector with go.mod and .api file detection
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(extractor): extend ProjectInfo with go-zero fields
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(gozero): implement Patcher with goctl version check
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix(gozero): patch goctl swagger generation bugs (#5426-5428)
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix(gozero): add API file patcher for goctl bug #5425
- Detect and patch unquoted multi-hyphen prefix values in .api files
- Automatically wrap values in quotes before passing to goctl
- Cleanup patched files after swagger generation
- Add ValidateAPIFile for manual validation with helpful error messages
Signed-off-by: spencercjh <spencercjh@gmail.com>
* test(gozero): update demo API to match Spring Boot demo
Add user.api with equivalent endpoints:
- GET /users/:id - Get user by ID
- GET /users - List users with pagination
- POST /users - Create user
- POST /users/upload - Upload file
- POST /users/:id/profile - Update profile
Includes all DTOs: User, ApiResponse, PageResult, FileUploadResult
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix(gozero): resolve all linter issues (gci, gocritic, gosec, govet, modernize, perfsprint)
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(extractor): add framework registration mechanism
Add Extractor interface and global registry for framework plugins.
Each framework (spring, gozero) registers itself via init().
Generate command now loops through all registered extractors.
- Add Extractor interface in internal/extractor/types.go
- Add Register/Get/GetAll/DetectFramework functions
- Add PatchResult type for uniform patch results
- Implement Extractor for spring package
- Implement Extractor for gozero package
- Update generate.go to use registration mechanism
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(extractor): use Framework constants in detectors
Use FrameworkSpringBoot and FrameworkGoZero constants when setting
ProjectInfo.Framework in both spring and gozero detectors.
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(extractor): compose ProjectInfo with framework-specific structs
Split ProjectInfo into common fields and framework-specific sub-structs:
- ProjectInfo: Framework, BuildTool, BuildFilePath
- SpringInfo: Spring Boot specific fields (HasSpringdocDeps, IsMultiModule, etc.)
- GoZeroInfo: go-zero specific fields (HasGoZeroDeps, HasGoctl, APIFiles, etc.)
This eliminates field pollution and makes the data model cleaner.
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor: decouple extractor types and move registration to builtin package
- Create internal/extractor/builtin/ package with registry
- Move SpringInfo to spring package as Info struct
- Move GoZeroInfo to gozero package as Info struct
- Change ProjectInfo.FrameworkData to 'any' type for framework-specific data
- Update all type assertions to use local Info types
- Remove empty init() functions from generator files
- Update all test files to use new type structure
- Fix linter issues (errcheck, govet shadowing)
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor: move framework constants to framework-specific packages
- Add FrameworkGoZero constant to gozero package
- Add FrameworkSpringBoot constant to spring package
- Update detectors to use local framework constants
- Remove framework constants from extractor/types.go
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(gozero): remove duplicate ProjectInfo struct
- Remove ProjectInfo from gozero.go (duplicate of Info in info.go)
- Update NeedsPatch to use *Info instead of *ProjectInfo
- Update test to use *Info
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(gozero): use golang.org/x/mod/modfile to parse go.mod
- Replace manual scanner-based parsing with modfile.Parse
- Remove parseRequireLine helper function
- Simplify parseGoMod logic using modfile API
- Update go.mod dependency
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix: address PR #8 review feedback
- Remove empty const block from types.go
- Add ErrNotGoZeroProject custom error type for better error handling
- Fix detector to reject projects without go-zero deps or .api files
- Use exact module path match for go-zero dependency
- Fix generator to respect OutputDir option
- Add nil checks in swagger_patch.go to prevent panics
- Update tests to use errors.As for error type checking
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat: add comprehensive logging to go-zero extractor
- Add debug/info/warn/error logging to detector for detection flow
- Add logging to patcher for goctl availability check
- Add logging to generator for swagger generation and conversion
- Add logging to api_patch for file patching operations
- Add logging to swagger_patch for document patching
- Enhance builtin.DetectFramework logging with detailed progress
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(spring): reduce cyclomatic complexity of patchGradle function
Signed-off-by: spencercjh <spencercjh@gmail.com>
* feat(gozero-demo): generate complete go-zero framework code with goctl
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix(go-zero): fix goctl swagger output path and add missing path params
- Fix goctl swagger filename extension (.json auto-added by goctl)
- Add -dir flag to specify output directory
- Add missing path params when converting Swagger to OpenAPI 3
- Remove old goctl-openapi.json and add new openapi.yaml output
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
* style(go-zero): fix lint issues and format gozero demo code
- Combine append calls in generator.go (gocritic appendCombine)
- Remove unnecessary blank lines in gozero demo imports
- Fix bare return statements to explicit returns
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
* refactor(executor): decouple executor from specific tools
- Remove Hint field from CommandNotFoundError
- Remove getInstallHint function from executor package
- Move install hints to each caller (spring, publisher)
- Update tests to remove Hint field references
- Add nolint comments for errors.AsType calls
This eliminates coupling between executor package and specific tools
like mvn, gradle, rdme, goctl.
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
* fix: address all remaining PR #8 review comments
1. spring/patcher.go: Fix error handling in Gradle patch helpers
- addGradleDependencyIfNeeded now returns (string, error)
- addGradlePluginIfNeeded now returns (string, error)
- Errors are propagated instead of silently ignored
2. gozero/generator.go: Fix api directory matching
- Change strings.HasPrefix(relPath, "api") to strings.HasPrefix(normalizedPath, "api/")
- Prevents matching directories like "api2/"
3. gozero/generator.go: Fix patched files logging
- Use apiPatcher.HasPatchedFiles() instead of len(patchedFiles)
- Only logs when files are actually modified
4. gozero/detector.go: Fix vendor directory check
- Change strings.Contains(path, "vendor") to info.Name() == "vendor"
- Prevents skipping unrelated directories like "myvendor"
5. gozero/detector.go: Fix goctl PATH check
- Remove os.Stat("goctl") which only checks current directory
- Now relies solely on exec.LookPath for proper PATH lookup
6. gozero/swagger_patch.go: Fix path parameter regex
- Change from \w+ to [^\}]+ to support hyphens in param names
- Now supports paths like /users/{user-id}
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
---------
Signed-off-by: spencercjh <spencercjh@gmail.com>
Signed-off-by: Claude <noreply@anthropic.com>1 parent fa3f248 commit 5fbaad1
51 files changed
Lines changed: 6300 additions & 166 deletions
File tree
- cmd
- docs/plans
- integration-tests/gozero-demo
- api
- etc
- internal
- config
- handler
- logic
- svc
- types
- openapi
- internal
- executor
- extractor
- builtin
- gozero
- spring
- publisher
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 73 | + | |
| 74 | + | |
76 | 75 | | |
77 | | - | |
| 76 | + | |
78 | 77 | | |
79 | 78 | | |
80 | 79 | | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
87 | | - | |
88 | 86 | | |
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
92 | | - | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | 95 | | |
98 | | - | |
| 96 | + | |
99 | 97 | | |
100 | 98 | | |
101 | | - | |
| 99 | + | |
102 | 100 | | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
109 | | - | |
110 | | - | |
| 107 | + | |
| 108 | + | |
111 | 109 | | |
112 | | - | |
113 | | - | |
| 110 | + | |
| 111 | + | |
114 | 112 | | |
115 | | - | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
120 | | - | |
121 | 118 | | |
122 | 119 | | |
123 | 120 | | |
| |||
132 | 129 | | |
133 | 130 | | |
134 | 131 | | |
135 | | - | |
| 132 | + | |
136 | 133 | | |
137 | 134 | | |
138 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | 67 | | |
69 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
70 | 76 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
80 | | - | |
81 | | - | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | | - | |
| 92 | + | |
87 | 93 | | |
88 | 94 | | |
89 | 95 | | |
| |||
0 commit comments