调试一半的代码

This commit is contained in:
2024-04-23 11:24:17 +08:00
parent a55cb66fd0
commit 7fb67b63ed
2 changed files with 48 additions and 25 deletions

View File

@ -129,20 +129,28 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
continue
}
// name 可能是 x.x.x 递归数组, 或者 x.x.[].x
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, "", itemParamInput.Name, itemParamInput)
namePath := strings.Split(itemParamInput.Name, ".")
realParamName := namePath[0]
parentPath := ""
if !strings.Contains(realParamName, ".") {
realParamName = "jsonBody"
parentPath = pathConfig.Uri + ".jsonBody"
}
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, parentPath, itemParamInput.Name, itemParamInput)
if _, exist := hasDealTable[namePath[0]]; !exist {
hasDealTable[namePath[0]] = true
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, &define.SwaggerPathConfigParameter{
generateParam := &define.SwaggerPathConfigParameter{
Type: itemParamInput.Type,
Description: itemParamInput.Description,
Name: namePath[0],
Name: realParamName,
In: itemParamInput.In,
Required: itemParamInput.Required,
Schema: map[string]string{
// "$ref": "#/definitions/" + pathConfig.Uri + ".input",
},
})
Schema: map[string]string{},
}
if len(parentPath) > 0 {
generateParam.Schema["$ref"] = "#/definitions/" + strings.TrimLeft(pathConfig.Uri, "/") + ".jsonBody"
}
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, generateParam)
}
}
@ -187,18 +195,33 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
Properties: make(map[string]*define.SwaggerDefinitionProperty),
}
}
if len(subPathArr) == 1 {
if len(parentPath) == 0 {
if paramConfig.In != strings.ToLower(consts.RequestLocationBody) {
// 长度为1, 还不在 body, 无需生成结构体
return
}
if _, exist := swaggerInfo.Definitions[parentPath]; !exist {
swaggerInfo.Definitions[parentPath] = &define.SwaggerDefinition{
Type: "object",
Required: make([]string, 0),
Properties: make(map[string]*define.SwaggerDefinitionProperty),
}
}
swaggerInfo.Definitions[parentPath].Type = paramConfig.Type
if paramConfig.Required {
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
}
/*swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
Description: paramConfig.Description,
Type: paramConfig.Type,
}*/
if len(parentPath) > 0 {
swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
Description: paramConfig.Description,
Type: paramConfig.Type,
}
if paramConfig.Required {
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
}
}
return
}
if len(parentPath) == 0 {