优化变量

This commit is contained in:
2024-04-25 17:21:42 +08:00
parent e03e1b9370
commit aadb6f15ee
4 changed files with 26 additions and 4 deletions

View File

@ -302,6 +302,18 @@ func handleOneLevelSubPath(swaggerInfo *define.Swagger, uri string, parentPath s
// 长度为1, 还不在 body, 无需生成结构体
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)
if paramConfig.Required {
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, subPath)
@ -325,14 +337,14 @@ func setGlobalMapDefinition(swaggerInfo *define.Swagger, dataType string) {
if !isGlobalMapType(dataType) {
return
}
// 只要最终类型存在mao 就一定会用到 global_map
// 只要最终类型存在mao 就一定会用到 consts.SwaggerBaseObjectDefinitionName
if nil == swaggerInfo.Definitions {
swaggerInfo.Definitions = map[string]*define.SwaggerDefinition{}
}
if _, exist := swaggerInfo.Definitions["global_map"]; exist {
if _, exist := swaggerInfo.Definitions[consts.SwaggerBaseObjectDefinitionName]; exist {
return
}
swaggerInfo.Definitions["global_map"] = &define.SwaggerDefinition{
swaggerInfo.Definitions[consts.SwaggerBaseObjectDefinitionName] = &define.SwaggerDefinition{
Type: consts.SwaggerDataTypeObject,
Required: make([]string, 0),
Properties: make(map[string]*define.SwaggerDefinitionProperty),