Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hz): compatible name conflict #1206

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/hz/thrift/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func astToService(ast *parser.Thrift, resolver *Resolver, args *config.Argument)
out := make([]*generator.Service, 0, len(ss))
var models model.Models
extendServices := getExtendServices(ast)
isCompatibleName := isCompatibleName(args)
for _, s := range ss {
// if the service is extended, it is not processed
if extendServices.exist(s.Name) && args.EnableExtends {
Expand Down Expand Up @@ -152,6 +153,9 @@ func astToService(ast *parser.Thrift, resolver *Resolver, args *config.Argument)
reqPackage = names[0]
}
}
if isCompatibleName && hasCompatibleNameCondition(reqRawName) {
reqName = reqName + "_"
}
var respName, respRawName, respPackage string
if !m.Oneway {
var err error
Expand All @@ -170,6 +174,9 @@ func astToService(ast *parser.Thrift, resolver *Resolver, args *config.Argument)
respPackage = names[0]
}
}
if isCompatibleName && hasCompatibleNameCondition(respRawName) {
respName = respName + "_"
}

sr, _ := util.GetFirstKV(getAnnotations(m.Annotations, SerializerTags))
method := &generator.HttpMethod{
Expand Down Expand Up @@ -244,6 +251,24 @@ func newHTTPMethod(s *parser.Service, m *parser.Function, method *generator.Http
return &newMethod, nil
}

func isCompatibleName(args *config.Argument) bool {
for _, t := range args.ThriftOptions {
if strings.EqualFold(t, "compatible_names=true") {
return true
}
}

return false
}

func hasCompatibleNameCondition(name string) bool {
if strings.HasPrefix(name, "New") || strings.HasSuffix(name, "Args") || strings.HasSuffix(name, "Result") {
return true
}

return false
}

func parseAnnotationToClient(clientMethod *generator.ClientMethod, p *parser.Type, symbol ResolvedSymbol) error {
if p == nil {
return fmt.Errorf("get type failed for parse annotatoon to client")
Expand Down
Loading