From 723d0e477c549c00249f7bdaace6338886bf36f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 26 Apr 2024 21:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7one=20level=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- swagger/run.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/swagger/run.go b/swagger/run.go index 90ac89d..d24dde2 100644 --- a/swagger/run.go +++ b/swagger/run.go @@ -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,