fix: swagger 导入后无法保存

This commit is contained in:
chenjianxing 2020-07-21 19:09:05 +08:00
parent e88983ecb3
commit cc7c5b9e23
5 changed files with 41 additions and 19 deletions

View File

@ -80,6 +80,16 @@
}
},
watch: {
projectId() {
this.initScenarioEnvironment();
}
},
activated() {
this.initScenarioEnvironment();
},
methods: {
createScenario: function () {
this.scenarios.push(new Scenario());
@ -119,6 +129,22 @@
this.activeName = 0;
this.select(this.scenarios[0]);
});
},
initScenarioEnvironment: function () {
if (this.projectId) {
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
let environments = response.data;
let environmentMap = new Map();
environments.forEach(environment => {
environmentMap.set(environment.id, environment);
});
this.scenarios.forEach(scenario => {
if (scenario.environmentId) {
scenario.environment = environmentMap.get(scenario.environmentId);
}
});
});
}
}
},

View File

@ -82,7 +82,6 @@
for (let i in this.environments) {
if (this.environments[i].id === this.scenario.environmentId) {
this.scenario.environment = this.environments[i];
this.setRequestEnvironments();
hasEnvironment = true;
break;
}
@ -101,7 +100,6 @@
for (let i in this.environments) {
if (this.environments[i].id === value) {
this.scenario.environment = this.environments[i];
this.setRequestEnvironments();
break;
}
}
@ -121,11 +119,6 @@
},
environmentConfigClose() {
this.getEnvironments();
},
setRequestEnvironments() {
this.scenario.requests.forEach(request => {
request.environment = this.scenario.environment;
});
}
}
}

View File

@ -226,8 +226,8 @@ export class HTTPSamplerProxy extends DefaultTestElement {
this.request = request || {};
if (request.useEnvironment) {
this.stringProp("HTTPSampler.domain", this.request.environment.domain);
this.stringProp("HTTPSampler.protocol", this.request.environment.protocol);
this.stringProp("HTTPSampler.domain", request.domain);
this.stringProp("HTTPSampler.protocol", request.protocol);
this.stringProp("HTTPSampler.path", this.request.path);
} else {
this.stringProp("HTTPSampler.domain", this.request.hostname);

View File

@ -160,6 +160,7 @@ export class Scenario extends BaseConfig {
this.headers = [];
this.requests = [];
this.environmentId = undefined;
this.environment = undefined;
this.set(options);
this.sets({variables: KeyValue, headers: KeyValue, requests: Request}, options);
@ -177,7 +178,7 @@ export class Scenario extends BaseConfig {
isValid() {
for (let i = 0; i < this.requests.length; i++) {
let validator = this.requests[i].isValid();
let validator = this.requests[i].isValid(this.environmentId);
if (!validator.isValid) {
return validator;
}
@ -214,9 +215,9 @@ export class Request extends BaseConfig {
return options;
}
isValid() {
isValid(environmentId) {
if (this.useEnvironment){
if (!this.environment) {
if (!environmentId) {
return {
isValid: false,
info: 'api_test.request.please_configure_environment_in_scenario'
@ -423,7 +424,7 @@ const JMX_ASSERTION_CONDITION = {
}
class JMXRequest {
constructor(request) {
constructor(request, environment) {
if (request && request instanceof Request && (request.url || request.path)) {
this.useEnvironment = request.useEnvironment;
this.method = request.method;
@ -435,10 +436,12 @@ class JMXRequest {
this.protocol = url.protocol.split(":")[0];
this.pathname = this.getPostQueryParameters(request, this.pathname);
} else {
this.environment = request.environment;
this.port = request.environment.port;
this.path = decodeURIComponent(request.path);
this.path = this.getPostQueryParameters(request, this.path);
if (environment) {
this.port = environment.port;
this.protocol = environment.protocol;
this.domain = environment.domain;
}
this.path = this.getPostQueryParameters(request, decodeURIComponent(request.path));
}
}
}
@ -497,7 +500,7 @@ class JMXGenerator {
scenario.requests.forEach(request => {
if (!request.isValid()) return;
let httpSamplerProxy = new HTTPSamplerProxy(request.name || "", new JMXRequest(request));
let httpSamplerProxy = new HTTPSamplerProxy(request.name || "", new JMXRequest(request, scenario.environment));
this.addRequestHeader(httpSamplerProxy, request);

View File

@ -259,7 +259,7 @@
maintainer: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
priority: [{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
type: [{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
testId: [{required: true, message: '请选择测试', trigger: 'change'}],
testId: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
method: [{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}],
prerequisite: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}],
remark: [{max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}]