From 54e32496a6f7e899c0843e19bee0a70ffbb250b3 Mon Sep 17 00:00:00 2001 From: Zodial Date: Fri, 8 Sep 2023 11:00:03 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20ORM=E7=94=9F=E6=88=90=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/orm/mysql.go | 9 ++++++++- console/commands/pgorm/pgsql.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/console/commands/orm/mysql.go b/console/commands/orm/mysql.go index 5df5348..4611351 100644 --- a/console/commands/orm/mysql.go +++ b/console/commands/orm/mysql.go @@ -317,9 +317,16 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships } } } + str += "\n}\n\n" + // 声明表字段 + str += "type {TableName}Field string\nvar (\n" + for _, column := range columns { + str += fmt.Sprintf("{TableName}Field%s {TableName}Field = \"%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 { diff --git a/console/commands/pgorm/pgsql.go b/console/commands/pgorm/pgsql.go index 964017a..fa57ed6 100644 --- a/console/commands/pgorm/pgsql.go +++ b/console/commands/pgorm/pgsql.go @@ -283,9 +283,16 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships } } } + str += "\n}\n\n" + // 声明表字段 + str += "type {TableName}Field string\nvar (\n" + for _, column := range columns { + str += fmt.Sprintf("{TableName}Field%s {TableName}Field = \"%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 { From 361d2cfe2b7ff8452ba09acf386265e44a5bb756 Mon Sep 17 00:00:00 2001 From: Zodial Date: Fri, 8 Sep 2023 12:00:20 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20ORM=E7=94=9F=E6=88=90=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/orm/mysql.go | 4 ++-- console/commands/pgorm/pgsql.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/console/commands/orm/mysql.go b/console/commands/orm/mysql.go index 4611351..f49352d 100644 --- a/console/commands/orm/mysql.go +++ b/console/commands/orm/mysql.go @@ -319,9 +319,9 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships } str += "\n}\n\n" // 声明表字段 - str += "type {TableName}Field string\nvar (\n" + str += "var (\n" for _, column := range columns { - str += fmt.Sprintf("{TableName}Field%s {TableName}Field = \"%s\"\n", parser.StringToHump(column.COLUMN_NAME), column.COLUMN_NAME) + str += fmt.Sprintf("{TableName}Field%s = \"%s\"\n", parser.StringToHump(column.COLUMN_NAME), column.COLUMN_NAME) } str += ")" diff --git a/console/commands/pgorm/pgsql.go b/console/commands/pgorm/pgsql.go index fa57ed6..9a059a2 100644 --- a/console/commands/pgorm/pgsql.go +++ b/console/commands/pgorm/pgsql.go @@ -285,9 +285,9 @@ func genOrmStruct(table string, columns []tableColumn, conf Conf, relationships } str += "\n}\n\n" // 声明表字段 - str += "type {TableName}Field string\nvar (\n" + str += "var (\n" for _, column := range columns { - str += fmt.Sprintf("{TableName}Field%s {TableName}Field = \"%s\"\n", parser.StringToHump(column.ColumnName), column.ColumnName) + str += fmt.Sprintf("{TableName}Field%s = \"%s\"\n", parser.StringToHump(column.ColumnName), column.ColumnName) } str += ")" From ada2f0b6b2ea110309c6cb83afe756f6d40fd615 Mon Sep 17 00:00:00 2001 From: Zodial Date: Tue, 10 Oct 2023 09:26:53 +0800 Subject: [PATCH 3/6] =?UTF-8?q?update:=20swagger=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=9A=84=E6=8F=8F=E8=BF=B0=E6=81=A2=E5=A4=8Dtag=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/swagger.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/console/commands/swagger.go b/console/commands/swagger.go index 6fc4bfc..3cfba71 100644 --- a/console/commands/swagger.go +++ b/console/commands/swagger.go @@ -187,9 +187,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{ From 9d33f7d14e0e8f167e9cc76e407bf5b89d2bdffa Mon Sep 17 00:00:00 2001 From: jinzhu <1992053348@qq.com> Date: Sun, 15 Oct 2023 11:53:08 +0800 Subject: [PATCH 4/6] add @latest --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 762dda2..9a47128 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # toolset 一个go项目工具集合 ````shell -go install github.com/go-home-admin/toolset +go install github.com/go-home-admin/toolset@latest ```` ![image](https://github.com/go-home-admin/toolset/blob/main/show.gif) From 92435a6e4cb0ed24c7702ba12715b24ee48a215a Mon Sep 17 00:00:00 2001 From: Zodial Date: Wed, 18 Oct 2023 11:21:41 +0800 Subject: [PATCH 5/6] =?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 From 6fb2f68a0211b8a8a7264fe13d9b71407ead0d3d Mon Sep 17 00:00:00 2001 From: Zodial Date: Wed, 18 Oct 2023 14:50:20 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dswagger=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=83=A8=E5=88=86=E5=8F=82=E6=95=B0=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/swagger.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/console/commands/swagger.go b/console/commands/swagger.go index a6b240b..1e964cb 100644 --- a/console/commands/swagger.go +++ b/console/commands/swagger.go @@ -401,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), @@ -421,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,