Эх сурвалжийг харах

feat(generator): 支持处理 HEAD、OPTIONS 和 TRACE HTTP 方法

新增对 HEAD、OPTIONS 和 TRACE 方法的服务器地址收集与路径项绑定逻辑,确保这些方法在生成 OpenAPI 规范时能正确继承或清除服务器配置。同时,
完善了 HTTP 规则中 PATCH 和自定义方法的处理流程。
dcsunny 1 сар өмнө
parent
commit
51392021ec
1 өөрчлөгдсөн 33 нэмэгдсэн , 0 устгасан
  1. 33 0
      generator/generator.go

+ 33 - 0
generator/generator.go

@@ -192,6 +192,18 @@ func (g *OpenAPIv3Generator) buildDocumentV3() *v3.Document {
 			servers = appendUnique(servers, path.Value.Patch.Servers[0].Url)
 			allServers = appendUnique(servers, path.Value.Patch.Servers[0].Url)
 		}
+		if path.Value.Head != nil && len(path.Value.Head.Servers) == 1 {
+			servers = appendUnique(servers, path.Value.Head.Servers[0].Url)
+			allServers = appendUnique(servers, path.Value.Head.Servers[0].Url)
+		}
+		if path.Value.Options != nil && len(path.Value.Options.Servers) == 1 {
+			servers = appendUnique(servers, path.Value.Options.Servers[0].Url)
+			allServers = appendUnique(servers, path.Value.Options.Servers[0].Url)
+		}
+		if path.Value.Trace != nil && len(path.Value.Trace.Servers) == 1 {
+			servers = appendUnique(servers, path.Value.Trace.Servers[0].Url)
+			allServers = appendUnique(servers, path.Value.Trace.Servers[0].Url)
+		}
 
 		if len(servers) == 1 {
 			path.Value.Servers = []*v3.Server{{Url: servers[0]}}
@@ -211,6 +223,15 @@ func (g *OpenAPIv3Generator) buildDocumentV3() *v3.Document {
 			if path.Value.Patch != nil {
 				path.Value.Patch.Servers = nil
 			}
+			if path.Value.Head != nil {
+				path.Value.Head.Servers = nil
+			}
+			if path.Value.Options != nil {
+				path.Value.Options.Servers = nil
+			}
+			if path.Value.Trace != nil {
+				path.Value.Trace.Servers = nil
+			}
 		}
 	}
 
@@ -707,6 +728,12 @@ func (g *OpenAPIv3Generator) addOperationToDocumentV3(d *v3.Document, op *v3.Ope
 		selectedPathItem.Value.Delete = op
 	case "PATCH":
 		selectedPathItem.Value.Patch = op
+	case http2.MethodHead:
+		selectedPathItem.Value.Head = op
+	case http2.MethodOptions:
+		selectedPathItem.Value.Options = op
+	case http2.MethodTrace:
+		selectedPathItem.Value.Trace = op
 	}
 }
 
@@ -746,6 +773,12 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr
 			case *annotations.HttpRule_Put:
 				path = httpRule.Put
 				httpMethod = http2.MethodPut
+			case *annotations.HttpRule_Patch:
+				path = httpRule.Patch
+				httpMethod = http2.MethodPatch
+			case *annotations.HttpRule_Custom:
+				path = httpRule.Custom.Path
+				httpMethod = httpRule.Custom.Kind
 			}
 			if path == "" {
 				path = fmt.Sprintf("/api/%s/%s", service.Desc.FullName(), method.GoName)