修复对象嵌套的BUG
This commit is contained in:
@ -189,9 +189,14 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
if nil == swaggerInfo.Definitions {
|
||||
swaggerInfo.Definitions = map[string]*define.SwaggerDefinition{}
|
||||
}
|
||||
parentPathArr := strings.Split(parentPath, ".")
|
||||
checkPath := parentPath
|
||||
if len(parentPathArr) >= 2 {
|
||||
checkPath = strings.Join([]string{parentPathArr[0], parentPathArr[1]}, ".")
|
||||
}
|
||||
subPathArr := strings.Split(subPath, ".")
|
||||
if _, exist := swaggerInfo.Definitions[parentPath]; !exist && len(parentPath) > 0 {
|
||||
swaggerInfo.Definitions[parentPath] = &define.SwaggerDefinition{
|
||||
if _, exist := swaggerInfo.Definitions[checkPath]; !exist && len(parentPath) > 0 {
|
||||
swaggerInfo.Definitions[checkPath] = &define.SwaggerDefinition{
|
||||
Type: "object",
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
@ -230,7 +235,29 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
Type: "Array",
|
||||
}
|
||||
} else {
|
||||
generateParameterDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), paramConfig)
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
Description: "参数描述",
|
||||
Type: "object",
|
||||
AllOf: []map[string]string{map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0],
|
||||
}},
|
||||
}
|
||||
|
||||
storageSubPath := parentPath + "." + subPathArr[0]
|
||||
if _, exist := swaggerInfo.Definitions[storageSubPath]; !exist {
|
||||
swaggerInfo.Definitions[storageSubPath] = &define.SwaggerDefinition{
|
||||
Type: "object",
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
}
|
||||
}
|
||||
if paramConfig.Required {
|
||||
swaggerInfo.Definitions[storageSubPath].Required = append(swaggerInfo.Definitions[storageSubPath].Required, subPathArr[1])
|
||||
}
|
||||
swaggerInfo.Definitions[storageSubPath].Properties[subPathArr[1]] = &define.SwaggerDefinitionProperty{
|
||||
Description: paramConfig.Description,
|
||||
Type: paramConfig.Type,
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user