From 605d2ac9ba58234fff0eed12328a52119c22c62b Mon Sep 17 00:00:00 2001 From: aide <1058165620@qq.com> Date: Fri, 7 Mar 2025 16:07:10 +0800 Subject: [PATCH] feat: add summary field to operations from first non-empty comment line - Extract and add the first non-empty line of the comment as the summary - Improve operation description by providing a concise summary --- cmd/protoc-gen-openapi/generator/generator.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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