fix(接口测试): swagger 定时同步,请求参数无法关闭问题修复

--bug=1009615 --user=周骏弘 【接口测试】swagger定时同步,请求参数无法关闭 https://www.tapd.cn/55049933/s/1093058
This commit is contained in:
junhong 2022-01-17 19:34:27 +08:00 committed by john1298308460
parent 87c216f01c
commit 0f1a6b6f7e
4 changed files with 48 additions and 18 deletions

View File

@ -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());
// 设置鉴权信息
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);
// 设置鉴权信息
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();

View File

@ -64,7 +64,7 @@ public class ScheduleService {
}
public void updateSwaggerUrlSchedule(SwaggerUrlProject swaggerUrlProject) {
swaggerUrlProjectMapper.updateByPrimaryKeySelective(swaggerUrlProject);
swaggerUrlProjectMapper.updateByPrimaryKeyWithBLOBs(swaggerUrlProject);
}
public ApiSwaggerUrlDTO selectApiSwaggerUrlDTO(String id) {

View File

@ -72,7 +72,7 @@
<el-form-item :label="'Swagger URL'" prop="swaggerUrl" class="swagger-url">
<el-input size="small" v-model="formData.swaggerUrl" clearable show-word-limit/>
</el-form-item>
<el-switch v-model="authEnable" :active-text="$t('api_test.api_import.add_request_params')"></el-switch>
<el-switch v-model="authEnable" :active-text="$t('api_test.api_import.add_request_params')" @change="changeAuthEnable"></el-switch>
</el-col>
<el-col :span="14" v-show="isSwagger2 && authEnable && swaggerUrlEnable">
@ -90,7 +90,7 @@
<div style="margin-top: 10px">
<span>{{$t('api_test.definition.request.auth_config')}}{{$t('api_test.api_import.optional')}}</span>
</div>
<ms-api-auth-config :is-read-only="isReadOnly" :request="authConfig" :encryptShow="false"/>
<ms-api-auth-config :is-read-only="isReadOnly" :request="authConfig" :encryptShow="false" ref="importAuth"/>
</el-col>
<el-col :span="12"
@ -142,6 +142,7 @@
import MsApiAuthConfig from "../auth/ApiAuthConfig";
import {REQUEST_HEADERS} from "@/common/js/constants";
import {ELEMENT_TYPE, TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
import {KeyValue} from "../../model/ApiTestModel";
export default {
name: "ApiImport",
@ -394,6 +395,19 @@
this.formData.moduleId = id;
this.formData.modulePath = data.path;
},
clearAuthInfo(){
this.headers = [];
this.queryArguments = [];
this.headers.push(new KeyValue({enable: true}));
this.queryArguments.push(new KeyValue({enable: true}));
this.authConfig = {hashTree: [], authManager: {}};
this.$refs.importAuth.initData();
},
changeAuthEnable() {
if(!this.authEnable){
this.clearAuthInfo();
}
},
buildParam() {
let param = {};
Object.assign(param, this.formData);
@ -407,7 +421,8 @@
param.projectId = this.projectId;
if (!this.swaggerUrlEnable) {
param.swaggerUrl = undefined;
}else{
}
if(this.authEnable){
//
param.headers = this.headers;
// query

View File

@ -32,7 +32,7 @@
</el-col>
<el-col :span="12" style="margin-left: 50px">
<el-switch v-model="authEnable" :active-text="$t('api_test.api_import.add_request_params')"></el-switch>
<el-switch v-model="authEnable" :active-text="$t('api_test.api_import.add_request_params')" @change="changeAuthEnable"></el-switch>
</el-col>
<el-col :span="19" v-show="authEnable" style="margin-top: 10px; margin-left: 50px" class="request-tabs">
@ -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,6 +284,7 @@ export default {
this.formData.projectId = getCurrentProjectID();
this.formData.workspaceId = getCurrentWorkspaceId();
this.formData.value = this.formData.rule;
if(this.authEnable){
// query
this.formData.headers = this.headers;
this.formData.arguments = this.queryArguments;
@ -287,6 +293,11 @@ export default {
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) {
url = '/api/definition/schedule/update';
@ -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() {