feat(接口测试): swagger的url导入支持自定义token

--bug=1046842 --user=宋天阳 【接口测试】导入接口-swagger导入带token-导入解析失败 https://www.tapd.cn/55049933/s/1582539
This commit is contained in:
Jianguo-Genius 2024-09-20 15:55:46 +08:00 committed by 建国
parent 95209738b0
commit 03bbba5ede
2 changed files with 23 additions and 7 deletions

View File

@ -121,12 +121,18 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
// 设置 headers
if (StringUtils.isNotBlank(request.getSwaggerToken())) {
String[] tokenRows = StringUtils.split(request.getSwaggerToken(), StringUtils.LF);
for (String row : tokenRows) {
String[] tokenArr = StringUtils.split(row, ":");
if (tokenArr.length == 2) {
AuthorizationValue authorizationValue = new AuthorizationValue();
authorizationValue.setType(HEADER);
authorizationValue.setKeyName("token");
authorizationValue.setValue(request.getSwaggerToken());
authorizationValue.setKeyName(tokenArr[0]);
authorizationValue.setValue(tokenArr[1]);
auths.add(authorizationValue);
}
}
}
return CollectionUtils.size(auths) == 0 ? null : auths;
}

View File

@ -158,7 +158,12 @@
></a-input>
</a-form-item>
<a-form-item field="token" label="token" asterisk-position="end">
<a-input v-model:model-value="importForm.swaggerToken" class="w-[700px]" allow-clear></a-input>
<a-textarea
v-model:model-value="importForm.swaggerToken"
:auto-size="{ minRows: 1 }"
class="w-[700px]"
allow-clear
/>
</a-form-item>
<div class="mb-[16px] flex items-center gap-[8px]">
<a-switch v-model:model-value="importForm.authSwitch" type="line" size="small"></a-switch>
@ -228,7 +233,12 @@
></a-input>
</a-form-item>
<a-form-item field="token" label="token" asterisk-position="end">
<a-input v-model:model-value="importForm.swaggerToken" class="w-[700px]" allow-clear></a-input>
<a-textarea
v-model:model-value="importForm.swaggerToken"
:auto-size="{ minRows: 1 }"
class="w-[700px]"
allow-clear
/>
</a-form-item>
<div class="mb-[16px] flex items-center gap-[8px]">
<a-switch v-model:model-value="importForm.authSwitch" type="line" size="small"></a-switch>