优化变量
This commit is contained in:
parent
e03e1b9370
commit
aadb6f15ee
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.zhangdeman.cn/gateway/api-doc
|
|||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425085343-09fdf2f01e4f
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425091616-00e0a924efcd
|
||||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240422034417-8c922be06d95
|
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240422034417-8c922be06d95
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
go.sum
2
go.sum
@ -6,6 +6,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22 h1:98cFHV
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425083843-f40760f6ee22/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425085343-09fdf2f01e4f h1:bbn19GoW7ScVB6BybUthRqsc4hxc0EqmGyCICXlXkr8=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425085343-09fdf2f01e4f h1:bbn19GoW7ScVB6BybUthRqsc4hxc0EqmGyCICXlXkr8=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425085343-09fdf2f01e4f/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425085343-09fdf2f01e4f/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425091616-00e0a924efcd h1:RBFDiEMI97fuzpyb5HBN4lu3UXTAGYo6nlGhV2gWq5U=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240425091616-00e0a924efcd/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 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
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=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQcGqdzi4UdpZlp4f4FUPeBqoygP58pEKJkmN3ROsE0=
|
||||||
|
@ -302,6 +302,18 @@ func handleOneLevelSubPath(swaggerInfo *define.Swagger, uri string, parentPath s
|
|||||||
// 长度为1, 还不在 body, 无需生成结构体
|
// 长度为1, 还不在 body, 无需生成结构体
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if isGlobalMapType(paramConfig.Type) {
|
||||||
|
swaggerInfo.Definitions[parentPath].Properties[subPath] = &define.SwaggerDefinitionProperty{
|
||||||
|
Description: paramConfig.Description,
|
||||||
|
Type: consts.SwaggerDataTypeObject,
|
||||||
|
AllOf: []map[string]string{
|
||||||
|
{
|
||||||
|
consts.SwaggerRefKey: getRefValue(consts.SwaggerBaseObjectDefinitionName),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
initAnyDefinition(swaggerInfo, parentPath)
|
initAnyDefinition(swaggerInfo, parentPath)
|
||||||
if paramConfig.Required {
|
if paramConfig.Required {
|
||||||
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, subPath)
|
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, subPath)
|
||||||
@ -325,14 +337,14 @@ func setGlobalMapDefinition(swaggerInfo *define.Swagger, dataType string) {
|
|||||||
if !isGlobalMapType(dataType) {
|
if !isGlobalMapType(dataType) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 只要最终类型存在mao, 就一定会用到 global_map
|
// 只要最终类型存在mao, 就一定会用到 consts.SwaggerBaseObjectDefinitionName
|
||||||
if nil == swaggerInfo.Definitions {
|
if nil == swaggerInfo.Definitions {
|
||||||
swaggerInfo.Definitions = map[string]*define.SwaggerDefinition{}
|
swaggerInfo.Definitions = map[string]*define.SwaggerDefinition{}
|
||||||
}
|
}
|
||||||
if _, exist := swaggerInfo.Definitions["global_map"]; exist {
|
if _, exist := swaggerInfo.Definitions[consts.SwaggerBaseObjectDefinitionName]; exist {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
swaggerInfo.Definitions["global_map"] = &define.SwaggerDefinition{
|
swaggerInfo.Definitions[consts.SwaggerBaseObjectDefinitionName] = &define.SwaggerDefinition{
|
||||||
Type: consts.SwaggerDataTypeObject,
|
Type: consts.SwaggerDataTypeObject,
|
||||||
Required: make([]string, 0),
|
Required: make([]string, 0),
|
||||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||||
|
@ -109,6 +109,14 @@ func TestGenerate(t *testing.T) {
|
|||||||
Required: true,
|
Required: true,
|
||||||
EnumList: nil,
|
EnumList: nil,
|
||||||
},
|
},
|
||||||
|
&define.SwaggerParameterInput{
|
||||||
|
Type: consts.DataTypeMapAnyAny,
|
||||||
|
Description: "测试global_map",
|
||||||
|
Name: "obj",
|
||||||
|
In: "body",
|
||||||
|
Required: true,
|
||||||
|
EnumList: nil,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ResponseList: []*define.SwaggerResponseInput{
|
ResponseList: []*define.SwaggerResponseInput{
|
||||||
&define.SwaggerResponseInput{
|
&define.SwaggerResponseInput{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user