diff --git a/cmd/protoc-gen-openapi/generator/generator.go b/cmd/protoc-gen-openapi/generator/generator.go index e548ab21..582c535b 100644 --- a/cmd/protoc-gen-openapi/generator/generator.go +++ b/cmd/protoc-gen-openapi/generator/generator.go @@ -600,6 +600,7 @@ func (g *OpenAPIv3Generator) buildOperationV3( // Create the operation. op := &v3.Operation{ Tags: []string{tagName}, + Summary: extractSummary(description), Description: description, OperationId: operationID, Parameters: parameters, @@ -668,6 +669,17 @@ func (g *OpenAPIv3Generator) buildOperationV3( return op, path } +func extractSummary(comment string) string { + lines := strings.Split(comment, "\n") + for _, line := range lines { + trimmed := strings.TrimSpace(line) + if trimmed != "" { + return trimmed + } + } + return "" +} + // addOperationToDocumentV3 adds an operation to the specified path/method. func (g *OpenAPIv3Generator) addOperationToDocumentV3(d *v3.Document, op *v3.Operation, path string, methodName string) { var selectedPathItem *v3.NamedPathItem