Skip to content

Commit

Permalink
(fix) remove internal comments from generated protoComments (#3864)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiambogo authored Jan 9, 2024
1 parent 637af10 commit 3ac68b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,7 @@ func protoComments(reg *descriptor.Registry, file *descriptor.File, outers []str
// - trim every line only if that is the case
// - join by \n
comments = strings.ReplaceAll(comments, "\n ", "\n")
comments = removeInternalComments(comments)
}
if loc.TrailingComments != nil {
trailing := strings.TrimSpace(*loc.TrailingComments)
Expand Down
30 changes: 30 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10473,6 +10473,36 @@ func TestUpdatePaths(t *testing.T) {
}
}

// Test that enum values have internal comments removed
func TestEnumValueProtoComments(t *testing.T) {
reg := descriptor.NewRegistry()
name := "kind"
comments := "(-- this is a comment --)"

enum := &descriptor.Enum{
EnumDescriptorProto: &descriptorpb.EnumDescriptorProto{
Name: &name,
},
File: &descriptor.File{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: new(string),
Package: new(string),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{
Location: []*descriptorpb.SourceCodeInfo_Location{
&descriptorpb.SourceCodeInfo_Location{
LeadingComments: &comments,
},
},
},
},
},
}
comments = enumValueProtoComments(reg, enum)
if comments != "" {
t.Errorf("expected '', got '%v'", comments)
}
}

func MustMarshal(v interface{}) []byte {
b, err := json.Marshal(v)
if err != nil {
Expand Down

0 comments on commit 3ac68b2

Please sign in to comment.