Skip to content

Commit

Permalink
fix: 修复引用公共构建时,引用名称不正确
Browse files Browse the repository at this point in the history
update: 生成swagger新增参数query,是否强制定义请求参数为query类型
  • Loading branch information
zodial committed Oct 18, 2023
1 parent ada2f0b commit 92435a6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions console/commands/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
// SwaggerCommand @Bean
type SwaggerCommand struct{}

var isQuery bool

func (SwaggerCommand) Configure() command.Configure {
return command.Configure{
Name: "make:swagger",
Expand All @@ -37,6 +39,11 @@ func (SwaggerCommand) Configure() command.Configure {
Description: "生成文件到指定目录",
Default: "@root/web/swagger_gen.json",
},
{
Name: "query",
Description: "是否强制请求参数为query类型",
Default: "false",
},
},
},
}
Expand All @@ -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"},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 92435a6

Please sign in to comment.