feat: Support projectPkg template variables in config, handler, logic, main, and svc template files (#4939)

This commit is contained in:
geekeryy
2025-08-19 20:29:41 +08:00
committed by GitHub
parent 20d20ef861
commit 73d6fcfccd
11 changed files with 42 additions and 34 deletions

View File

@@ -15,7 +15,7 @@ import (
//go:embed handler_test.tpl
var handlerTestTemplate string
func genHandlerTest(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
func genHandlerTest(dir, rootPkg, projectPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
handler := getHandlerName(route)
handlerPath := getHandlerFolderPath(group, route)
pkgName := handlerPath[strings.LastIndex(handlerPath, "/")+1:]
@@ -50,14 +50,15 @@ func genHandlerTest(dir, rootPkg string, cfg *config.Config, group spec.Group, r
"HasRequest": len(route.RequestTypeName()) > 0,
"HasDoc": len(route.JoinedDoc()) > 0,
"Doc": getDoc(route.JoinedDoc()),
"projectPkg": projectPkg,
},
})
}
func genHandlersTest(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
func genHandlersTest(dir, rootPkg, projectPkg string, cfg *config.Config, api *spec.ApiSpec) error {
for _, group := range api.Service.Groups {
for _, route := range group.Routes {
if err := genHandlerTest(dir, rootPkg, cfg, group, route); err != nil {
if err := genHandlerTest(dir, rootPkg, projectPkg, cfg, group, route); err != nil {
return err
}
}