Conversation
ljluestc
force-pushed
the
feat/support-x-extension-swagger
branch
from
August 23, 2026 22:48
2cea78a to
3d73395
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(api/swagger): 在
.api文件中支持自定义x-扩展字段并生成 Swagger关联 issue:go-zero/go-zero#5628
摘要
本改动让 API 作者可以直接在
.api文件里声明自定义 Swagger 扩展字段(x-*),语法是在路由的@handler之前添加@x-<key>注解:生成的 Swagger JSON 会在 operation 上带上这些扩展字段:
改动内容
tools/goctl/pkg/parser/api/scanner/scanner.go):识别@x-<key>词法单元。tools/goctl/pkg/parser/api/token/token.go、tools/goctl/pkg/parser/api/ast/servicestatement.go):新增AT_Xtoken 类型,以及AtXStmt/AtXAnnotationsAST 节点。tools/goctl/pkg/parser/api/parser/parser.go):在@handler前解析零个或多个@x-*注解,并在ParseForUintTest中暴露该能力。tools/goctl/pkg/parser/api/parser/analyzer.go、tools/goctl/api/spec/spec.go):将注解写入spec.Route.Extensions,并移除一处重复的@doc转换。tools/goctl/api/swagger/swagger.go、tools/goctl/api/swagger/path.go):将扩展值解析为布尔值、数字、字符串或 JSON 数组/对象,并写入spec.Operation.Extensions。tools/goctl/pkg/parser/api/parser/parser_test.go、tools/goctl/api/swagger/swagger_test.go):覆盖独立@x-*解析、service 级解析以及端到端 Swagger 生成,包括字符串、布尔、数字、JSON 数组/对象等取值。扩展字段值解析规则
按以下顺序解析值:
true/false)。30、3.14)。验证
所有测试通过,构建成功。