From fa6117e27654fa6bc7d85b45acccbfe98039d227 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 21 Jan 2022 11:19:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20swagger=E5=AF=BC=E5=85=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E5=B1=82=E7=BA=A7=E7=9A=84tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parse/SwaggerAbstractParser.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/SwaggerAbstractParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/SwaggerAbstractParser.java index 1628c96045..825459f9c8 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/SwaggerAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/SwaggerAbstractParser.java @@ -19,15 +19,32 @@ public abstract class SwaggerAbstractParser extends ApiImportAbstractParser { - ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId); - apiDefinition.setModuleId(module.getId()); - if (StringUtils.isNotBlank(selectModulePath)) { - apiDefinition.setModulePath(selectModulePath + "/" + tag); + // 涉及到多级目录的结构,如: 一级目录/二级目录 + if (tag.contains("/")) { + String[] tagTree = tag.split("/"); + ApiModule pModule = parentModule; + String prefix = selectModulePath; + for (String item : tagTree) { + pModule = buildModule(pModule, apiDefinition, item, prefix); + prefix += "/" + item; + } } else { - apiDefinition.setModulePath("/" + tag); + buildModule(parentModule, apiDefinition, tag, selectModulePath); } }); } } + private ApiModule buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, + String tag, String selectModulePath) { + ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId); + apiDefinition.setModuleId(module.getId()); + if (StringUtils.isNotBlank(selectModulePath)) { + apiDefinition.setModulePath(selectModulePath + "/" + tag); + } else { + apiDefinition.setModulePath("/" + tag); + } + return module; + } + }