2024-12-24 11:18:15 +08:00
|
|
|
// Package api_doc ...
|
|
|
|
//
|
|
|
|
// Description : api_doc ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2024-12-24 10:52
|
|
|
|
package api_doc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
|
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetUriPathParamList 获取uri参数列表
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:52 2024/12/24
|
|
|
|
func GetUriPathParamList(uriPath string) []*define.ParamConfig {
|
|
|
|
var (
|
|
|
|
paramList []string
|
|
|
|
result = make([]*define.ParamConfig, 0)
|
|
|
|
)
|
|
|
|
if paramList = define.UriParamRegexp.FindAllString(uriPath, -1); len(paramList) == 0 {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
for _, param := range paramList {
|
|
|
|
result = append(result, &define.ParamConfig{
|
|
|
|
Location: consts.RequestDataLocationUriPath.String(),
|
|
|
|
Path: strings.TrimRight(strings.TrimLeft(param, "{"), "}"),
|
|
|
|
Type: consts.DataTypeString.String(),
|
|
|
|
Title: param,
|
|
|
|
Description: param,
|
2024-12-24 12:11:17 +08:00
|
|
|
IsRequired: true,
|
2024-12-24 11:18:15 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2024-12-24 12:11:17 +08:00
|
|
|
|
|
|
|
// GetParamType 将文档配置的数据类型转换为归一化处理后的数据类型
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:52 2024/12/24
|
|
|
|
func GetParamType(docParamType string, formatType string) consts.DataType {
|
|
|
|
docParamType = strings.ToLower(docParamType)
|
|
|
|
formatType = strings.ToLower(formatType)
|
|
|
|
if len(formatType) == 0 {
|
|
|
|
formatType = docParamType
|
|
|
|
}
|
|
|
|
switch docParamType {
|
|
|
|
case "integer":
|
|
|
|
if formatType == "int64" {
|
|
|
|
return consts.DataTypeInt
|
|
|
|
}
|
|
|
|
return consts.DataTypeUint
|
|
|
|
case "string":
|
|
|
|
return consts.DataTypeString
|
|
|
|
default:
|
|
|
|
return consts.DataTypeAny
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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":
|
|
|
|
return consts.RequestDataLocationQuery
|
|
|
|
case "header":
|
|
|
|
return consts.RequestDataLocationHeader
|
|
|
|
case "cookie":
|
|
|
|
return consts.RequestDataLocationCookie
|
|
|
|
case "body":
|
|
|
|
return consts.RequestDataLocationBody
|
|
|
|
case "path":
|
|
|
|
return consts.RequestDataLocationUriPath
|
|
|
|
default:
|
|
|
|
return consts.RequestDataLocationQuery
|
|
|
|
}
|
|
|
|
}
|