diff --git a/protoc-gen-openapiv2/internal/genopenapi/template.go b/protoc-gen-openapiv2/internal/genopenapi/template.go index 7b0ac902e5d..d073666d8af 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -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) diff --git a/protoc-gen-openapiv2/internal/genopenapi/template_test.go b/protoc-gen-openapiv2/internal/genopenapi/template_test.go index 53c1e559eb6..0be48cde805 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template_test.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template_test.go @@ -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 {