upgrade: 优化部分代码, 部分内容待配置化
This commit is contained in:
38
common.go
38
common.go
@ -9,9 +9,11 @@ package api_doc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"git.zhangdeman.cn/gateway/api-doc/enums"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
)
|
||||
|
||||
// GetUriPathParamList 获取uri参数列表
|
||||
@ -60,22 +62,22 @@ func GetDataType(docParamType string, formatType string) string {
|
||||
|
||||
// format type 和内置的支持数据类型不一致, 根据文档类型进行转换
|
||||
switch docParamType {
|
||||
case consts.SwaggerDataTypeInteger:
|
||||
case enums.SwaggerDataTypeInteger.String():
|
||||
if formatType == consts.DataTypeInt.String() {
|
||||
return consts.DataTypeInt.String()
|
||||
}
|
||||
return consts.DataTypeInt.String()
|
||||
case "string", "apikey":
|
||||
case enums.SwaggerDataTypeString.String(), enums.SwaggerDataTypeString.String():
|
||||
return consts.DataTypeString.String()
|
||||
case "object":
|
||||
case enums.SwaggerDataTypeObject.String():
|
||||
return consts.DataTypeMapStrAny.String()
|
||||
case "boolean":
|
||||
case enums.SwaggerDataTypeObject.String():
|
||||
return consts.DataTypeBool.String()
|
||||
case "number", "float", "double", "float64":
|
||||
case enums.SwaggerDataTypeNumber.String(), "float", "double", "float64":
|
||||
return consts.DataTypeFloat64.String()
|
||||
case "float32":
|
||||
return consts.DataTypeFloat32.String()
|
||||
case "array":
|
||||
case enums.SwaggerDataTypeArray.String():
|
||||
if formatType == "integer" {
|
||||
return consts.DataTypeSliceInt.String()
|
||||
} else if formatType == "string" {
|
||||
@ -89,22 +91,18 @@ func GetDataType(docParamType string, formatType string) string {
|
||||
}
|
||||
|
||||
// GetParamLocation 获取参数位置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:02 2024/12/24
|
||||
func GetParamLocation(docParamLocation string) consts.RequestDataLocation {
|
||||
docParamLocation = strings.ToLower(docParamLocation)
|
||||
switch docParamLocation {
|
||||
case "query":
|
||||
case enums.DocParamLocationQuery.String():
|
||||
return consts.RequestDataLocationQuery
|
||||
case "header":
|
||||
case enums.DocParamLocationHeader.String():
|
||||
return consts.RequestDataLocationHeader
|
||||
case "cookie":
|
||||
case enums.DocParamLocationCookie.String():
|
||||
return consts.RequestDataLocationCookie
|
||||
case "body":
|
||||
case enums.DocParamLocationBody.String():
|
||||
return consts.RequestDataLocationBody
|
||||
case "path":
|
||||
case enums.DocParamLocationPath.String():
|
||||
return consts.RequestDataLocationUriPath
|
||||
default:
|
||||
return consts.RequestDataLocationQuery
|
||||
@ -113,12 +111,12 @@ func GetParamLocation(docParamLocation string) consts.RequestDataLocation {
|
||||
|
||||
// GetRealDefinitionsKey 通过schema下的 $ref 获取真实的 definitions key
|
||||
func GetRealDefinitionsKey(ref string) string {
|
||||
return strings.TrimPrefix(ref, "#/definitions/")
|
||||
return strings.TrimPrefix(ref, enums.RefPrefixSchemaDefinition.String())
|
||||
}
|
||||
|
||||
// GetRealResponseKey 通过schema下的 $ref 获取真实的 response key
|
||||
func GetRealResponseKey(ref string) string {
|
||||
return strings.TrimPrefix(ref, "#/responses/")
|
||||
return strings.TrimPrefix(ref, enums.RefPrefixSchemaResponse.String())
|
||||
}
|
||||
|
||||
// GetSuccessResponseConfig 获取成功的响应配置
|
||||
@ -133,7 +131,7 @@ func GetSuccessResponseConfig(resultConfig map[string]*define.SwaggerPathConfigR
|
||||
|
||||
// DataTypeIsArray 判断数据类型是否为数组
|
||||
func DataTypeIsArray(docDataType string) bool {
|
||||
return strings.ToLower(docDataType) == "array"
|
||||
return strings.ToLower(docDataType) == enums.SwaggerDataTypeArray.String()
|
||||
}
|
||||
|
||||
// ExpandArrayParam 展开详细的数组配置
|
||||
|
Reference in New Issue
Block a user