修复对象数组文档生成的BUg
This commit is contained in:
parent
c46e7ee8de
commit
a3038b693e
@ -219,7 +219,7 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
if paramConfig.Required {
|
||||
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
|
||||
}
|
||||
swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPath] = &define.SwaggerDefinitionProperty{
|
||||
Description: paramConfig.Description,
|
||||
Type: util.GetSwaggerType(paramConfig.Type),
|
||||
}
|
||||
@ -245,18 +245,25 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
},
|
||||
}
|
||||
} else {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
Description: "参数描述",
|
||||
Type: "object",
|
||||
AllOf: []map[string]string{map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0],
|
||||
}},
|
||||
if subPathArr[0] == "[]" {
|
||||
generateParameterDefinitions(swaggerInfo, uri, parentPath+".[]", strings.Join(subPathArr[1:], "."), paramConfig)
|
||||
return
|
||||
} else {
|
||||
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 subPathArr[1] == "[]" {
|
||||
storageSubPath += ".[]"
|
||||
}
|
||||
if _, exist := swaggerInfo.Definitions[storageSubPath]; !exist {
|
||||
swaggerInfo.Definitions[storageSubPath] = &define.SwaggerDefinition{
|
||||
Type: "object",
|
||||
Type: wrapper.TernaryOperator.String(strings.HasSuffix(parentPath, "[]"), "array", "object").Value(),
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
}
|
||||
@ -273,14 +280,23 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
}
|
||||
|
||||
if _, exist := swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]]; !exist {
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{
|
||||
itemSwaggerDefinition := &define.SwaggerDefinitionProperty{
|
||||
Description: "对象描述",
|
||||
Type: "object",
|
||||
Type: wrapper.TernaryOperator.String(subPathArr[1] == "[]", "array", "object").Value(),
|
||||
Items: nil,
|
||||
AllOf: []map[string]string{map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0],
|
||||
}},
|
||||
AllOf: nil,
|
||||
}
|
||||
if itemSwaggerDefinition.Type == "object" {
|
||||
itemSwaggerDefinition.AllOf = []map[string]string{map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0],
|
||||
}}
|
||||
} else if itemSwaggerDefinition.Type == "array" {
|
||||
itemSwaggerDefinition.Description = "数组描述"
|
||||
itemSwaggerDefinition.Items = map[string]string{
|
||||
"$ref": "#/definitions/" + parentPath + "." + subPathArr[0] + ".[]",
|
||||
}
|
||||
}
|
||||
swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = itemSwaggerDefinition
|
||||
}
|
||||
// fmt.Println(parentPath + "." + subPathArr[0])
|
||||
generateParameterDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), paramConfig)
|
||||
|
@ -93,6 +93,22 @@ func TestGenerate(t *testing.T) {
|
||||
Required: true,
|
||||
EnumList: []interface{}{18, 19, 20},
|
||||
},
|
||||
&define.SwaggerParameterInput{
|
||||
Type: consts.DataTypeInt,
|
||||
Description: "年龄",
|
||||
Name: "test_list.[].age",
|
||||
In: "body",
|
||||
Required: true,
|
||||
EnumList: []interface{}{18, 19, 20},
|
||||
},
|
||||
&define.SwaggerParameterInput{
|
||||
Type: consts.DataTypeString,
|
||||
Description: "年龄",
|
||||
Name: "test_list.[].name",
|
||||
In: "body",
|
||||
Required: true,
|
||||
EnumList: nil,
|
||||
},
|
||||
},
|
||||
ResponseList: []*define.SwaggerResponseInput{
|
||||
&define.SwaggerResponseInput{
|
||||
|
Loading…
x
Reference in New Issue
Block a user