feat: add gen api @doc comment to logic handler routes (#3790)

Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
chentong
2024-03-30 19:09:54 +08:00
committed by GitHub
parent cf987295df
commit 8c0bb27136
7 changed files with 54 additions and 41 deletions

View File

@@ -71,6 +71,7 @@ type (
method string
path string
handler string
doc string
}
)
@@ -92,13 +93,24 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
var gbuilder strings.Builder
gbuilder.WriteString("[]rest.Route{")
for _, r := range g.routes {
fmt.Fprintf(&gbuilder, `
{
Method: %s,
Path: "%s",
Handler: %s,
},`,
r.method, r.path, r.handler)
var routeString string
if len(r.doc) > 0 {
routeString = fmt.Sprintf(`
{
%s
Method: %s,
Path: "%s",
Handler: %s,
},`, getDoc(r.doc), r.method, r.path, r.handler)
} else {
routeString = fmt.Sprintf(`
{
Method: %s,
Path: "%s",
Handler: %s,
},`, r.method, r.path, r.handler)
}
fmt.Fprint(&gbuilder, routeString)
}
var jwt string
@@ -239,6 +251,7 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
method: mapping[r.Method],
path: r.Path,
handler: handler,
doc: r.JoinedDoc(),
})
}