递归生成参数结构
This commit is contained in:
@ -229,10 +229,20 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
parentPath = uri + ".input"
|
||||
}
|
||||
if len(subPathArr) == 2 {
|
||||
if _, exist := swaggerInfo.Definitions[parentPath]; !exist {
|
||||
swaggerInfo.Definitions[parentPath] = &define.SwaggerDefinition{
|
||||
Type: "object",
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
}
|
||||
}
|
||||
if subPathArr[1] == "[]" {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
Description: paramConfig.Description,
|
||||
Type: "Array",
|
||||
Type: "array",
|
||||
Items: map[string]string{
|
||||
"type": util.GetSwaggerType(paramConfig.Type),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
@ -256,11 +266,23 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
}
|
||||
swaggerInfo.Definitions[storageSubPath].Properties[subPathArr[1]] = &define.SwaggerDefinitionProperty{
|
||||
Description: paramConfig.Description,
|
||||
Type: paramConfig.Type,
|
||||
Type: util.GetSwaggerType(paramConfig.Type),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if _, exist := swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]]; !exist {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
Description: "对象描述",
|
||||
Type: "object",
|
||||
Items: nil,
|
||||
AllOf: []map[string]string{map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0],
|
||||
}},
|
||||
}
|
||||
}
|
||||
// fmt.Println(parentPath + "." + subPathArr[0])
|
||||
generateParameterDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), paramConfig)
|
||||
}
|
||||
|
||||
@ -299,7 +321,7 @@ func generateResponseDefinitions(swaggerInfo *define.Swagger, uri string, parent
|
||||
if subPathArr[1] == "[]" {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
Description: responseConfig.Description,
|
||||
Type: "Array",
|
||||
Type: "array",
|
||||
}
|
||||
} else {
|
||||
generateResponseDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), responseConfig)
|
||||
|
Reference in New Issue
Block a user