Error generating summary and description with use_go_templates=true

Author: tombrachoCreated Mar 4, 2025Updated Sep 28, 2026

Documentation

Hello! First of all, thanks for your awesome plugin!

I'm trying to generate summary and description using information from the documentation: customizing_openapi_output.md#using-go-templates-in-proto-file-comments

However, after generating OpenAPI v2 documentation, part of the description is incorrectly included in the summary field.

Expected behavior:

  • The summary field should contain only the method name or the first line of the annotation.
  • The description field should include the detailed method explanation and Markdown tables.

Actual behavior:

  • summary contains too much information, including: ** Repeated method name. ** Full method description. ** Markdown tables (imported from tables.md).
  • description is incomplete and missing part of the intended content.

Example of Incorrect Output:

json
  "paths": {
    "/api/volunteering/event/{id}": {
      "get": {
        "summary": "GetEvent\r\n\r\nGetEvent is a call with the method(s) GET within the \"VolunteeringHttp\" service.\r\nIt takes in \"EventId\" and returns a \"Event\".\r\n\r\n## EventId\n| Field ID    | Name      | Type                                                       | Description                  |\n| ----------- | --------- | ---------------------------------------------------------  | ---------------------------- | \n| 1 | id | TYPE_INT32 |  |",
        "description": "## Event\n| Field ID    | Name      | Type                                                       | Description                  |\n| ----------- | --------- | ---------------------------------------------------------- | ---------------------------- | \n| 1 | id | TYPE_INT32 |  | \n| 2 | creator_id | TYPE_INT32 |  | \n| 3 | title | TYPE_STRING | Заголовки | \n| 4 | og_title | TYPE_STRING |  | \n| 5 | description | TYPE_STRING | Описание | \n| 6 | og_description | TYPE_STRING |  | \n| 7 | content | TYPE_STRING | Контент | \n| 8 | address | TYPE_STRING | Адрес и город | \n| 9 | city | TYPE_INT32 |  | \n| 10 | organization_id | TYPE_INT32 | Идентификатор организации | \n| 11 | is_published | TYPE_BOOL |  | \n| 12 | eventDays | []TYPE_MESSAGE | Дни проведения эвента | \n| 13 | images | TYPE_MESSAGE | Изображения эвента | \n| 14 | directionIds | []TYPE_INT32 | Направления (идентификаторы) |",
        "operationId": "VolunteeringHttp_GetEvent",
    }
  }
}
Image

Configuration:

buf.gen.yaml

yaml
version: v1
plugins:
  - name: go
    out: gen/protos/go
    opt: paths=source_relative
  - name: go-grpc
    out: gen/protos/go
    opt:
      - paths=source_relative
  - name: grpc-gateway
    out: gen/protos/go
    opt:
      - paths=source_relative
  - name: openapiv2
    out: swagger-ui
    opt:
      - allow_merge=true
      - merge_file_name=openapi
      - use_go_templates=true
      - openapi_naming_strategy=simple
      - disable_default_errors=true

And the .proto service definition:

proto
service VolunteeringHttp {
  // GetEvent
  //
  // {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
  // It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
  //
  // {{import "tables.md"}}
  rpc GetEvent(volunteering_service.EventId) returns (volunteering_service.Event) {
    option (google.api.http) = {
      get: "/api/volunteering/event/{id}"
    };
  }
}

And the tables.md

## {{.RequestType.Name}}
| Field ID    | Name      | Type                                                       | Description                  |
| ----------- | --------- | ---------------------------------------------------------  | ---------------------------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}

## {{.ResponseType.Name}}
| Field ID    | Name      | Type                                                       | Description                  |
| ----------- | --------- | ---------------------------------------------------------- | ---------------------------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}

Source: grpc-ecosystem/grpc-gateway