From 0320d74b3646387ccc2b21d8bf7a547976170767 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Thu, 20 May 2021 18:50:51 +0200 Subject: [PATCH] Fixed incorrect interface nil check in protoc-gen-openapi (#249) 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 --- apps/protoc-gen-openapi/generator/openapi-v3.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/protoc-gen-openapi/generator/openapi-v3.go b/apps/protoc-gen-openapi/generator/openapi-v3.go index f022312..4211c97 100644 --- a/apps/protoc-gen-openapi/generator/openapi-v3.go +++ b/apps/protoc-gen-openapi/generator/openapi-v3.go @@ -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) {