From 0acf8d98a82d71842338c12145f04584e93d2022 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 21 Sep 2023 16:13:22 +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=E6=8E=A5=E5=8F=A3=E5=8F=82=E6=95=B0=E8=A7=92?= =?UTF-8?q?=E6=A0=87=E4=B8=8D=E6=98=BE=E7=A4=BA=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=1031018 --user=王孝刚 【接口测试】场景详情-复制步骤或者接口列表导入复制case-步骤认证配置选择Basic Auth和Digest Auth保存场景-认证配置tab页角标未更 https://www.tapd.cn/55049933/s/1419518 --bug=1031015 --user=王孝刚 【接口测试】场景详情-复制case-请求体json和form-data下都有数据-清空json-请求体角标不显示了 https://www.tapd.cn/55049933/s/1419545 --- .../api/parse/api/Swagger3Parser.java | 15 ++++++- .../commons/json-schema/JsonSchemaEditor.vue | 4 ++ .../json-schema/schema/editor/main.vue | 1 + .../components/auth/ApiAuthConfig.vue | 1 + .../definition/components/body/ApiBody.vue | 4 ++ .../request/http/ApiHttpRequestForm.vue | 42 +++++-------------- 6 files changed, 35 insertions(+), 32 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 62d1a83706..a893f4498c 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 @@ -40,6 +40,8 @@ import org.json.JSONObject; import org.springframework.http.HttpMethod; import java.io.InputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.*; @@ -107,17 +109,28 @@ 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())) { for (KeyValue keyValue : request.getArguments()) { if (StringUtils.isNotBlank(keyValue.getName())) { AuthorizationValue authorizationValue = new AuthorizationValue(); authorizationValue.setType("query"); authorizationValue.setKeyName(keyValue.getName()); - authorizationValue.setValue(keyValue.getValue()); + try { + authorizationValue.setValue(keyValue.isUrlEncode() ? URLEncoder.encode(keyValue.getValue(), StandardCharsets.UTF_8) : keyValue.getValue()); + } 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; } diff --git a/api-test/frontend/src/business/commons/json-schema/JsonSchemaEditor.vue b/api-test/frontend/src/business/commons/json-schema/JsonSchemaEditor.vue index 1f8846df8d..1ce9abec51 100644 --- a/api-test/frontend/src/business/commons/json-schema/JsonSchemaEditor.vue +++ b/api-test/frontend/src/business/commons/json-schema/JsonSchemaEditor.vue @@ -34,6 +34,7 @@ :expand-all-params="expandAllParams" :scenario-definition="scenarioDefinition" @editScenarioAdvance="editScenarioAdvance" + @bodyReload="reloadBody" :param-columns="apiJsonSchemaShowColumns" :need-mock="needMock" lang="zh_CN" @@ -141,6 +142,9 @@ export default { }; }, methods: { + reloadBody() { + this.$emit('headersChange'); + }, refreshApiParamsField() { this.apiJsonSchemaShowColumns = getShowFields(this.storageKey); }, diff --git a/api-test/frontend/src/business/commons/json-schema/schema/editor/main.vue b/api-test/frontend/src/business/commons/json-schema/schema/editor/main.vue index e87f701f16..b6b127a22f 100644 --- a/api-test/frontend/src/business/commons/json-schema/schema/editor/main.vue +++ b/api-test/frontend/src/business/commons/json-schema/schema/editor/main.vue @@ -648,6 +648,7 @@ export default { this.$emit('reloadItems'); }, reloadItems() { + this.$emit('bodyReload'); if (!this.hidden) { this.hidden = !this.hidden; this.$nextTick(() => { diff --git a/api-test/frontend/src/business/definition/components/auth/ApiAuthConfig.vue b/api-test/frontend/src/business/definition/components/auth/ApiAuthConfig.vue index a1973690b8..037439a836 100644 --- a/api-test/frontend/src/business/definition/components/auth/ApiAuthConfig.vue +++ b/api-test/frontend/src/business/definition/components/auth/ApiAuthConfig.vue @@ -125,6 +125,7 @@ export default { this.authConfig = authManager; this.request.authManager = this.authConfig; } + this.$emit('headersChange'); }, initData() { if (this.request.hashTree) { diff --git a/api-test/frontend/src/business/definition/components/body/ApiBody.vue b/api-test/frontend/src/business/definition/components/body/ApiBody.vue index ea3669134f..804c059691 100644 --- a/api-test/frontend/src/business/definition/components/body/ApiBody.vue +++ b/api-test/frontend/src/business/definition/components/body/ApiBody.vue @@ -63,6 +63,7 @@ :body="body" :scenario-definition="scenarioDefinition" @editScenarioAdvance="editScenarioAdvance" + @headersChange="reloadBody" :is-read-only="isReadOnly" ref="jsonCodeEdit" /> { diff --git a/api-test/frontend/src/business/definition/components/request/http/ApiHttpRequestForm.vue b/api-test/frontend/src/business/definition/components/request/http/ApiHttpRequestForm.vue index f4cd1f5027..6a52aa1a2e 100644 --- a/api-test/frontend/src/business/definition/components/request/http/ApiHttpRequestForm.vue +++ b/api-test/frontend/src/business/definition/components/request/http/ApiHttpRequestForm.vue @@ -135,7 +135,7 @@ - + - + @@ -371,35 +371,15 @@ export default { return this.request.authManager && this.request.authManager.verification !== 'No Auth'; }, showSubscript() { - if (!this.request.body || !this.request.body.type) { - return false; - } - switch (this.request.body.type) { - case BODY_TYPE.RAW: - case BODY_TYPE.XML: - return this.request.body.raw; - case BODY_TYPE.BINARY: - return ( - this.request.body.binary && - this.request.body.binary.length > 0 && - this.request.body.binary[0].files && - this.request.body.binary[0].files.length > 0 - ); - case BODY_TYPE.KV: - return this.request.body.kvs && this.request.body.kvs.length > 1; - case BODY_TYPE.JSON: { - if (this.request.body.format && this.request.body.format === 'JSON-SCHEMA') { - return this.request.body.jsonSchema; - } else { - return this.request.body.raw; - } - } - case BODY_TYPE.FORM_DATA: - case BODY_TYPE.WWW_FORM: - return this.request.body.kvs && this.request.body.kvs.length > 1; - default: - return false; - } + return ( + (this.request.body.kvs && this.request.body.kvs.length > 1) || + this.request.body.raw || + (this.request.body.binary && + this.request.body.binary.length > 0 && + this.request.body.binary[0].files && + this.request.body.binary[0].files.length > 0) || + (this.request.body.jsonSchema && this.request.body.jsonSchema.properties && Object.keys(this.request.body.jsonSchema.properties).length !== 0) + ); }, refreshApiParamsField() { let oldActiveName = this.activeName;