From 03bbba5ede9fb5ff52b0dc81618e1b8e5704319d Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Fri, 20 Sep 2024 15:55:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20s?= =?UTF-8?q?wagger=E7=9A=84url=E5=AF=BC=E5=85=A5=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046842 --user=宋天阳 【接口测试】导入接口-swagger导入带token-导入解析失败 https://www.tapd.cn/55049933/s/1582539 --- .../parser/api/Swagger3ParserApiDefinition.java | 16 +++++++++++----- .../api-test/management/components/import.vue | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3ParserApiDefinition.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3ParserApiDefinition.java index b1da06602b..eda2e67b2f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3ParserApiDefinition.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3ParserApiDefinition.java @@ -121,11 +121,17 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract // 设置 headers if (StringUtils.isNotBlank(request.getSwaggerToken())) { - AuthorizationValue authorizationValue = new AuthorizationValue(); - authorizationValue.setType(HEADER); - authorizationValue.setKeyName("token"); - authorizationValue.setValue(request.getSwaggerToken()); - auths.add(authorizationValue); + 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(tokenArr[0]); + authorizationValue.setValue(tokenArr[1]); + auths.add(authorizationValue); + } + } } return CollectionUtils.size(auths) == 0 ? null : auths; diff --git a/frontend/src/views/api-test/management/components/import.vue b/frontend/src/views/api-test/management/components/import.vue index d125215c60..b69619ba59 100644 --- a/frontend/src/views/api-test/management/components/import.vue +++ b/frontend/src/views/api-test/management/components/import.vue @@ -158,7 +158,12 @@ > - +
@@ -228,7 +233,12 @@ > - +