优化文档数据类型 -> Golang数据类型的转换
This commit is contained in:
parent
cef0969b3e
commit
0899ad9fe6
18
common.go
18
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user