Spec Forge supports generating OpenAPI specs from go-zero projects.
- Detection: Parses
go.modto detect go-zero dependency and locate API definition files (.apifiles) - Patching: Checks for
goctlinstallation- For goctl < 1.9.2: Patches multi-hyphen prefix values to avoid parsing errors (issue #5425)
- For goctl >= 1.9.2: Skips patching (issue fixed upstream)
- Generation: Uses
goctl api swaggercommand to generate the OpenAPI spec - Post-processing: Fixes generated Swagger issues
- Adds missing
itemsfield for array types (issue #5426) - Removes invalid parameters with name "-" (issue #5427)
- Fixes path parameter mismatches (issue #5428)
- Adds missing
- Nested array types:
[][]interface{}generates Swagger without nesteditemsfield (issue #5426)- Workaround: Post-processing adds missing
items: { type: "object" }for each array layer
- Workaround: Post-processing adds missing
- Multi-hyphen prefixes: For goctl < 1.9.2, prefix values like
/api/alert-centerneed quotes- Workaround: Pre-processing wraps unquoted values in quotes for goctl < 1.9.2
- For goctl >= 1.9.2: No patching needed (issue fixed upstream)
The goctl tool must be installed (v1.8.0+, recommended v1.9.2+)
# Install goctl
go install github.com/zeromicro/go-zero/tools/goctl@latest
# Verify installation
goctl --version# Basic generation
spec-forge generate ./my-go-zero-project
# With AI enrichment
spec-forge generate ./my-go-zero-project --language zh