From 021966ae23d62a6afc2dd4417a60935097761967 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 19 Sep 2024 19:10:40 +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=8Dhar=E5=AF=BC=E5=85=A5=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=93=8D=E5=BA=94=E4=BD=93=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046761 --user=宋天阳 【接口测试】导入har接口和已存在接口响应体不同名-接口更新-响应体被覆盖了 https://www.tapd.cn/55049933/s/1581743 --- .../metersphere/api/parser/api/HarParserApiDefinition.java | 6 ++++-- .../io/metersphere/api/parser/ms/HTTPSamplerConverter.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HarParserApiDefinition.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HarParserApiDefinition.java index 37bfc01b96..6039ec85c6 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HarParserApiDefinition.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HarParserApiDefinition.java @@ -100,12 +100,11 @@ public class HarParserApiDefinition extends HttpApiDefinitionImportAbstractParse if (CollectionUtils.isEmpty(importApi.getResponse())) { importApi.setResponse(savedApi.getResponse()); } else { - if (CollectionUtils.isEmpty(savedApi.getResponse())) { importApi.getResponse().getFirst().setDefaultFlag(true); } else { List existenceResponseList = savedApi.getResponse(); - for (HttpResponse importRsp : savedApi.getResponse()) { + for (HttpResponse importRsp : importApi.getResponse()) { boolean isExistence = false; for (HttpResponse existenceRsp : existenceResponseList) { if (StringUtils.equals(importRsp.getName(), existenceRsp.getName())) { @@ -120,6 +119,9 @@ public class HarParserApiDefinition extends HttpApiDefinitionImportAbstractParse existenceResponseList.add(importRsp); } } + if (CollectionUtils.isNotEmpty(existenceResponseList)) { + importApi.setResponse(existenceResponseList); + } } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/HTTPSamplerConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/HTTPSamplerConverter.java index 46f508c1b6..236a3f77c3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/HTTPSamplerConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/HTTPSamplerConverter.java @@ -112,7 +112,7 @@ public class HTTPSamplerConverter extends AbstractMsElementConverter samplerProxy.getBody().setRawBody(new RawBody() {{ this.setValue(v); }})); - } else if (StringUtils.isNotEmpty(bodyType) || ("POST".equalsIgnoreCase(source.getMethod()) && source.getArguments().getArgumentsAsMap().size() > 0)) { + } else if (StringUtils.isNotEmpty(bodyType) || (StringUtils.equalsAnyIgnoreCase(source.getMethod(), "POST", "PUT") && !source.getArguments().getArgumentsAsMap().isEmpty())) { samplerProxy.getBody().setBodyType(Body.BodyType.WWW_FORM.name()); List keyValues = new LinkedList<>(); source.getArguments().getArguments().forEach(params -> {