fix(接口测试): 修复接口导入未校验url存在

--bug=1039308 --user=王孝刚 【接口测试】新增接口定时任务-url已存在-可创建成功
https://www.tapd.cn/55049933/s/1497004
This commit is contained in:
wxg0103 2024-04-15 15:26:44 +08:00 committed by Craftsman
parent 653cd227e8
commit d1741bb3ca
9 changed files with 18 additions and 26 deletions

View File

@ -432,4 +432,6 @@ api_scenario_step.resource_num.length_range=资源编号长度必须在1-50之
tags_size_large_than=标签数量超过{0}个
no_permission_to_resource=无操作资源的权限
api_scenario_circular_reference_error=场景存在循环引用
api_scenario_circular_reference_error=场景存在循环引用
api_import_url_is_exist=导入的URL已存在

View File

@ -439,4 +439,5 @@ api_report_default_env=Default environment
tags_size_large_than=The number of tags cannot exceed 10
no_permission_to_resource=No permission to access the resource
api_scenario_circular_reference_error=There are circular references to the scenario
api_scenario_circular_reference_error=There are circular references to the scenario
api_import_url_is_exist=The imported URL already exists

View File

@ -407,4 +407,6 @@ api_report_default_env=默认环境
tags_size_large_than=标签数量超过{0}个
no_permission_to_resource=没有权限访问该资源
api_scenario_circular_reference_error=场景存在循环引用
api_scenario_circular_reference_error=场景存在循环引用
api_import_url_is_exist=导入的URL已存在

View File

@ -406,4 +406,6 @@ api_report_default_env=默认環境
tags_size_large_than=標籤數量不能超過{max}
no_permission_to_resource=無權限訪問資源
api_scenario_circular_reference_error=場景存在循環引用
api_scenario_circular_reference_error=場景存在循環引用
api_import_url_is_exist=导入URL已存在

View File

@ -1,7 +1,6 @@
package io.metersphere.api.controller.definition;
import io.metersphere.api.dto.definition.ApiScheduleDTO;
import io.metersphere.api.dto.definition.SwaggerUrlCheck;
import io.metersphere.api.dto.definition.request.ApiScheduleRequest;
import io.metersphere.api.service.definition.ApiDefinitionLogService;
import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
@ -43,13 +42,6 @@ public class ApiDefinitionScheduleController {
return apiDefinitionScheduleService.updateSchedule(request, SessionUtils.getUserId());
}
@PostMapping(value = "/check")
@Operation(summary = "接口测试-接口管理-定时同步-校验url是否存在")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT)
public Boolean checkSchedule(@RequestBody SwaggerUrlCheck swaggerUrlCheck) {
return apiDefinitionScheduleService.checkSwaggerUrl(swaggerUrlCheck.getProjectId(), swaggerUrlCheck.getSwaggerUrl());
}
@GetMapping(value = "/switch/{id}")
@Operation(summary = "接口测试-接口管理-定时同步-开启/关闭")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT)

View File

@ -55,6 +55,7 @@ public class ApiDefinitionScheduleService {
BeanUtils.copyBean(apiSwagger, request);
apiSwagger.setId(IDGenerator.nextStr());
apiSwagger.setNum(NumGenerator.nextNum(request.getProjectId(), ApplicationNumScope.API_IMPORT));
checkSwaggerUrl(request.getProjectId(), request.getSwaggerUrl());
// 设置鉴权信息
SwaggerBasicAuth basicAuth = new SwaggerBasicAuth();
basicAuth.setUserName(request.getAuthUsername());
@ -103,11 +104,13 @@ public class ApiDefinitionScheduleService {
return apiDefinitionSwagger;
}
public Boolean checkSwaggerUrl(String projectId, String url) {
public void checkSwaggerUrl(String projectId, String url) {
ApiDefinitionSwaggerExample example = new ApiDefinitionSwaggerExample();
example.createCriteria().andProjectIdEqualTo(projectId).andSwaggerUrlEqualTo(url);
List<ApiDefinitionSwagger> apiDefinitionSwaggers = apiDefinitionSwaggerMapper.selectByExample(example);
return CollectionUtils.isNotEmpty(apiDefinitionSwaggers);
if (CollectionUtils.isNotEmpty(apiDefinitionSwaggers)) {
throw new MSException(Translator.get("api_import_url_is_exist"));
}
}
public String updateSchedule(ApiScheduleRequest request, String userId) {

View File

@ -3,7 +3,6 @@ package io.metersphere.api.controller;
import io.metersphere.api.domain.ApiDefinitionSwagger;
import io.metersphere.api.domain.ApiDefinitionSwaggerExample;
import io.metersphere.api.dto.definition.ApiScheduleDTO;
import io.metersphere.api.dto.definition.SwaggerUrlCheck;
import io.metersphere.api.dto.definition.request.ApiScheduleRequest;
import io.metersphere.api.mapper.ApiDefinitionSwaggerMapper;
import io.metersphere.api.utils.ApiDataUtils;
@ -141,15 +140,6 @@ public class ApiDefinitionScheduleControllerTests extends BaseTest {
assert schedule.getEnable();
}
@Order(5)
@Test
public void checkSchedule() throws Exception {
SwaggerUrlCheck swaggerUrlCheck = new SwaggerUrlCheck();
swaggerUrlCheck.setProjectId(DEFAULT_PROJECT_ID);
swaggerUrlCheck.setSwaggerUrl("https://petstore3.swagger.io/api/v3/openapi.json");
this.requestPost(BASE_PATH + "check", swaggerUrlCheck);
}
@Order(6)
@Test
public void deleteSchedule() throws Exception {

View File

@ -26,7 +26,7 @@
v-model="form.name"
class="w-[243px]"
:max-length="255"
:placeholder="t('system.userGroup.pleaseInputUserGroupName')"
:placeholder="t('system.userGroup.searchHolder')"
allow-clear
@press-enter="handleBeforeOk"
@keyup.esc="handleCancel"

View File

@ -19,7 +19,7 @@
<a-input
v-model="form.name"
class="w-[245px]"
:placeholder="t('system.userGroup.pleaseInputUserGroupName')"
:placeholder="t('system.userGroup.searchHolder')"
allow-clear
:max-length="255"
@press-enter="handleBeforeOk(undefined)"