From b919c9f48545b89a6928006bc1d6e27fbe228b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 11 Apr 2025 22:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96GOType=20->=20swagger=20type?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/tool.go | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/util/tool.go b/util/tool.go index 53108c1..4419a44 100644 --- a/util/tool.go +++ b/util/tool.go @@ -50,15 +50,41 @@ func GetParameterDefaultLocation(requestMethod string) string { // // Date : 12:23 2024/4/22 func GetSwaggerType(inputType string) string { - convertTable := map[string]string{ - consts.DataTypeString.String(): "string", - consts.DataTypeInt.String(): "integer", - consts.DataTypeUint.String(): "integer", - consts.DataTypeFloat.String(): "number", - consts.DataTypeBool.String(): "boolean", + for _, itemType := range consts.DataTypeBaseInt { + if itemType.String() == inputType { + return consts.SwaggerDataTypeInteger + } } - if _, exist := convertTable[inputType]; exist { - return convertTable[inputType] + for _, itemType := range consts.DataTypeBaseUint { + if itemType.String() == inputType { + return consts.SwaggerDataTypeInteger + } + } + for _, itemType := range consts.DataTypeBaseFloat { + if itemType.String() == inputType { + return consts.SwaggerDataTypeDouble + } + } + for _, itemType := range consts.DataTypeBaseString { + if itemType.String() == inputType { + return consts.SwaggerDataTypeString + } + } + for _, itemType := range consts.DataTypeBaseString { + if itemType.String() == inputType { + return consts.SwaggerDataTypeString + } + } + for _, itemType := range consts.DataTypeBaseBool { + if itemType.String() == inputType { + return consts.SwaggerDataTypeBoolean + } + } + if strings.HasPrefix(inputType, "[]") { + return consts.SwaggerDataTypeArray + } + if strings.HasPrefix(inputType, "map") { + return consts.SwaggerDataTypeObject } return inputType }