Skip to content

Commit

Permalink
fix(hz): resolve typedef panic for thrift (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF authored May 5, 2023
1 parent 9d0b519 commit 7710e71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/hz/testdata/thrift/psm.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ struct MultiDefaultReq {
24: required common.CommonType IsDepCommonTypeReq = {"IsCommonString":"fffffff", "TTT":"ttt", "HHH":true, "GGG": {"AAA":"test","BBB":32}};
}

typedef map<string, string> IsTypedefContainer

service Hertz {
Resp Method1(1: MultiTypeReq request) (api.get="/company/department/group/user:id/name", api.handler_path="v1");
Resp Method2(1: MultiTagReq request) (api.post="/company/department/group/user:id/sex", api.handler_path="v1");
Expand All @@ -114,4 +116,7 @@ service Hertz {
Resp Method6(1: MultiTagReq request) (api.head="/school/class/student/number", api.handler_path="v2");
Resp Method7(1: MultiTagReq request) (api.patch="/school/class/student/sex", api.handler_path="v2");
Resp Method8(1: BaseType request) (api.any="/school/class/student/grade/*subjects", api.handler_path="v2");

Resp Method9(1: IsTypedefContainer request) (api.get="/typedef/container", api.handler_path="v2");
Resp Method10(1: map<string, string> request) (api.get="/container", api.handler_path="v2");
}
8 changes: 8 additions & 0 deletions cmd/hz/thrift/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ func (resolver *Resolver) ResolveIdentifier(id string) (ret ResolvedSymbol, err
}

func (resolver *Resolver) ResolveTypeName(typ *parser.Type) (string, error) {
if typ.GetIsTypedef() {
rt, err := resolver.ResolveIdentifier(typ.GetName())
if err != nil {
return "", err
}

return rt.Expression(), nil
}
switch typ.GetCategory() {
case parser.Category_Map:
keyType, err := resolver.ResolveTypeName(typ.GetKeyType())
Expand Down

0 comments on commit 7710e71

Please sign in to comment.