Skip to content

Commit

Permalink
fix: operationID should be unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Adol1111 committed Jul 12, 2023
1 parent 987797b commit 5328483
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ paths:
patch:
tags:
- Messaging
operationId: Messaging_UpdateMessage
operationId: Messaging_UpdateMessage_PATCH_/v1/messages
requestBody:
content:
application/json:
Expand Down
10 changes: 9 additions & 1 deletion cmd/protoc-gen-openapi/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,10 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
rules = append(rules, rule.AdditionalBindings...)
}

count := 0
for _, rule := range rules {
count++

var path string
var methodName string
var body string
Expand Down Expand Up @@ -735,8 +738,13 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
if methodName != "" {
defaultHost := proto.GetExtension(service.Desc.Options(), annotations.E_DefaultHost).(string)

id := operationID
if count > 1 {
id = fmt.Sprintf("%s_%s_%s", id, methodName, path)
}

op, path2 := g.buildOperationV3(
d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage)
d, id, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage)

// Merge any `Operation` annotations with the current
extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation)
Expand Down

0 comments on commit 5328483

Please sign in to comment.