Browse Source

fix(generator): 显式定义httpRule的没处理对

lihf 6 days ago
parent
commit
2a41e3bdee
1 changed files with 35 additions and 31 deletions
  1. 35 31
      generator/generator.go

+ 35 - 31
generator/generator.go

@@ -752,41 +752,45 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
 			if extOperation == nil || extOperation == v3.E_Operation.InterfaceOf(v3.E_Operation.Zero()) {
 			if extOperation == nil || extOperation == v3.E_Operation.InterfaceOf(v3.E_Operation.Zero()) {
 				continue
 				continue
 			}
 			}
-			httpOperation := proto.GetExtension(method.Desc.Options(), annotations.E_Http)
-			if httpOperation == nil || httpOperation == annotations.E_Http.InterfaceOf(annotations.E_Http.Zero()) {
-				continue
-			}
-			annotationsCount++
-			_httpOperation := httpOperation.(*annotations.HttpRule)
+
 			var path string
 			var path string
 			var httpMethod string
 			var httpMethod string
 			var bodyField string
 			var bodyField string
-			switch httpRule := _httpOperation.GetPattern().(type) {
-			case *annotations.HttpRule_Post:
-				path = httpRule.Post
-				httpMethod = http2.MethodPost
-				bodyField = _httpOperation.GetBody()
-			case *annotations.HttpRule_Get:
-				path = httpRule.Get
-				httpMethod = http2.MethodGet
-				bodyField = ""
-			case *annotations.HttpRule_Delete:
-				path = httpRule.Delete
-				httpMethod = http2.MethodDelete
-				bodyField = ""
-			case *annotations.HttpRule_Put:
-				path = httpRule.Put
-				httpMethod = http2.MethodPut
-				bodyField = _httpOperation.GetBody()
-			case *annotations.HttpRule_Patch:
-				path = httpRule.Patch
-				httpMethod = http2.MethodPatch
-				bodyField = _httpOperation.GetBody()
-			case *annotations.HttpRule_Custom:
-				path = httpRule.Custom.Path
-				httpMethod = httpRule.Custom.Kind
-				bodyField = _httpOperation.GetBody()
+
+			httpOperation := proto.GetExtension(method.Desc.Options(), annotations.E_Http)
+			if httpOperation != nil && httpOperation != annotations.E_Http.InterfaceOf(annotations.E_Http.Zero()) {
+				_httpOperation := httpOperation.(*annotations.HttpRule)
+
+				switch httpRule := _httpOperation.GetPattern().(type) {
+				case *annotations.HttpRule_Post:
+					path = httpRule.Post
+					httpMethod = http2.MethodPost
+					bodyField = _httpOperation.GetBody()
+				case *annotations.HttpRule_Get:
+					path = httpRule.Get
+					httpMethod = http2.MethodGet
+					bodyField = ""
+				case *annotations.HttpRule_Delete:
+					path = httpRule.Delete
+					httpMethod = http2.MethodDelete
+					bodyField = ""
+				case *annotations.HttpRule_Put:
+					path = httpRule.Put
+					httpMethod = http2.MethodPut
+					bodyField = _httpOperation.GetBody()
+				case *annotations.HttpRule_Patch:
+					path = httpRule.Patch
+					httpMethod = http2.MethodPatch
+					bodyField = _httpOperation.GetBody()
+				case *annotations.HttpRule_Custom:
+					path = httpRule.Custom.Path
+					httpMethod = httpRule.Custom.Kind
+					bodyField = _httpOperation.GetBody()
+				}
 			}
 			}
+
+			annotationsCount++
+
 			if path == "" {
 			if path == "" {
 				path = fmt.Sprintf("/api/%s/%s", service.Desc.FullName(), method.GoName)
 				path = fmt.Sprintf("/api/%s/%s", service.Desc.FullName(), method.GoName)
 			}
 			}