升级one level处理逻辑

This commit is contained in:
白茶清欢 2024-04-26 21:27:57 +08:00
parent 33a5ec22b1
commit 723d0e477c

View File

@ -135,7 +135,7 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
parentPath := ""
if strings.ToUpper(itemParamInput.In) == consts.RequestLocationBody && !strings.Contains(realParamName, ".") {
realParamName = "jsonBody"
parentPath = pathConfig.Uri + ".jsonBody"
parentPath = strings.ReplaceAll(pathConfig.Uri, ".", "-") + ".jsonBody"
}
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, parentPath, itemParamInput.Name, itemParamInput)
if _, exist := hasDealTable[realParamName]; !exist {
@ -172,7 +172,7 @@ func generatePathResponseConfig(swaggerInfo *define.Swagger, pathConfig *define.
continue
}
// name 可能是 x.x.x 递归数组, 或者 x.x.[].x
outputDefine := strings.TrimLeft(pathConfig.Uri, "/") + "." + itemResponseConfig.Code + ".output"
outputDefine := strings.TrimLeft(strings.ReplaceAll(pathConfig.Uri, ".", "-"), "/") + "." + itemResponseConfig.Code + ".output"
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, outputDefine, itemResponseInput.Field, &define.SwaggerParameterInput{
Type: itemResponseInput.Type,
Description: itemResponseInput.Description,
@ -202,7 +202,7 @@ func generatePathResponseConfig(swaggerInfo *define.Swagger, pathConfig *define.
// Date : 14:06 2024/4/22
func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, parentPath string, subPath string, paramConfig *define.SwaggerParameterInput) {
setGlobalMapDefinition(swaggerInfo, paramConfig.Type)
uri = strings.TrimLeft(uri, "/")
uri = strings.ReplaceAll(strings.TrimLeft(uri, "/"), ".", "-")
parentPath = strings.TrimLeft(parentPath, "/")
checkPath := getCheckPath(parentPath)
subPathArr := strings.Split(subPath, ".")
@ -302,6 +302,16 @@ func handleOneLevelSubPath(swaggerInfo *define.Swagger, uri string, parentPath s
// 长度为1, 还不在 body, 无需生成结构体
return
}
if strings.HasSuffix(paramConfig.Type, "[]") {
swaggerInfo.Definitions[parentPath].Properties[subPath] = &define.SwaggerDefinitionProperty{
Description: paramConfig.Description,
Type: consts.SwaggerDataTypeArray,
Items: map[string]string{
consts.SwaggerTypeKey: util.GetSwaggerType(strings.TrimSuffix(paramConfig.Type, "[]")),
},
}
return
}
if isGlobalMapType(paramConfig.Type) {
swaggerInfo.Definitions[parentPath].Properties[subPath] = &define.SwaggerDefinitionProperty{
Description: paramConfig.Description,