Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed Oct 19, 2023
2 parents 6bc2c19 + 6fb2f68 commit 04a8db9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. 有 go 环境安装
````shell
go install github.com/go-home-admin/toolset
go install github.com/go-home-admin/toolset@latest
````

2. 直接下载二进制文件, 放到任意 path 包含的路径下
Expand Down
9 changes: 8 additions & 1 deletion console/commands/orm/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,16 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships
}
}
}
str += "\n}\n\n"
// 声明表字段
str += "var (\n"
for _, column := range columns {
str += fmt.Sprintf("{TableName}Field%s = \"%s\"\n", parser.StringToHump(column.COLUMN_NAME), column.COLUMN_NAME)
}
str += ")"

str = strings.ReplaceAll(str, "{TableName}", TableName)
return "\n" + str + "\n}"
return "\n" + str + "\n"
}

func genGormTag(column tableColumn) string {
Expand Down
9 changes: 8 additions & 1 deletion console/commands/pgorm/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,16 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships
}
}
}
str += "\n}\n\n"
// 声明表字段
str += "var (\n"
for _, column := range columns {
str += fmt.Sprintf("{TableName}Field%s = \"%s\"\n", parser.StringToHump(column.ColumnName), column.ColumnName)
}
str += ")"

str = strings.ReplaceAll(str, "{TableName}", TableName)
return "\n" + str + "\n}"
return "\n" + str + "\n"
}

func genGormTag(column tableColumn) string {
Expand Down
30 changes: 23 additions & 7 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 @@ -187,9 +198,8 @@ func rpcToPath(pge string, service parser.ServiceRpc, swagger *openapi.Spec, now
endpoint := &openapi.Endpoint{}
switch option.Key {
case "http.Get", "http.Put", "http.Post", "http.Patch", "http.Delete":
service.Doc = filterTag(service.Doc)
endpoint.Description = service.Doc + option.Doc
endpoint.Summary = service.Doc + option.Doc
endpoint.Summary = filterTag(service.Doc) + option.Doc
endpoint.Tags = strings.Split(pge, ".")
endpoint.Parameters = messageToParameters(option.Key, service.Param, nowDirProtoc, allProtoc)
endpoint.Responses = map[string]*openapi.Response{
Expand Down Expand Up @@ -286,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 @@ -366,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 All @@ -387,7 +401,8 @@ func messageToSchemas(pge string, message parser.Message, swagger *openapi.Spec)
if isProtoBaseType(option.Ty) {
// 基础类型的数组
attr := &openapi.Schema{
Type: "array",
Type: "array",
Description: doc,
Items: &openapi.Schema{
Description: doc,
Type: getProtoToSwagger(option.Ty),
Expand All @@ -407,7 +422,8 @@ func messageToSchemas(pge string, message parser.Message, swagger *openapi.Spec)
} else {
// 引用其他对象
attr := &openapi.Schema{
Type: "array",
Type: "array",
Description: doc,
Items: &openapi.Schema{
Ref: getRef(pge, option.Ty),
Description: doc,
Expand Down

0 comments on commit 04a8db9

Please sign in to comment.