Skip to content

Commit

Permalink
add: swagger对象引用只能是query
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed Jul 7, 2023
1 parent 100a438 commit eef90f3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions console/commands/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr
if protocMessage == nil {
return got
}
in := "query"
switch method {
case "http.Get":
default:
in = "formData"
}
for _, option := range protocMessage.Attr {
doc, isRequired := filterRequired(option.Doc)
doc = getTitle(doc)
Expand All @@ -297,7 +303,7 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr
Description: doc,
Enum: nil,
Format: option.Ty,
In: "query",
In: in,
Required: isRequired,
Items: &openapi.Schema{
Description: doc,
Expand All @@ -313,7 +319,7 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr
Name: option.Name,
Description: doc,
Type: "array",
In: "query",
In: in,
Required: isRequired,
Items: &openapi.Schema{
Ref: getRef(pge, option.Ty),
Expand All @@ -327,7 +333,7 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr
} else if isProtoBaseType(option.Ty) {
attr := &openapi.Parameter{
Name: option.Name,
In: "query",
In: in,
Description: doc,
Type: getProtoToSwagger(option.Ty),
Format: option.Ty,
Expand All @@ -341,7 +347,7 @@ func messageToParameters(method string, message string, nowDirProtoc []parser.Pr
Description: doc,
Type: getProtoToSwagger(option.Ty),
Format: option.Ty,
In: "query",
In: "query", // 对象引用只能是query, 不然页面显示错误
Required: isRequired,
Schema: &openapi.Schema{
Type: "object",
Expand Down Expand Up @@ -489,7 +495,7 @@ func getProtoToSwagger(t string) string {
if ok {
return ty
}
return "string"
return "object"
}

func getPrefix(path, s string) string {
Expand Down

0 comments on commit eef90f3

Please sign in to comment.