diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java index 48fc273c8c..ee300e3a1e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java @@ -152,15 +152,22 @@ public class ApiDefinitionImportUtilService { if (StringUtils.isNotBlank(request.getModuleId())) { BaseTreeNode baseTreeNode = idModuleMap.get(request.getModuleId()); String modulePath = baseTreeNode.getPath(); - importData.forEach(t -> { - t.setModulePath(modulePath + t.getModulePath()); - }); + //如果选择了未规划模块, 导入的数据的模块清空, 只导入数据,不处理模块信息 + if ("root".equals(request.getModuleId())) { + importData.forEach(t -> { + t.setModulePath(modulePath); + }); + } else { + importData.forEach(t -> { + t.setModulePath(modulePath + t.getModulePath()); + }); + } } //去掉apiLists中不存在的模块数据 - apiLists = apiLists.stream().filter(t -> modulePathMap.containsKey(t.getModulePath())).toList(); apiLists.forEach(t -> { t.setModulePath(idModuleMap.get(t.getModuleId()) != null ? idModuleMap.get(t.getModuleId()).getPath() : StringUtils.EMPTY); }); + apiLists = apiLists.stream().filter(t -> modulePathMap.containsKey(t.getModulePath())).toList(); ApiDetailWithData apiDealWithData = new ApiDetailWithData(); //判断数据是否是唯一的 checkApiDataOnly(request, importData, apiLists, apiDealWithData); @@ -419,7 +426,7 @@ public class ApiDefinitionImportUtilService { //判断模块是否一样 if (!StringUtils.equals(apiDefinitionDTO.getModulePath(), importDTO.getModulePath())) { //不一样的模块需要更 - apiDefinitionDTO.setModulePath(apiDefinitionDTO.getModulePath()); + apiDefinitionDTO.setModulePath(importDTO.getModulePath()); updateModuleData.add(apiDefinitionDTO); logMap.put(apiDefinitionDTO.getId(), importDTO); } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index 1dbd7fc5ac..328ed8592e 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -1539,6 +1539,7 @@ public class ApiDefinitionControllerTests extends BaseTest { .getPath())); file = new MockMultipartFile("file", "openapi1.json", MediaType.APPLICATION_OCTET_STREAM_VALUE, inputStream); paramMap.add("file", file); + request.setModuleId("root"); request.setCoverModule(true); request.setCoverData(true); paramMap.add("request", JSON.toJSONString(request)); diff --git a/frontend/src/views/api-test/management/components/import.vue b/frontend/src/views/api-test/management/components/import.vue index 2bb8d0d8ca..c74321e640 100644 --- a/frontend/src/views/api-test/management/components/import.vue +++ b/frontend/src/views/api-test/management/components/import.vue @@ -46,6 +46,7 @@ class="w-[436px]" :field-names="{ title: 'name', key: 'id', children: 'children' }" allow-search + allow-clear /> diff --git a/frontend/src/views/api-test/management/components/management/api/apiTable.vue b/frontend/src/views/api-test/management/components/management/api/apiTable.vue index 032b5a082f..f07e50e4b6 100644 --- a/frontend/src/views/api-test/management/components/management/api/apiTable.vue +++ b/frontend/src/views/api-test/management/components/management/api/apiTable.vue @@ -409,6 +409,7 @@ label: 'common.delete', eventTag: 'delete', danger: true, + permission: ['PROJECT_API_DEFINITION:READ+DELETE'], }, ], };