diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java index 2b38e1f092..3db7d88024 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java @@ -104,6 +104,14 @@ public class FilterChainUtils { filterChainDefinitionMap.put("/test-plan/report/share/get-layout/**", "anon"); // 默认语言 filterChainDefinitionMap.put("/user/local/config/default-locale", "anon"); + // 定义-分享 + filterChainDefinitionMap.put("/api/doc/share/detail/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/get-detail/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/check/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/module/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/export/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/stop/**", "anon"); + filterChainDefinitionMap.put("/api/doc/share/download/file/**", "anon"); return filterChainDefinitionMap; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java index 6aecf66717..d033ef5dd6 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java @@ -3,13 +3,17 @@ package io.metersphere.api.controller.definition; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.domain.ApiDocShare; +import io.metersphere.api.dto.definition.ApiDefinitionDTO; import io.metersphere.api.dto.definition.ApiDocShareDTO; import io.metersphere.api.dto.definition.ApiDocShareDetail; import io.metersphere.api.dto.definition.request.*; +import io.metersphere.api.service.ApiTestService; import io.metersphere.api.service.definition.ApiDefinitionExportService; +import io.metersphere.api.service.definition.ApiDefinitionService; import io.metersphere.api.service.definition.ApiDocShareLogService; import io.metersphere.api.service.definition.ApiDocShareService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -45,6 +49,10 @@ public class ApiDocShareController { private ApiDocShareService apiDocShareService; @Resource private ApiDefinitionExportService apiDefinitionExportService; + @Resource + private ApiTestService apiTestService; + @Resource + private ApiDefinitionService apiDefinitionService; @PostMapping(value = "/page") @Operation(summary = "接口测试-定义-分页获取分享列表") @@ -100,12 +108,18 @@ public class ApiDocShareController { @PostMapping("/module/tree") @Operation(summary = "接口测试-定义-分享-模块树") public List getShareDocTree(@Validated @RequestBody ApiDocShareModuleRequest request) { + List protocols = apiTestService.getProtocols(request.getOrgId()); + List protocolList = protocols.stream().map(ProtocolDTO::getProtocol).toList(); + request.setProtocols(protocolList); return apiDocShareService.getShareTree(request); } @PostMapping("/module/count") @Operation(summary = "接口测试-定义-分享-模块树数量") public Map getShareDocTreeCount(@Validated @RequestBody ApiDocShareModuleRequest request) { + List protocols = apiTestService.getProtocols(request.getOrgId()); + List protocolList = protocols.stream().map(ProtocolDTO::getProtocol).toList(); + request.setProtocols(protocolList); return apiDocShareService.getShareTreeCount(request); } @@ -127,4 +141,10 @@ public class ApiDocShareController { apiDefinitionExportService.downloadFile(projectId, fileId, SessionUtils.getUserId(), httpServletResponse); } + @GetMapping(value = "/get-detail/{id}") + @Operation(summary = "接口测试-接口管理-获取接口详情") + public ApiDefinitionDTO get(@PathVariable String id) { + return apiDefinitionService.get(id, SessionUtils.getUserId()); + } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiDocShareModuleRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiDocShareModuleRequest.java index cbb66a1cd1..04b1bc695a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiDocShareModuleRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiDocShareModuleRequest.java @@ -16,4 +16,7 @@ public class ApiDocShareModuleRequest extends ApiModuleRequest { @NotBlank(message = "{api_doc_share.id.not_blank}") @Size(min = 1, max = 50, message = "{api_doc_share.id.length_range}") private String shareId; + + @Schema(description = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String orgId; } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java index 0eb4b420ea..c294db512a 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java @@ -38,6 +38,7 @@ public class ApiDocShareControllerTests extends BaseTest { private final static String MODULE_COUNT = BASE_PATH + "module/count"; private final static String EXPORT = BASE_PATH + "export/Swagger"; private final static String DOWNLOAD = BASE_PATH + "download/file/"; + private final static String GET_DETAIL = BASE_PATH + "/get-detail/"; @Order(1) @Test @@ -62,7 +63,7 @@ public class ApiDocShareControllerTests extends BaseTest { ApiDocShareModuleRequest moduleRequest = new ApiDocShareModuleRequest(); moduleRequest.setShareId(docShare.getId()); moduleRequest.setProjectId(DEFAULT_PROJECT_ID); - moduleRequest.setProtocols(List.of("HTTP", "SPX", "Redis", "MongoDB")); + moduleRequest.setOrgId(DEFAULT_ORGANIZATION_ID); this.requestPostWithOk(MODULE_TREE, moduleRequest); request.setId(docShare.getId()); request.setName("share-2"); @@ -86,6 +87,7 @@ public class ApiDocShareControllerTests extends BaseTest { this.requestGetWithOk(DELETE + docShare.getId()); // 不存在的ID this.requestGet(DELETE + "not-exist-id").andExpect(status().is5xxServerError()); + this.requestGet(GET_DETAIL + "not-exist-id").andExpect(status().is5xxServerError()); } @Order(2) @@ -115,7 +117,7 @@ public class ApiDocShareControllerTests extends BaseTest { ApiDocShareModuleRequest moduleRequest = new ApiDocShareModuleRequest(); moduleRequest.setShareId(docShare.getId()); moduleRequest.setProjectId(DEFAULT_PROJECT_ID); - moduleRequest.setProtocols(List.of("HTTP", "SPX", "Redis", "MongoDB")); + moduleRequest.setOrgId(DEFAULT_ORGANIZATION_ID); this.requestPostWithOk(MODULE_COUNT, moduleRequest); request.setName("share-5"); request.setRangeMatchSymbol("CONTAINS");