Skip to content

Commit

Permalink
feat: body 参数文档生成优化
Browse files Browse the repository at this point in the history
  • Loading branch information
GaoShuai committed Sep 3, 2024
1 parent 7a3981a commit a562f91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,21 @@ func genXService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generate
for _, p := range httpParam.UrlParamList {
g.P("// @Param ", p.PName, " path ", p.PType, " true ", `"some id"`)
}
for _, ff := range value.Input.Fields {
query := "query"
if httpParam.MethodName == "POST" || httpParam.MethodName == "PATCH" {
query = "body"
}
fp := utils.ParseFieldLeading(ff)
if len(fp.FTail) > 0 {
g.P("// @Param ", fp.FName, " ", query, " ", fp.FType, " ", fp.FRequired, ` "`, fp.FTail, `" `, fp.GetEnums())
} else {
g.P("// @Param ", fp.FName, " ", query, " ", fp.FType, " ", fp.FRequired, ` "参数无注释" `, fp.GetEnums())

if httpParam.MethodName == "POST" || httpParam.MethodName == "PATCH" {
g.P(`// @Param data body `, value.Input.GoIdent.GoName, ` true "body 参数"`)
} else {
for _, ff := range value.Input.Fields {
query := "query"
if httpParam.MethodName == "POST" || httpParam.MethodName == "PATCH" {
query = "body"
}
fp := utils.ParseFieldLeading(ff)
if len(fp.FTail) > 0 {
g.P("// @Param ", fp.FName, " ", query, " ", fp.FType, " ", fp.FRequired, ` "`, fp.FTail, `" `, fp.GetEnums())
} else {
g.P("// @Param ", fp.FName, " ", query, " ", fp.FType, " ", fp.FRequired, ` "参数无注释" `, fp.GetEnums())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/utils/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

var VERSION = "1.3.3"
var VERSION = "1.3.4"

const DeprecationComment = "// Deprecated: Do not use."
const StringType = "string"
Expand Down

0 comments on commit a562f91

Please sign in to comment.