fix(接口测试): 修复导入swagger中query参数带中文,导入失败的缺陷
--bug=1028500 --user=王孝刚 【接口测试】github#26025,swagger-url带中文导入metersphere失败 https://www.tapd.cn/55049933/s/1420806
This commit is contained in:
parent
9125a69248
commit
7f7afdc566
|
@ -109,32 +109,30 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
}
|
||||
// 设置 query 参数
|
||||
if (!CollectionUtils.isEmpty(request.getArguments())) {
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(request.getSwaggerUrl());
|
||||
if (!request.getSwaggerUrl().contains("?")) {
|
||||
if (StringUtils.isNotBlank(request.getSwaggerUrl()) && !request.getSwaggerUrl().contains("?")) {
|
||||
pathBuilder.append("?");
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(request.getArguments())) {
|
||||
for (KeyValue keyValue : request.getArguments()) {
|
||||
if (StringUtils.isNotBlank(keyValue.getName())) {
|
||||
AuthorizationValue authorizationValue = new AuthorizationValue();
|
||||
authorizationValue.setType("query");
|
||||
authorizationValue.setKeyName(keyValue.getName());
|
||||
try {
|
||||
authorizationValue.setValue(keyValue.isUrlEncode() ? URLEncoder.encode(keyValue.getValue(), StandardCharsets.UTF_8) : keyValue.getValue());
|
||||
authorizationValue.setValue(URLEncoder.encode(keyValue.getValue(), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
LogUtil.info("swagger3 url encode error: " + e);
|
||||
}
|
||||
pathBuilder.append(keyValue.getName()).append("=").append(authorizationValue.getValue()).append("&");
|
||||
auths.add(authorizationValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
request.setSwaggerUrl(pathBuilder.substring(0, pathBuilder.length() - 1));
|
||||
}
|
||||
return CollectionUtils.size(auths) == 0 ? null : auths;
|
||||
}
|
||||
|
||||
|
||||
private List<ApiDefinitionWithBLOBs> parseRequests(OpenAPI openAPI, ApiTestImportRequest importRequest) {
|
||||
Paths paths = openAPI.getPaths();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
:data="environments" :item-operators="environmentOperators" :add-fuc="addEnvironment"
|
||||
:env-add-permission="ENV_CREATE"
|
||||
:delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/>
|
||||
<environment-edit :if-create="ifCreate" :environment="currentEnvironment"
|
||||
<environment-edit :if-create="ifCreate" :environment="currentEnvironment" v-if="visible"
|
||||
ref="environmentEdit" :is-read-only="isReadOnly"
|
||||
@confirm="save" :is-project="true" :key="currentEnvironment.id"
|
||||
@close="close" @refreshAfterSave="refresh">
|
||||
|
@ -164,9 +164,7 @@ export default {
|
|||
}
|
||||
})
|
||||
this.$refs.environmentEdit._save(newEnvironment);
|
||||
this.environments.unshift(newEnvironment);
|
||||
this.$refs.environmentItems.itemSelected(this.environments.length - 1, newEnvironment);
|
||||
this.refresh();
|
||||
this.getEnvironments();
|
||||
},
|
||||
validateEnvironment(environment) {
|
||||
if (!this.$refs.environmentEdit.validate()) {
|
||||
|
@ -199,6 +197,7 @@ export default {
|
|||
if (this.projectId) {
|
||||
this.result = getEnvironmentByProjectId(this.projectId).then(response => {
|
||||
this.environments = response.data;
|
||||
this.currentEnvironment.id = null;
|
||||
if (this.environments.length > 0) {
|
||||
if (this.selectEnvironmentId) {
|
||||
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
|
||||
|
|
Loading…
Reference in New Issue