From 7d5e9a9d9c51e149e5069bf70a784f7533192d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 8 Feb 2025 10:18:44 +0800 Subject: [PATCH] fix data type --- common.go | 28 ++++++++++++++-------------- go.mod | 2 +- go.sum | 6 ++---- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/common.go b/common.go index 469b561..fb1fac6 100644 --- a/common.go +++ b/common.go @@ -45,36 +45,36 @@ func GetUriPathParamList(uriPath string) []*define.ParamConfig { // Author : go_developer@163.com<白茶清欢> // // Date : 11:52 2024/12/24 -func GetDataType(docParamType string, formatType string) consts.DataType { +func GetDataType(docParamType string, formatType string) string { docParamType = strings.ToLower(docParamType) formatType = strings.ToLower(formatType) if len(formatType) == 0 { formatType = docParamType } switch docParamType { - case "integer": + case consts.SwaggerDataTypeInteger: if formatType == "int64" { - return consts.DataTypeInt + return consts.DataTypeInt.String() } - return consts.DataTypeUint + return consts.DataTypeUint.String() case "string", "apikey": - return consts.DataTypeString + return consts.DataTypeString.String() case "object": - return consts.DataTypeMapStrAny + return consts.DataTypeMapStrAny.String() case "boolean": - return consts.DataTypeBool + return consts.DataTypeBool.String() case "number", "float", "double", "float32", "float64": - return consts.DataTypeFloat + return consts.DataTypeFloat.String() case "array": if formatType == "integer" { - return consts.DataTypeSliceInt + return consts.DataTypeSliceInt.String() } else if formatType == "string" { - return consts.DataTypeSliceString + return consts.DataTypeSliceString.String() } else { - return consts.DataTypeSliceAny + return consts.DataTypeSliceAny.String() } default: - return consts.DataTypeAny + return consts.DataTypeAny.String() } } @@ -137,7 +137,7 @@ func ExpandArrayParam(swaggerDoc *define.Swagger, ref string, rootPath string) [ res = append(res, &define.ParamConfig{ Location: consts.RequestDataLocationBody.String(), Path: pathPrefix + "{{#idx#}}." + itemKey, - Type: GetDataType(itemConfig.Type, "").String(), + Type: GetDataType(itemConfig.Type, ""), Title: pathPrefix + itemKey, Description: pathPrefix + itemKey, Required: false, @@ -158,7 +158,7 @@ func ExpandArrayResult(swaggerDoc *define.Swagger, ref string, rootPath string) res = append(res, &define.ResultConfig{ Location: consts.ResponseDataLocationBody.String(), Path: pathPrefix + "{{#idx#}}." + itemKey, - Type: GetDataType(itemConfig.Type, "").String(), + Type: GetDataType(itemConfig.Type, ""), Title: pathPrefix + itemKey, Description: pathPrefix + itemKey, }) diff --git a/go.mod b/go.mod index 67c3dea..c828600 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.zhangdeman.cn/gateway/api-doc go 1.22.2 require ( - git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207132005-330777d80591 + git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250208020330-a50062af46a1 git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250124091620-c757e551a8c9 github.com/tidwall/gjson v1.18.0 diff --git a/go.sum b/go.sum index ef348cb..e1ce507 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ -git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207125648-b75d2ec7f3c1 h1:qWqq6dWW2eIpaXvLBUjTrbOzX1xrSw/nswz2ZL7a8Zw= -git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207125648-b75d2ec7f3c1/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= -git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207130030-67b5d5cc6121 h1:48wtD5FTfQ6AiHWrFHg/IaCxzNWYRbuGlENWDhn0Fbw= -git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207130030-67b5d5cc6121/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207132005-330777d80591 h1:P58+JwVhycrAFqE2Eq25N9y5lDokYBUz+oLxCKk44BE= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250207132005-330777d80591/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250208020330-a50062af46a1 h1:vv4X72I6s6XcTi0ykj2v/cgMZyseFyE2LkS4WloICCs= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250208020330-a50062af46a1/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y= git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd h1:q7GG14qgXKB4MEXQFOe7/UYebsqMfPaSX80TcPdOosI=