diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/BinaryBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/BinaryBody.java index 2cd57c97ef..47b3380152 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/BinaryBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/BinaryBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; /** @@ -8,10 +7,8 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:25 */ @Data -@JsonTypeName("BINARY") -public class BinaryBody extends Body { - // todo 如果fileName能直接定义到文件,就不需要filePath - private String filePath; +public class BinaryBody { + private String fileId; private String fileName; private String description; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/Body.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/Body.java index c8e46def94..6b68e3cdea 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/Body.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/Body.java @@ -1,7 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Data; /** @@ -9,15 +7,27 @@ import lombok.Data; * @CreateTime: 2023-11-06 16:59 */ @Data -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "bodyType") -@JsonSubTypes({ - @JsonSubTypes.Type(value = NoneBody.class), - @JsonSubTypes.Type(value = FormDataBody.class), - @JsonSubTypes.Type(value = WWWFormBody.class), - @JsonSubTypes.Type(value = JsonBody.class), - @JsonSubTypes.Type(value = XmlBody.class), - @JsonSubTypes.Type(value = RawBody.class), - @JsonSubTypes.Type(value = BinaryBody.class) -}) -public abstract class Body { +public class Body { + /** + * 当前选择的请求体类型 + * @see BodyType + * 同时持久化多个类型的请求体 + */ + private String bodyType; + private NoneBody noneBody; + private FormDataBody formDataBody; + private WWWFormBody wwwFormBody; + private JsonBody jsonBody; + private XmlBody xmlBody; + private RawBody rawBody; + private BinaryBody binaryBody; + + public enum BodyType { + BINARY, + FORM_DATA, + NONE, + RAW, + WWW_FORM, + XML + } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataBody.java index ea5adb5466..2b655098a8 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; import java.util.List; @@ -10,7 +9,6 @@ import java.util.List; * @CreateTime: 2023-11-06 16:59 */ @Data -@JsonTypeName("FORM_DATA") -public class FormDataBody extends Body { +public class FormDataBody { private List fromValues; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/JsonBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/JsonBody.java index 493a1fb790..0985c09852 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/JsonBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/JsonBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; /** @@ -8,7 +7,18 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:25 */ @Data -@JsonTypeName("JSON") -public class JsonBody extends Body { - private String value; +public class JsonBody { + /** + * 是否启用 json-schema + */ + private Boolean enableJsonSchema; + /** + * 没有启用 json-schema 时的 json 参数值 + */ + private String jsonValue; + /** + * 启用 json-schema 时的参数对象 + * todo json-schema 编辑器待调研,暂时使用 Object 类型 + */ + private Object jsonSchema; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/NoneBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/NoneBody.java index 556cf18e11..68b1bc1958 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/NoneBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/NoneBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; /** @@ -8,6 +7,5 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:25 */ @Data -@JsonTypeName("NONE") -public class NoneBody extends Body { +public class NoneBody { } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/RawBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/RawBody.java index ba819b4924..9461769343 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/RawBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/RawBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; /** @@ -8,7 +7,6 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:25 */ @Data -@JsonTypeName("RAW") -public class RawBody extends Body { +public class RawBody { private String value; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/WWWFormBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/WWWFormBody.java index d590333fc8..6b59c1c416 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/WWWFormBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/WWWFormBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; import java.util.List; @@ -10,7 +9,6 @@ import java.util.List; * @CreateTime: 2023-11-06 16:59 */ @Data -@JsonTypeName("WWW_FORM") -public class WWWFormBody extends Body { +public class WWWFormBody { private List fromValues; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/XmlBody.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/XmlBody.java index 7a9286d002..eb5139a1e1 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/XmlBody.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/XmlBody.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.request.http.body; -import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Data; /** @@ -8,7 +7,6 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:25 */ @Data -@JsonTypeName("XML") -public class XmlBody extends Body { +public class XmlBody { private String value; } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java index 01ebe538b0..cdb045bef4 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java @@ -1,5 +1,4 @@ package io.metersphere.api.controller; -import io.metersphere.sdk.dto.api.request.http.body.Body; import io.metersphere.api.dto.definition.HttpResponse; import io.metersphere.sdk.util.ApiDataUtils; @@ -37,7 +36,8 @@ public class MsHTTPElementTest { MsHTTPElement msHTTPElement = getMsHttpElement(); - List bodies = new ArrayList<>(); + Body body = new Body(); + body.setBodyType(Body.BodyType.FORM_DATA.name()); FormDataBody formDataBody = new FormDataBody(); FormDataKV formDataKV = new FormDataKV(); @@ -52,38 +52,35 @@ public class MsHTTPElementTest { formDataKV.setValue("value"); formDataKV.setKey("key"); formDataBody.setFromValues(List.of(formDataKV)); - bodies.add(formDataBody); + body.setFormDataBody(formDataBody); WWWFormBody wwwFormBody = new WWWFormBody(); wwwFormBody.setFromValues(List.of(formDataKV)); - bodies.add(wwwFormBody); + body.setWwwFormBody(wwwFormBody); JsonBody jsonBody = new JsonBody(); - jsonBody.setValue("{}"); - bodies.add(jsonBody); + jsonBody.setJsonSchema("{}"); + body.setJsonBody(jsonBody); - bodies.add(new NoneBody()); + body.setNoneBody(new NoneBody()); RawBody rawBody = new RawBody(); rawBody.setValue("A"); - bodies.add(rawBody); + body.setRawBody(rawBody); XmlBody xmlBody = new XmlBody(); xmlBody.setValue(""); - bodies.add(xmlBody); + body.setXmlBody(xmlBody); BinaryBody binaryBody = new BinaryBody(); - binaryBody.setFilePath("/test/a.png"); + binaryBody.setFileId("sdfsf2222"); binaryBody.setFileName("a.png"); - bodies.add(binaryBody); + body.setBinaryBody(binaryBody); - - for (Object body : bodies) { - msHTTPElement.setBody((Body) body); - String json = ApiDataUtils.toJSONString(msHTTPElement); - Assertions.assertNotNull(json); - Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); - } + msHTTPElement.setBody(body); + String json = ApiDataUtils.toJSONString(msHTTPElement); + Assertions.assertNotNull(json); + Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); } @Test @@ -297,7 +294,9 @@ public class MsHTTPElementTest { formDataKV.setValue("value"); formDataKV.setKey("key"); formDataBody.setFromValues(List.of(formDataKV)); - httpResponse.setBody(formDataBody); + Body body = new Body(); + body.setBodyType(Body.BodyType.FORM_DATA.name()); + httpResponse.setBody(body); httpResponses.add(httpResponse); return httpResponses;