优化一波api-doc代码
This commit is contained in:
parent
181f963688
commit
fb906a49ea
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.zhangdeman.cn/gateway/api-doc
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425080806-c101cbfe4cad
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240422034417-8c922be06d95
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -2,6 +2,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240422030654-fc4470a2cebc h1:1fgPDw
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240422030654-fc4470a2cebc/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425080806-c101cbfe4cad h1:hOmxPRzrD6tDPjZH8lVBuSkz3WXr7j/q2aD9AvEGTFg=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425080806-c101cbfe4cad/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22 h1:98cFHVl4z4+AboA3r6UOVYKDOLgANePFjnItZ3FufvY=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQcGqdzi4UdpZlp4f4FUPeBqoygP58pEKJkmN3ROsE0=
|
||||
|
@ -110,6 +110,8 @@ func generatePathConfig(swaggerInfo *define.Swagger, docConfig *define.SwaggerIn
|
||||
}
|
||||
// 生成参数配置
|
||||
generatePathParameterConfig(swaggerInfo, itemPath)
|
||||
// 生成相应配置
|
||||
generatePathResponseConfig(swaggerInfo, itemPath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +123,6 @@ func generatePathConfig(swaggerInfo *define.Swagger, docConfig *define.SwaggerIn
|
||||
func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define.SwaggerPathInput) {
|
||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = make([]*define.SwaggerPathConfigParameter, 0)
|
||||
hasDealTable := map[string]bool{}
|
||||
hasDealResponseTable := map[string]bool{}
|
||||
|
||||
for _, itemParamInput := range pathConfig.ParameterList {
|
||||
if len(itemParamInput.Name) == 0 {
|
||||
@ -132,7 +133,7 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
namePath := strings.Split(itemParamInput.Name, ".")
|
||||
realParamName := namePath[0]
|
||||
parentPath := ""
|
||||
if !strings.Contains(realParamName, ".") {
|
||||
if strings.ToUpper(itemParamInput.In) == consts.RequestLocationBody && !strings.Contains(realParamName, ".") {
|
||||
realParamName = "jsonBody"
|
||||
parentPath = pathConfig.Uri + ".jsonBody"
|
||||
}
|
||||
@ -148,13 +149,22 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
Schema: map[string]string{},
|
||||
}
|
||||
if len(parentPath) > 0 {
|
||||
generateParam.Schema["$ref"] = getRefValue(pathConfig.Uri + ".jsonBody")
|
||||
generateParam.Schema[consts.SwaggerRefKey] = getRefValue(pathConfig.Uri + ".jsonBody")
|
||||
generateParam.Type = ""
|
||||
}
|
||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, generateParam)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generatePathResponseConfig 生成响应配置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:43 2024/4/25
|
||||
func generatePathResponseConfig(swaggerInfo *define.Swagger, pathConfig *define.SwaggerPathInput) {
|
||||
hasDealResponseTable := map[string]bool{}
|
||||
for _, itemResponseConfig := range pathConfig.ResponseList {
|
||||
for _, itemResponseInput := range itemResponseConfig.List {
|
||||
if len(itemResponseInput.Field) == 0 {
|
||||
@ -359,7 +369,7 @@ func initAnyDefinition(swaggerInfo *define.Swagger, definitionName string) {
|
||||
}
|
||||
swaggerInfo.Definitions[definitionName] = &define.SwaggerDefinition{
|
||||
Type: consts.SwaggerDataTypeObject,
|
||||
Format: "",
|
||||
Format: consts.DataTypeMapStrAny,
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
}
|
||||
@ -371,5 +381,5 @@ func initAnyDefinition(swaggerInfo *define.Swagger, definitionName string) {
|
||||
//
|
||||
// Date : 16:31 2024/4/25
|
||||
func getRefValue(path string) string {
|
||||
return "#/definitions/" + strings.TrimLeft(path, "/")
|
||||
return consts.SwaggerRefValPrefix + strings.TrimLeft(path, "/")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user