Skip to content

Commit

Permalink
Fixed incorrect interface nil check in protoc-gen-openapi (#249)
Browse files Browse the repository at this point in the history
The `annotation` variable is an interface and was only checked for `nil`, but not if `nil` would be assigned to the interface.
This lead to a crash, if a method within a service was not annotated at all.

Closes #248
  • Loading branch information
oxisto authored May 20, 2021
1 parent c686e50 commit 0320d74
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/protoc-gen-openapi/generator/openapi-v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, file *protogen
inputMessage := method.Input
outputMessage := method.Output
operationID := service.GoName + "_" + method.GoName
extension := proto.GetExtension(method.Desc.Options(), annotations.E_Http)
xt := annotations.E_Http
extension := proto.GetExtension(method.Desc.Options(), xt)
var path string
var methodName string
var body string
if extension != nil {
if extension != nil && extension != xt.InterfaceOf(xt.Zero()) {
rule := extension.(*annotations.HttpRule)
body = rule.Body
switch pattern := rule.Pattern.(type) {
Expand Down

0 comments on commit 0320d74

Please sign in to comment.