fix(goctl): allow duplicate_path_expression under different prefix (#4626)

This commit is contained in:
youzipi
2025-02-07 16:37:11 +08:00
committed by GitHub
parent 396393b336
commit e347d3f8f8
6 changed files with 171 additions and 78 deletions

View File

@@ -13,8 +13,8 @@ import (
)
const (
atServerGroupKey = "group:"
atServerPrefixKey = "prefix:"
atServerGroupKey = "group"
atServerPrefixKey = "prefix"
)
// API is the parsed api file.
@@ -38,18 +38,24 @@ func convert2API(a *ast.AST, importSet map[string]lang.PlaceholderType, is *impo
syntax, ok := one.(*ast.SyntaxStmt)
if !ok {
syntax = &ast.SyntaxStmt{
Syntax: ast.NewTokenNode(token.Token{
Type: token.IDENT,
Text: token.Syntax,
}),
Assign: ast.NewTokenNode(token.Token{
Type: token.ASSIGN,
Text: "=",
}),
Value: ast.NewTokenNode(token.Token{
Type: token.STRING,
Text: `"v1"`,
}),
Syntax: ast.NewTokenNode(
token.Token{
Type: token.IDENT,
Text: token.Syntax,
},
),
Assign: ast.NewTokenNode(
token.Token{
Type: token.ASSIGN,
Text: "=",
},
),
Value: ast.NewTokenNode(
token.Token{
Type: token.STRING,
Text: `"v1"`,
},
),
}
}
@@ -133,10 +139,14 @@ func (api *API) checkServiceStmt() error {
for _, item := range v.Routes {
handlerChecker.checkNodeWithPrefix(group, item.AtHandler.Name)
path := fmt.Sprintf("[%s]:%s", prefix, item.Route.Format(""))
pathChecker.check(ast.NewTokenNode(token.Token{
Text: path,
Position: item.Route.Pos(),
}))
pathChecker.check(
ast.NewTokenNode(
token.Token{
Text: path,
Position: item.Route.Pos(),
},
),
)
}
}
return f.error()
@@ -237,7 +247,8 @@ func (api *API) getAtServerValue(atServer *ast.AtServerStmt, key string) string
func (api *API) mergeAPI(in *API) error {
if api.Syntax.Value.Format() != in.Syntax.Value.Format() {
return ast.SyntaxError(in.Syntax.Value.Pos(),
return ast.SyntaxError(
in.Syntax.Value.Pos(),
"multiple syntax value expression, expected <%s>, got <%s>",
api.Syntax.Value.Format(),
in.Syntax.Value.Format(),