From 0b6a10e9a345bcb0edbe0610f9ca1d5bd7428de1 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Wed, 18 Sep 2024 13:34:22 +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=E6=96=87=E4=BB=B6=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=97=B6=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=88=9B=E5=BB=BA=E4=B8=8D=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046522 --user=宋天阳 【接口测试】导入HAR格式接口-新增接口成功-编辑导入接口-保存无反应 https://www.tapd.cn/55049933/s/1579539 --- .../api/parser/api/HarParserApiDefinition.java | 2 +- .../api/HttpApiDefinitionImportAbstractParser.java | 10 ++++++++++ .../service/definition/ApiDefinitionImportService.java | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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 5236b48418..06cd9166ee 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 @@ -242,7 +242,7 @@ public class HarParserApiDefinition extends HttpApiDefinitionImportAbstractParse HarRequest harRequest = entry.request; if (harRequest != null) { // css 、 js 略过 - if (StringUtils.equalsIgnoreCase(harRequest.method, HttpMethodConstants.GET.name()) && StringUtils.endsWithAny(harRequest.url, ".css", ".js")) { + if (StringUtils.equalsIgnoreCase(harRequest.method, HttpMethodConstants.GET.name()) && StringUtils.endsWithAny(harRequest.url.toLowerCase(), ".css", ".js", ".png", ".jpg", ".jpeg")) { continue; } String url = harRequest.url; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HttpApiDefinitionImportAbstractParser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HttpApiDefinitionImportAbstractParser.java index 69fdeff224..ecb1521bcc 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HttpApiDefinitionImportAbstractParser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/HttpApiDefinitionImportAbstractParser.java @@ -7,10 +7,12 @@ import io.metersphere.api.dto.converter.ApiImportFileParseResult; import io.metersphere.api.dto.definition.ApiDefinitionMockDTO; import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.request.ImportRequest; +import io.metersphere.api.dto.request.MsCommonElement; import io.metersphere.api.dto.request.http.MsHTTPConfig; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.parser.ApiDefinitionImportParser; +import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.dto.environment.auth.NoAuth; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.LogUtils; @@ -24,6 +26,7 @@ import java.io.InputStreamReader; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -109,6 +112,7 @@ public abstract class HttpApiDefinitionImportAbstractParser implements ApiDef httpConfig.setResponseTimeout(60000L); request.setOtherConfig(httpConfig); request.setAuthConfig(new NoAuth()); + // assertionConfig Body body = new Body(); body.setBinaryBody(new BinaryBody()); body.setFormDataBody(new FormDataBody()); @@ -120,6 +124,12 @@ public abstract class HttpApiDefinitionImportAbstractParser implements ApiDef body.setNoneBody(new NoneBody()); body.setBodyType(Body.BodyType.NONE.name()); request.setBody(body); + + MsCommonElement commonElement = new MsCommonElement(); + LinkedList children = new LinkedList<>(); + children.add(commonElement); + request.setChildren(children); + return request; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportService.java index 61ce967fac..6258c730a8 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportService.java @@ -680,6 +680,12 @@ public class ApiDefinitionImportService { this.updateApiDefinitionRequest(importApi, msProtocolTestElement, request.getPlatform()); apiDefinitionPreImportAnalysisResult.getUpdateApiData().add(importApi); } + } else if (!StringUtils.equalsIgnoreCase(importApi.getProtocol(), "HTTP")) { + /* + 非http的要进行更新,例如tcp最重要的是请求内容,不更新的话就会导致导入的内容丢失 + 而http判断是否一致主要还是请求里的key,不是value。只要key还不变就没关系 + */ + apiDefinitionPreImportAnalysisResult.getUpdateApiData().add(importApi); } } else { if (!isSameApi) {