fix(接口测试): 修复接口参数角标不显示的缺陷

--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
This commit is contained in:
wxg0103 2023-09-21 16:13:22 +08:00 committed by wxg0103
parent ebbb9c3a56
commit 0acf8d98a8
6 changed files with 35 additions and 32 deletions

View File

@ -40,6 +40,8 @@ import org.json.JSONObject;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import java.io.InputStream; import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
@ -107,17 +109,28 @@ public class Swagger3Parser extends SwaggerAbstractParser {
} }
} }
// 设置 query 参数 // 设置 query 参数
StringBuilder pathBuilder = new StringBuilder();
pathBuilder.append(request.getSwaggerUrl());
if (!request.getSwaggerUrl().contains("?")) {
pathBuilder.append("?");
}
if (!CollectionUtils.isEmpty(request.getArguments())) { if (!CollectionUtils.isEmpty(request.getArguments())) {
for (KeyValue keyValue : request.getArguments()) { for (KeyValue keyValue : request.getArguments()) {
if (StringUtils.isNotBlank(keyValue.getName())) { if (StringUtils.isNotBlank(keyValue.getName())) {
AuthorizationValue authorizationValue = new AuthorizationValue(); AuthorizationValue authorizationValue = new AuthorizationValue();
authorizationValue.setType("query"); authorizationValue.setType("query");
authorizationValue.setKeyName(keyValue.getName()); 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); auths.add(authorizationValue);
} }
} }
} }
request.setSwaggerUrl(pathBuilder.substring(0, pathBuilder.length() - 1));
return CollectionUtils.size(auths) == 0 ? null : auths; return CollectionUtils.size(auths) == 0 ? null : auths;
} }

View File

@ -34,6 +34,7 @@
:expand-all-params="expandAllParams" :expand-all-params="expandAllParams"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
@bodyReload="reloadBody"
:param-columns="apiJsonSchemaShowColumns" :param-columns="apiJsonSchemaShowColumns"
:need-mock="needMock" :need-mock="needMock"
lang="zh_CN" lang="zh_CN"
@ -141,6 +142,9 @@ export default {
}; };
}, },
methods: { methods: {
reloadBody() {
this.$emit('headersChange');
},
refreshApiParamsField() { refreshApiParamsField() {
this.apiJsonSchemaShowColumns = getShowFields(this.storageKey); this.apiJsonSchemaShowColumns = getShowFields(this.storageKey);
}, },

View File

@ -648,6 +648,7 @@ export default {
this.$emit('reloadItems'); this.$emit('reloadItems');
}, },
reloadItems() { reloadItems() {
this.$emit('bodyReload');
if (!this.hidden) { if (!this.hidden) {
this.hidden = !this.hidden; this.hidden = !this.hidden;
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -125,6 +125,7 @@ export default {
this.authConfig = authManager; this.authConfig = authManager;
this.request.authManager = this.authConfig; this.request.authManager = this.authConfig;
} }
this.$emit('headersChange');
}, },
initData() { initData() {
if (this.request.hashTree) { if (this.request.hashTree) {

View File

@ -63,6 +63,7 @@
:body="body" :body="body"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
@headersChange="reloadBody"
:is-read-only="isReadOnly" :is-read-only="isReadOnly"
ref="jsonCodeEdit" /> ref="jsonCodeEdit" />
<ms-code-edit <ms-code-edit
@ -195,6 +196,9 @@ export default {
}, },
}, },
methods: { methods: {
reloadBody() {
this.$emit('headersChange');
},
refreshApiParamsField() { refreshApiParamsField() {
this.reloadedApiVariable = false; this.reloadedApiVariable = false;
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -135,7 +135,7 @@
</el-tab-pane> </el-tab-pane>
<!-- 认证配置 --> <!-- 认证配置 -->
<el-tab-pane :label="$t('api_test.definition.request.auth_config')" name="authConfig"> <el-tab-pane v-if="isBodyShow" :label="$t('api_test.definition.request.auth_config')" name="authConfig">
<el-tooltip <el-tooltip
class="item-tabs" class="item-tabs"
effect="dark" effect="dark"
@ -150,7 +150,7 @@
</span> </span>
</el-tooltip> </el-tooltip>
<ms-api-auth-config :is-read-only="isReadOnly" :request="request" v-if="activeName === 'authConfig'" /> <ms-api-auth-config :is-read-only="isReadOnly" :request="request" v-if="activeName === 'authConfig'" @headersChange="reloadBody"/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.other_config')" name="advancedConfig"> <el-tab-pane :label="$t('api_test.definition.request.other_config')" name="advancedConfig">
@ -371,35 +371,15 @@ export default {
return this.request.authManager && this.request.authManager.verification !== 'No Auth'; return this.request.authManager && this.request.authManager.verification !== 'No Auth';
}, },
showSubscript() { showSubscript() {
if (!this.request.body || !this.request.body.type) { return (
return false; (this.request.body.kvs && this.request.body.kvs.length > 1) ||
} this.request.body.raw ||
switch (this.request.body.type) { (this.request.body.binary &&
case BODY_TYPE.RAW: this.request.body.binary.length > 0 &&
case BODY_TYPE.XML: this.request.body.binary[0].files &&
return this.request.body.raw; this.request.body.binary[0].files.length > 0) ||
case BODY_TYPE.BINARY: (this.request.body.jsonSchema && this.request.body.jsonSchema.properties && Object.keys(this.request.body.jsonSchema.properties).length !== 0)
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;
}
}, },
refreshApiParamsField() { refreshApiParamsField() {
let oldActiveName = this.activeName; let oldActiveName = this.activeName;