完成基础的返回结果数据机构解析

This commit is contained in:
2024-12-25 11:55:22 +08:00
parent 3722798c42
commit cc4ef13e23
4 changed files with 72 additions and 23 deletions

View File

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