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;