优化GOType -> swagger type转换

This commit is contained in:
白茶清欢 2025-04-11 22:00:05 +08:00
parent 4b9d44296d
commit b919c9f485

View File

@ -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
}