完成基础的返回结果数据机构解析
This commit is contained in:
19
common.go
19
common.go
@ -8,6 +8,7 @@
|
||||
package api_doc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"strings"
|
||||
@ -39,12 +40,12 @@ func GetUriPathParamList(uriPath string) []*define.ParamConfig {
|
||||
return result
|
||||
}
|
||||
|
||||
// GetParamType 将文档配置的数据类型转换为归一化处理后的数据类型
|
||||
// GetDataType 将文档配置的数据类型转换为归一化处理后的数据类型
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:52 2024/12/24
|
||||
func GetParamType(docParamType string, formatType string) consts.DataType {
|
||||
func GetDataType(docParamType string, formatType string) consts.DataType {
|
||||
docParamType = strings.ToLower(docParamType)
|
||||
formatType = strings.ToLower(formatType)
|
||||
if len(formatType) == 0 {
|
||||
@ -60,6 +61,10 @@ func GetParamType(docParamType string, formatType string) consts.DataType {
|
||||
return consts.DataTypeString
|
||||
case "object":
|
||||
return consts.DataTypeMapStrAny
|
||||
case "boolean":
|
||||
return consts.DataTypeBool
|
||||
case "number", "float", "double", "float32", "float64":
|
||||
return consts.DataTypeFloat
|
||||
case "array":
|
||||
if formatType == "integer" {
|
||||
return consts.DataTypeSliceInt
|
||||
@ -105,3 +110,13 @@ func GetRealDefinitionsKey(ref string) string {
|
||||
func GetRealResponseKey(ref string) string {
|
||||
return strings.TrimPrefix(ref, "#/responses/")
|
||||
}
|
||||
|
||||
// GetSuccessResponseConfig 获取成功的响应配置
|
||||
func GetSuccessResponseConfig(resultConfig map[string]*define.SwaggerPathConfigResponse) *define.SwaggerPathConfigResponse {
|
||||
for httpCode := 200; httpCode <= 299; httpCode++ {
|
||||
if cfg := resultConfig[fmt.Sprintf("%d", httpCode)]; nil != cfg {
|
||||
return cfg
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user