From 7f7afdc566818c91f636b81cc0e1a6ea7b3d88dc Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 25 Sep 2023 17:05:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5swagger=E4=B8=ADquery?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=B8=A6=E4=B8=AD=E6=96=87=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A4=B1=E8=B4=A5=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1028500 --user=王孝刚 【接口测试】github#26025,swagger-url带中文导入metersphere失败 https://www.tapd.cn/55049933/s/1420806 --- .../api/parse/api/Swagger3Parser.java | 16 +++++++--------- .../environment/ApiEnvironmentConfig.vue | 7 +++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java index a893f4498c..c1a88ddbcd 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java @@ -109,32 +109,30 @@ public class Swagger3Parser extends SwaggerAbstractParser { } } // 设置 query 参数 - StringBuilder pathBuilder = new StringBuilder(); - pathBuilder.append(request.getSwaggerUrl()); - if (!request.getSwaggerUrl().contains("?")) { - pathBuilder.append("?"); - } if (!CollectionUtils.isEmpty(request.getArguments())) { + StringBuilder pathBuilder = new StringBuilder(); + pathBuilder.append(request.getSwaggerUrl()); + if (StringUtils.isNotBlank(request.getSwaggerUrl()) && !request.getSwaggerUrl().contains("?")) { + pathBuilder.append("?"); + } 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)); } - request.setSwaggerUrl(pathBuilder.substring(0, pathBuilder.length() - 1)); return CollectionUtils.size(auths) == 0 ? null : auths; } - private List parseRequests(OpenAPI openAPI, ApiTestImportRequest importRequest) { Paths paths = openAPI.getPaths(); diff --git a/framework/sdk-parent/frontend/src/components/environment/ApiEnvironmentConfig.vue b/framework/sdk-parent/frontend/src/components/environment/ApiEnvironmentConfig.vue index a1cd006fd5..2ddb9f1eb3 100644 --- a/framework/sdk-parent/frontend/src/components/environment/ApiEnvironmentConfig.vue +++ b/framework/sdk-parent/frontend/src/components/environment/ApiEnvironmentConfig.vue @@ -8,7 +8,7 @@ :data="environments" :item-operators="environmentOperators" :add-fuc="addEnvironment" :env-add-permission="ENV_CREATE" :delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/> - @@ -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);