From b2d1c1599dd97000ba0a87d7e49712f2235cc2f4 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Thu, 6 Aug 2026 00:08:42 +0000 Subject: [PATCH] fix: operationId must be unique Signed-off-by: Shane Loretz --- .../examples/tests/additional_bindings/openapi.yaml | 2 +- cmd/protoc-gen-openapi/generator/generator.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml index 15c32d3e..41ce71ae 100644 --- a/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml @@ -10,7 +10,7 @@ paths: patch: tags: - Messaging - operationId: Messaging_UpdateMessage + operationId: Messaging_UpdateMessage_2 requestBody: content: application/json: diff --git a/cmd/protoc-gen-openapi/generator/generator.go b/cmd/protoc-gen-openapi/generator/generator.go index e548ab21..1c79f970 100644 --- a/cmd/protoc-gen-openapi/generator/generator.go +++ b/cmd/protoc-gen-openapi/generator/generator.go @@ -719,7 +719,7 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr rules = append(rules, rule.AdditionalBindings...) } - for _, rule := range rules { + for i, rule := range rules { var path string var methodName string var body string @@ -748,10 +748,15 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr } if methodName != "" { + opID := operationID + if i > 0 { + // operationId must be unique (OpenAPI v3.0.3 4.7.10.1) + opID = fmt.Sprintf("%s_%d", operationID, i+1) + } defaultHost := proto.GetExtension(service.Desc.Options(), annotations.E_DefaultHost).(string) op, path2 := g.buildOperationV3( - d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage) + d, opID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage) // Merge any `Operation` annotations with the current extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation)