From af684b2b8ebdb1d7523016f78ace3b1df6135f6f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Sat, 11 May 2024 19:32:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E8=A6=86=E7=9B=96=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=95=B0=E6=8D=AE=E8=A2=AB=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/schema/JsonSchemaItem.java | 2 - .../ApiDefinitionImportUtilService.java | 85 +++++++++++-------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/schema/JsonSchemaItem.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/schema/JsonSchemaItem.java index 7d4e75cb2e..d00bb89257 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/schema/JsonSchemaItem.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/schema/JsonSchemaItem.java @@ -5,7 +5,6 @@ import io.metersphere.project.constants.PropertyConstant; import io.metersphere.sdk.constants.ValueEnum; import io.metersphere.system.valid.EnumValue; import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -29,7 +28,6 @@ public class JsonSchemaItem { /** * 参数ID */ - @NotBlank private String id; /** * 参数名称 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java index d7d1be0563..62595b0c82 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java @@ -608,56 +608,69 @@ public class ApiDefinitionImportUtilService { Body dbbody = dbRequest.getBody(); Body importBody = importRequest.getBody(); if (dbbody != null && importBody != null) { + if (!StringUtils.equals(dbbody.getBodyType(), importBody.getBodyType())) { + return false; + } //判断null类型 StringUtils.equals(String.valueOf(dbbody.getNoneBody()), String.valueOf(importBody.getNoneBody())); //判断form类型 - FormDataBody formDataBody = dbbody.getFormDataBody(); - FormDataBody importFormDataBody = importBody.getFormDataBody(); - if (ObjectUtils.isNotEmpty(formDataBody) || ObjectUtils.isNotEmpty(importFormDataBody)) { - List formValues = formDataBody.getFormValues(); - List importFormValues = importFormDataBody.getFormValues(); - if (CollectionUtils.isNotEmpty(formValues) || CollectionUtils.isNotEmpty(importFormValues)) { - List dbFormKeys = formValues.stream().map(FormDataKV::getKey).toList(); - List importFormKeys = importFormValues.stream().map(FormDataKV::getKey).toList(); - if (paramsIsSame(dbFormKeys, importFormKeys)) { - return false; + if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.FORM_DATA.name())) { + FormDataBody formDataBody = dbbody.getFormDataBody(); + FormDataBody importFormDataBody = importBody.getFormDataBody(); + if (ObjectUtils.isNotEmpty(formDataBody) || ObjectUtils.isNotEmpty(importFormDataBody)) { + List formValues = formDataBody.getFormValues(); + List importFormValues = importFormDataBody.getFormValues(); + if (CollectionUtils.isNotEmpty(formValues) || CollectionUtils.isNotEmpty(importFormValues)) { + List dbFormKeys = formValues.stream().map(FormDataKV::getKey).toList(); + List importFormKeys = importFormValues.stream().map(FormDataKV::getKey).toList(); + if (paramsIsSame(dbFormKeys, importFormKeys)) { + return false; + } } } } - //判读www类型 - WWWFormBody wwwBody = dbbody.getWwwFormBody(); - WWWFormBody importWwwBody = importBody.getWwwFormBody(); - if (ObjectUtils.isNotEmpty(wwwBody) || ObjectUtils.isNotEmpty(importWwwBody)) { - List wwwValues = wwwBody.getFormValues(); - List importWwwValues = importWwwBody.getFormValues(); - if (CollectionUtils.isNotEmpty(wwwValues) || CollectionUtils.isNotEmpty(importWwwValues)) { - List dbWwwKeys = wwwValues.stream().map(WWWFormKV::getKey).toList(); - List importWwwKeys = importWwwValues.stream().map(WWWFormKV::getKey).toList(); - if (paramsIsSame(dbWwwKeys, importWwwKeys)) { - return false; + if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.WWW_FORM.name())) { + //判读www类型 + WWWFormBody wwwBody = dbbody.getWwwFormBody(); + WWWFormBody importWwwBody = importBody.getWwwFormBody(); + if (ObjectUtils.isNotEmpty(wwwBody) || ObjectUtils.isNotEmpty(importWwwBody)) { + List wwwValues = wwwBody.getFormValues(); + List importWwwValues = importWwwBody.getFormValues(); + if (CollectionUtils.isNotEmpty(wwwValues) || CollectionUtils.isNotEmpty(importWwwValues)) { + List dbWwwKeys = wwwValues.stream().map(WWWFormKV::getKey).toList(); + List importWwwKeys = importWwwValues.stream().map(WWWFormKV::getKey).toList(); + if (paramsIsSame(dbWwwKeys, importWwwKeys)) { + return false; + } } } } + //TODO 判断binary类型 //判断raw类型 - RawBody rawBody = dbbody.getRawBody(); - RawBody importRawBody = importBody.getRawBody(); - if (ObjectUtils.isNotEmpty(rawBody) || ObjectUtils.isNotEmpty(importRawBody)) { - return false; - } - //判断json类型 - JsonBody jsonBody = dbbody.getJsonBody(); - JsonBody importJsonBody = importBody.getJsonBody(); - if (ObjectUtils.isNotEmpty(jsonBody) || ObjectUtils.isNotEmpty(importJsonBody)) { - if (StringUtils.isNotBlank(jsonBody.getJsonValue()) || StringUtils.isNotBlank(importJsonBody.getJsonValue())) { + if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.RAW.name())) { + RawBody rawBody = dbbody.getRawBody(); + RawBody importRawBody = importBody.getRawBody(); + if (ObjectUtils.isNotEmpty(rawBody) || ObjectUtils.isNotEmpty(importRawBody)) { return false; } - //判断jsonschema - JsonSchemaItem jsonSchema = jsonBody.getJsonSchema(); - JsonSchemaItem importJsonSchema = importJsonBody.getJsonSchema(); - if (jsonSchema != null && importJsonSchema != null) { - return jsonSchemaIsSame(jsonSchema, importJsonSchema); + } + //判断json类型 + if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.JSON.name())) { + //判断json类型 + JsonBody jsonBody = dbbody.getJsonBody(); + JsonBody importJsonBody = importBody.getJsonBody(); + if (ObjectUtils.isNotEmpty(jsonBody) || ObjectUtils.isNotEmpty(importJsonBody)) { + if (!StringUtils.equals(jsonBody.getJsonValue(), importJsonBody.getJsonValue())) { + return false; + } + //判断jsonschema + JsonSchemaItem jsonSchema = jsonBody.getJsonSchema(); + JsonSchemaItem importJsonSchema = importJsonBody.getJsonSchema(); + if (jsonSchema != null && importJsonSchema != null) { + return jsonSchemaIsSame(jsonSchema, importJsonSchema); + } } } }