From 0899ad9fe6ce95730618ae56cb1f719ea8e0d3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 7 Apr 2025 12:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B=20->=20Golang=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/common.go b/common.go index 4586d55..6f3f664 100644 --- a/common.go +++ b/common.go @@ -47,24 +47,34 @@ func GetUriPathParamList(uriPath string) []*define.ParamConfig { // Date : 11:52 2024/12/24 func GetDataType(docParamType string, formatType string) string { docParamType = strings.ToLower(docParamType) - formatType = strings.ToLower(formatType) + formatType = strings.ReplaceAll(strings.ToLower(formatType), "interface{}", "any") // 内置支持的类型统一使用any, 不使用 interface{} if len(formatType) == 0 { formatType = docParamType } + // format type 和内置的支持数据类型一致, 直接返回对应类型 + for _, itemType := range consts.DataTypeList { + if itemType.Value.String() == formatType { + return itemType.Value.String() + } + } + + // format type 和内置的支持数据类型不一致, 根据文档类型进行转换 switch docParamType { case consts.SwaggerDataTypeInteger: - if formatType == "int64" { + if formatType == consts.DataTypeInt.String() { return consts.DataTypeInt.String() } - return consts.DataTypeUint.String() + return consts.DataTypeInt.String() case "string", "apikey": return consts.DataTypeString.String() case "object": return consts.DataTypeMapStrAny.String() case "boolean": return consts.DataTypeBool.String() - case "number", "float", "double", "float32", "float64": + case "number", "float", "double", "float64": return consts.DataTypeFloat64.String() + case "float32": + return consts.DataTypeFloat32.String() case "array": if formatType == "integer" { return consts.DataTypeSliceInt.String()