From 92435a6e4cb0ed24c7702ba12715b24ee48a215a Mon Sep 17 00:00:00 2001 From: Zodial Date: Wed, 18 Oct 2023 11:21:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=9E=84=E5=BB=BA=E6=97=B6=EF=BC=8C=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=90=8D=E7=A7=B0=E4=B8=8D=E6=AD=A3=E7=A1=AE=20update?= =?UTF-8?q?:=20=E7=94=9F=E6=88=90swagger=E6=96=B0=E5=A2=9E=E5=8F=82?= =?UTF-8?q?=E6=95=B0query=EF=BC=8C=E6=98=AF=E5=90=A6=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E4=B8=BA?= =?UTF-8?q?query=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/swagger.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/console/commands/swagger.go b/console/commands/swagger.go index 3cfba71..a6b240b 100644 --- a/console/commands/swagger.go +++ b/console/commands/swagger.go @@ -16,6 +16,8 @@ import ( // SwaggerCommand @Bean type SwaggerCommand struct{} +var isQuery bool + func (SwaggerCommand) Configure() command.Configure { return command.Configure{ Name: "make:swagger", @@ -37,6 +39,11 @@ func (SwaggerCommand) Configure() command.Configure { Description: "生成文件到指定目录", Default: "@root/web/swagger_gen.json", }, + { + Name: "query", + Description: "是否强制请求参数为query类型", + Default: "false", + }, }, }, } @@ -48,6 +55,10 @@ func (SwaggerCommand) Execute(input command.Input) { out := input.GetOption("out") path := input.GetOption("path") + if input.GetOption("query") == "true" || input.GetOption("query") == "1" { + isQuery = true + } + swagger := openapi.Spec{ Swagger: "2.0", Schemes: []string{"http", "https"}, @@ -285,11 +296,14 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr if protocMessage == nil { return got } - in := "query" + in := "formData" switch method { case "http.Get": + in = "query" default: - in = "formData" + if isQuery { + in = "query" + } } for _, option := range protocMessage.Attr { doc, isRequired := filterRequired(option.Doc) @@ -365,7 +379,8 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr func getRef(pge string, ty string) string { arr := strings.Split(ty, ".") if len(arr) == 1 { - return "#/definitions/" + pge + "." + ty + arr = strings.Split(pge, ".") + return "#/definitions/" + arr[len(arr)-1] + "." + ty } return "#/definitions/" + ty