From 0f1a6b6f7eeb46d840e9c1830efce2a202a7ce40 Mon Sep 17 00:00:00 2001 From: junhong Date: Mon, 17 Jan 2022 19:34:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20sw?= =?UTF-8?q?agger=20=E5=AE=9A=E6=97=B6=E5=90=8C=E6=AD=A5=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009615 --user=周骏弘 【接口测试】swagger定时同步,请求参数无法关闭 https://www.tapd.cn/55049933/s/1093058 --- .../api/service/ApiDefinitionService.java | 14 ++++++--- .../metersphere/service/ScheduleService.java | 2 +- .../components/import/ApiImport.vue | 21 ++++++++++++-- .../components/import/ApiSchedule.vue | 29 ++++++++++++------- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index e346e718f7..0a39f4909d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1408,13 +1408,15 @@ public class ApiDefinitionService { /*swagger定时导入*/ public void createSchedule(ScheduleRequest request) { - String config = setAuthParams(request); /*保存swaggerUrl*/ SwaggerUrlProject swaggerUrlProject = new SwaggerUrlProject(); BeanUtils.copyBean(swaggerUrlProject, request); swaggerUrlProject.setId(UUID.randomUUID().toString()); // 设置鉴权信息 - swaggerUrlProject.setConfig(config); + if(request.getHeaders() !=null || request.getArguments() !=null || request.getAuthManager() != null){ + String config = setAuthParams(request); + swaggerUrlProject.setConfig(config); + } scheduleService.addSwaggerUrlSchedule(swaggerUrlProject); request.setResourceId(swaggerUrlProject.getId()); @@ -1435,11 +1437,15 @@ public class ApiDefinitionService { } public void updateSchedule(ScheduleRequest request) { - String config = setAuthParams(request); SwaggerUrlProject swaggerUrlProject = new SwaggerUrlProject(); BeanUtils.copyBean(swaggerUrlProject, request); // 设置鉴权信息 - swaggerUrlProject.setConfig(config); + if(request.getHeaders() !=null || request.getArguments() !=null || request.getAuthManager() != null){ + String config = setAuthParams(request); + swaggerUrlProject.setConfig(config); + }else{ + swaggerUrlProject.setConfig(null); + } scheduleService.updateSwaggerUrlSchedule(swaggerUrlProject); // 只修改表达式和名称 Schedule schedule = new Schedule(); diff --git a/backend/src/main/java/io/metersphere/service/ScheduleService.java b/backend/src/main/java/io/metersphere/service/ScheduleService.java index 25166fb13e..0df93cbf4c 100644 --- a/backend/src/main/java/io/metersphere/service/ScheduleService.java +++ b/backend/src/main/java/io/metersphere/service/ScheduleService.java @@ -64,7 +64,7 @@ public class ScheduleService { } public void updateSwaggerUrlSchedule(SwaggerUrlProject swaggerUrlProject) { - swaggerUrlProjectMapper.updateByPrimaryKeySelective(swaggerUrlProject); + swaggerUrlProjectMapper.updateByPrimaryKeyWithBLOBs(swaggerUrlProject); } public ApiSwaggerUrlDTO selectApiSwaggerUrlDTO(String id) { diff --git a/frontend/src/business/components/api/definition/components/import/ApiImport.vue b/frontend/src/business/components/api/definition/components/import/ApiImport.vue index cb82cee63f..01a8329cb0 100644 --- a/frontend/src/business/components/api/definition/components/import/ApiImport.vue +++ b/frontend/src/business/components/api/definition/components/import/ApiImport.vue @@ -72,7 +72,7 @@ - + @@ -90,7 +90,7 @@
{{$t('api_test.definition.request.auth_config')}}{{$t('api_test.api_import.optional')}}:
- +
- + @@ -239,6 +239,11 @@ export default { currentUser: () => { return getCurrentUser(); }, + changeAuthEnable() { + if(!this.authEnable){ + this.clearAuthInfo(); + } + }, clear() { this.formData.id = null; this.formData.moduleId = null; @@ -279,13 +284,19 @@ export default { this.formData.projectId = getCurrentProjectID(); this.formData.workspaceId = getCurrentWorkspaceId(); this.formData.value = this.formData.rule; - // 设置请求头或 query 参数 - this.formData.headers = this.headers; - this.formData.arguments = this.queryArguments; - // 设置 BaseAuth 参数 - if(this.authConfig.authManager != undefined){ - this.authConfig.authManager.clazzName = TYPE_TO_C.get("AuthManager"); - this.formData.authManager = this.authConfig.authManager; + if(this.authEnable){ + // 设置请求头或 query 参数 + this.formData.headers = this.headers; + this.formData.arguments = this.queryArguments; + // 设置 BaseAuth 参数 + if(this.authConfig.authManager != undefined){ + this.authConfig.authManager.clazzName = TYPE_TO_C.get("AuthManager"); + this.formData.authManager = this.authConfig.authManager; + } + }else { + this.formData.headers = undefined; + this.formData.arguments = undefined; + this.formData.authManager = undefined; } let url = ''; if (this.formData.id) { @@ -300,7 +311,6 @@ export default { this.clear(); }); }, - intervalShortValidate() { if (this.getIntervalTime() < 3 * 60 * 1000) { this.$info(this.$t('schedule.cron_expression_interval_short_error')); @@ -348,7 +358,6 @@ export default { this.authConfig = {hashTree: [], authManager: {}}; this.authEnable = false; } - }, computed: { isTesterPermission() {