Skip to content

Commit

Permalink
fix(hz): sort all pb tags (cloudwego#1139)
Browse files Browse the repository at this point in the history
Signed-off-by: rogerogers <[email protected]>
  • Loading branch information
rogerogers authored Jun 17, 2024
1 parent 9f33fc5 commit 2a16d50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions cmd/hz/protobuf/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ func TestTagGenerate(t *testing.T) {
},
{
Annotation: "form",
GeneratedTag: "protobuf:\"bytes,4,opt,name=FormTag\" json:\"FormTag,omitempty\" form:\"form\"",
GeneratedTag: "protobuf:\"bytes,4,opt,name=FormTag\" form:\"form\" json:\"FormTag,omitempty\"",
},
{
Annotation: "cookie",
GeneratedTag: "protobuf:\"bytes,5,opt,name=CookieTag\" json:\"CookieTag,omitempty\" cookie:\"cookie\"",
GeneratedTag: "protobuf:\"bytes,5,opt,name=CookieTag\" cookie:\"cookie\" json:\"CookieTag,omitempty\"",
},
{
Annotation: "header",
GeneratedTag: "protobuf:\"bytes,6,opt,name=HeaderTag\" json:\"HeaderTag,omitempty\" header:\"header\"",
GeneratedTag: "protobuf:\"bytes,6,opt,name=HeaderTag\" header:\"header\" json:\"HeaderTag,omitempty\"",
},
{
Annotation: "body",
GeneratedTag: "bytes,7,opt,name=BodyTag\" form:\"body\" json:\"body,omitempty\"",
},
{
Annotation: "go.tag",
GeneratedTag: "bytes,8,opt,name=GoTag\" json:\"json\" form:\"form\" goTag:\"tag\" header:\"header\" query:\"query\"",
GeneratedTag: "bytes,8,opt,name=GoTag\" form:\"form\" goTag:\"tag\" header:\"header\" json:\"json\" query:\"query\"",
},
{
Annotation: "vd",
GeneratedTag: "bytes,9,opt,name=VdTag\" json:\"VdTag,omitempty\" form:\"VdTag\" query:\"VdTag\" vd:\"$!='?'\"",
GeneratedTag: "bytes,9,opt,name=VdTag\" form:\"VdTag\" json:\"VdTag,omitempty\" query:\"VdTag\" vd:\"$!='?'\"",
},
{
Annotation: "non",
GeneratedTag: "bytes,10,opt,name=DefaultTag\" json:\"DefaultTag,omitempty\" form:\"DefaultTag\" query:\"DefaultTag\"",
GeneratedTag: "bytes,10,opt,name=DefaultTag\" form:\"DefaultTag\" json:\"DefaultTag,omitempty\" query:\"DefaultTag\"",
},
{
Annotation: "query required",
Expand All @@ -92,11 +92,11 @@ func TestTagGenerate(t *testing.T) {
},
{
Annotation: "go.tag required",
GeneratedTag: "protobuf:\"bytes,15,req,name=ReqGoTag\" query:\"ReqGoTag,required\" form:\"ReqGoTag,required\" json:\"json\"",
GeneratedTag: "protobuf:\"bytes,15,req,name=ReqGoTag\" form:\"ReqGoTag,required\" json:\"json\" query:\"ReqGoTag,required\"",
},
{
Annotation: "go.tag optional",
GeneratedTag: "bytes,16,opt,name=OptGoTag\" query:\"OptGoTag\" form:\"OptGoTag\" json:\"json\"",
GeneratedTag: "bytes,16,opt,name=OptGoTag\" form:\"OptGoTag\" json:\"json\" query:\"OptGoTag\"",
},
{
Annotation: "go tag cover query",
Expand Down
3 changes: 1 addition & 2 deletions cmd/hz/protobuf/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ func injectTagsToStructTags(f protoreflect.FieldDescriptor, out *structTags, nee
tags.Remove(t.Key)
}
}
// protobuf tag as first
sort.Sort(tags[1:])
sort.Sort(tags)
for _, t := range tags {
if disableTag {
*out = append(*out, [2]string{t.Key, "-"})
Expand Down

0 comments on commit 2a16d50

Please sign in to comment.