From ae6fb6184a7edc80caeb3ef1fd7e3675588f9750 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Sun, 28 Jan 2024 11:55:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=AE=8C=E5=96=84=E8=AF=B7=E6=B1=82=E8=AF=A6=E6=83=85java?= =?UTF-8?q?=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/api/dto/ApiFile.java | 13 +++- .../api/dto/request/MsCommonElement.java | 6 ++ .../dto/request/assertion/MsAssertion.java | 16 +++++ .../request/assertion/MsAssertionConfig.java | 3 +- .../assertion/MsResponseBodyAssertion.java | 12 +++- .../assertion/MsResponseCodeAssertion.java | 4 +- .../assertion/MsResponseHeaderAssertion.java | 14 +++- .../assertion/body/MsBodyAssertionItem.java | 4 ++ .../assertion/body/MsDocumentAssertion.java | 12 +++- .../body/MsDocumentAssertionElement.java | 34 +++++++++ .../body/MsJSONPathAssertionItem.java | 13 +++- .../assertion/body/MsRegexAssertion.java | 2 + .../assertion/body/MsRegexAssertionItem.java | 3 + .../assertion/body/MsXPathAssertion.java | 6 +- .../assertion/body/MsXPathAssertionItem.java | 6 ++ .../api/dto/request/http/Header.java | 1 + .../dto/request/http/KeyValueEnableParam.java | 4 ++ .../api/dto/request/http/KeyValueParam.java | 4 ++ .../dto/request/http/KeyValueParamType.java | 43 +++++++++++ .../api/dto/request/http/MsHTTPConfig.java | 21 ++++++ .../api/dto/request/http/MsHTTPElement.java | 23 +++++- .../api/dto/request/http/QueryParam.java | 10 ++- .../api/dto/request/http/RestParam.java | 9 ++- .../api/dto/request/http/auth/HTTPAuth.java | 8 +++ .../api/dto/request/http/body/BinaryBody.java | 7 +- .../api/dto/request/http/body/Body.java | 70 +++++++++++++++++- .../dto/request/http/body/BodyParamType.java | 57 +++++++++++++++ .../dto/request/http/body/FormDataBody.java | 3 + .../api/dto/request/http/body/FormDataKV.java | 10 ++- .../api/dto/request/http/body/JsonBody.java | 14 ++-- .../api/dto/request/http/body/RawBody.java | 4 ++ .../dto/request/http/body/WWWFormBody.java | 3 + .../api/dto/request/http/body/WWWFormKV.java | 43 ++++++----- .../api/dto/request/http/body/XmlBody.java | 4 ++ .../processors/ExtractPostProcessor.java | 1 + .../dto/request/processors/MsProcessor.java | 13 ++++ .../request/processors/MsProcessorConfig.java | 8 ++- .../dto/request/processors/SQLProcessor.java | 11 +++ .../request/processors/ScriptProcessor.java | 10 ++- .../processors/TimeWaitingProcessor.java | 5 ++ .../request/processors/extract/MsExtract.java | 32 +++++++++ .../processors/extract/RegexExtract.java | 56 ++++++--------- .../extract/ResultMatchingExtract.java | 12 +++- .../processors/extract/XPathExtract.java | 6 ++ .../api/dto/schema/JsonSchemaItem.java | 72 ++++++++++++++++++- .../jmeter/body/MsBinaryBodyConverter.java | 3 +- .../extract/RegexExtractConverter.java | 44 +++++++++--- .../api/controller/MsHTTPElementTest.java | 6 +- 48 files changed, 664 insertions(+), 101 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParamType.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BodyParamType.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java index 32b18a2c5f..76000a6fd6 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/ApiFile.java @@ -1,16 +1,25 @@ package io.metersphere.api.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; +/** + * 接口执行所需要的文件 + */ @Data public class ApiFile { /** * 记录文件的ID,防止重名 - * 生成脚本时,通过 fileId + value(文件名) 获取文件路径 + * 生成脚本时,通过 fileId + fileName(文件名) 获取文件路径 */ + @NotBlank + @Size(max = 50) private String fileId; /** - * 文件名称 + * 文件名 */ + @NotBlank + @Size(max = 200) private String fileName; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/MsCommonElement.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/MsCommonElement.java index c5d8a1ce42..ec29fb5e4d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/MsCommonElement.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/MsCommonElement.java @@ -3,12 +3,15 @@ package io.metersphere.api.dto.request; import io.metersphere.api.dto.request.assertion.MsAssertionConfig; import io.metersphere.api.dto.request.processors.MsProcessorConfig; import io.metersphere.plugin.api.spi.AbstractMsTestElement; +import jakarta.validation.Valid; import lombok.Data; import lombok.EqualsAndHashCode; /** * 协议插件中通用的配置 + *
  * 添加到对应元素的 children 属性中
+ * 
* @Author: jianxing * @CreateTime: 2023-12-25 10:50 */ @@ -18,13 +21,16 @@ public class MsCommonElement extends AbstractMsTestElement { /** * 前置处理器配置 */ + @Valid private MsProcessorConfig preProcessorConfig; /** * 后置处理器配置 */ + @Valid private MsProcessorConfig postProcessorConfig; /** * 断言配置 */ + @Valid private MsAssertionConfig assertionConfig; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertion.java index f57681080b..c84212dec2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertion.java @@ -2,10 +2,24 @@ package io.metersphere.api.dto.request.assertion; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.metersphere.api.dto.request.processors.extract.JSONPathExtract; +import io.metersphere.api.dto.request.processors.extract.RegexExtract; +import io.metersphere.api.dto.request.processors.extract.XPathExtract; +import jakarta.validation.constraints.Size; import lombok.Data; /** * 断言 + *
+ * 该参数传参时,需要传入 assertionType 字段,用于区分是哪种断言
+ * assertionType 取值为:
+ *   RESPONSE_CODE {@link MsResponseCodeAssertion}
+ *   RESPONSE_HEADER {@link MsResponseHeaderAssertion}
+ *   RESPONSE_BODY {@link MsResponseBodyAssertion}
+ *   RESPONSE_TIME {@link MsResponseTimeAssertion}
+ *   SCRIPT {@link MsScriptAssertion}
+ *   VARIABLE {@link MsVariableAssertion}
+ * 
*/ @Data @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "assertionType") @@ -20,10 +34,12 @@ import lombok.Data; public abstract class MsAssertion { /** * 是否启用 + * 默认启用 */ private Boolean enable = true; /** * 断言名称 */ + @Size(max = 100) private String name; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertionConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertionConfig.java index 7ca3c4e782..657e4285af 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertionConfig.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsAssertionConfig.java @@ -13,8 +13,9 @@ import java.util.List; public class MsAssertionConfig { /** * 是否启用全局断言 + * 默认为 false */ - private Boolean enableGlobal; + private Boolean enableGlobal = false; /** * 断言列表 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseBodyAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseBodyAssertion.java index d8ff0e6683..0a9f977161 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseBodyAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseBodyAssertion.java @@ -5,6 +5,8 @@ import io.metersphere.api.dto.request.assertion.body.MsDocumentAssertion; import io.metersphere.api.dto.request.assertion.body.MsJSONPathAssertion; import io.metersphere.api.dto.request.assertion.body.MsRegexAssertion; import io.metersphere.api.dto.request.assertion.body.MsXPathAssertion; +import io.metersphere.system.valid.EnumValue; +import jakarta.validation.Valid; import lombok.Data; import java.util.HashMap; @@ -26,24 +28,29 @@ public class MsResponseBodyAssertion extends MsAssertion { * 后端从设计层面支持多种断言,前端只支持一种 * 同时切换可以同时持久化两种类型 * - * @see MsBodyAssertionType + * 取值参考 {@link MsBodyAssertionType} */ + @EnumValue(enumClass = MsBodyAssertionType.class) private String assertionBodyType; /** * jsonPath断言 */ + @Valid private MsJSONPathAssertion jsonPathAssertion; /** * xpath断言 */ + @Valid private MsXPathAssertion xpathAssertion; /** * 文档断言 */ + @Valid private MsDocumentAssertion documentAssertion; /** * 正则断言 */ + @Valid private MsRegexAssertion regexAssertion; private static Map bodyAssertionClassMap = new HashMap<>(); @@ -68,6 +75,9 @@ public class MsResponseBodyAssertion extends MsAssertion { return boadyAssertionMap.get(MsBodyAssertionType.valueOf(assertionBodyType)); } + /** + * 请求体断言类型 + */ public enum MsBodyAssertionType { /** * 正则断言 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseCodeAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseCodeAssertion.java index 571d67ebf0..05b80cb568 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseCodeAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseCodeAssertion.java @@ -1,6 +1,7 @@ package io.metersphere.api.dto.request.assertion; import com.fasterxml.jackson.annotation.JsonTypeName; +import jakarta.validation.constraints.Size; import lombok.Data; /** @@ -15,8 +16,9 @@ public class MsResponseCodeAssertion extends MsAssertion { * 不校验即忽略状态 * 选择其他条件时,也忽略状态 * 不校验可搭配其他校验使用 - * @see io.metersphere.sdk.constants.MsAssertionCondition + * 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition} */ + @Size(max = 50) private String condition; /** * 匹配值 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseHeaderAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseHeaderAssertion.java index c583271ea5..608b1bfb02 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseHeaderAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/MsResponseHeaderAssertion.java @@ -1,6 +1,8 @@ package io.metersphere.api.dto.request.assertion; import com.fasterxml.jackson.annotation.JsonTypeName; +import io.metersphere.system.valid.EnumValue; +import jakarta.validation.Valid; import lombok.Data; import java.util.List; @@ -13,14 +15,21 @@ import java.util.List; @Data @JsonTypeName("RESPONSE_HEADER") public class MsResponseHeaderAssertion extends MsAssertion { - + /** + * 断言列表 + */ + @Valid private List assertions; + /** + * 响应头断言项 + */ @Data public static class ResponseHeaderAssertionItem { /** * 是否启用 + * 默认启用 */ private Boolean enable = true; /** @@ -29,8 +38,9 @@ public class MsResponseHeaderAssertion extends MsAssertion { private String header; /** * 匹配条件 - * 值为 MsAssertionCondition + * 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition} */ + @EnumValue(enumClass = io.metersphere.sdk.constants.MsAssertionCondition.class) private String condition; /** * 匹配值 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsBodyAssertionItem.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsBodyAssertionItem.java index 7fba37263c..1e4b08f06e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsBodyAssertionItem.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsBodyAssertionItem.java @@ -9,5 +9,9 @@ import lombok.Data; */ @Data public abstract class MsBodyAssertionItem { + /** + * 是否启用 + * 默认启用 + */ private Boolean enable = true; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertion.java index 3803c80a98..228470beb4 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertion.java @@ -1,5 +1,8 @@ package io.metersphere.api.dto.request.assertion.body; +import io.metersphere.system.valid.EnumValue; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; import lombok.Data; /** @@ -13,6 +16,7 @@ public class MsDocumentAssertion extends MsBodyAssertionItem { * 跟随定义的apiId * 传空为不跟随接口定义 */ + @Size(max = 50) private String followApiId; /** * 文档类型 @@ -21,16 +25,20 @@ public class MsDocumentAssertion extends MsBodyAssertionItem { * 这里跟前端数据结构有差异 * 后端从设计层面支持多种文档格式,前端只支持一种 * 同时切换可以同时持久化两种格式 - * @see DocumentType - */ + * + * 取值参考 {@link DocumentType} += */ + @EnumValue(enumClass = DocumentType.class) private String documentType; /** * json格式的文档断言 */ + @Valid private MsDocumentAssertionElement jsonAssertion; /** * xml格式的文档断言 */ + @Valid private MsDocumentAssertionElement xmlAssertion; public enum DocumentType { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertionElement.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertionElement.java index a3e3f2d3cf..5b5d515476 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertionElement.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsDocumentAssertionElement.java @@ -1,10 +1,16 @@ package io.metersphere.api.dto.request.assertion.body; +import io.metersphere.sdk.constants.MsAssertionCondition; +import io.metersphere.sdk.constants.ValueEnum; +import io.metersphere.system.valid.EnumValue; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; import lombok.Data; import java.util.List; /** + * 文档断言项 * @Author: jianxing * @CreateTime: 2023-11-23 11:43 */ @@ -14,6 +20,7 @@ public class MsDocumentAssertionElement { /** * 参数名 */ + @Size(max = 100) private String paramName; /** * 必含 @@ -21,7 +28,9 @@ public class MsDocumentAssertionElement { private Boolean include = false; /** * 类型 + * 取值参考 {@link DocumentAssertionType} */ + @EnumValue(enumClass = DocumentAssertionType.class) private String type; /** * 类型校验 @@ -29,7 +38,9 @@ public class MsDocumentAssertionElement { private Boolean typeVerification = false; /** * 匹配条件 + * 取值参考 {@link MsAssertionCondition} */ + @EnumValue(enumClass = MsAssertionCondition.class) private String condition; /** * 匹配值 @@ -43,5 +54,28 @@ public class MsDocumentAssertionElement { /** * 子对象 */ + @Valid private List children; + + /** + * 文档断言类型 + */ + public enum DocumentAssertionType implements ValueEnum { + STRING("string"), + NUMBER("number"), + INTEGER("integer"), + BOOLEAN("boolean"), + ARRAY("array"); + + private String value; + + DocumentAssertionType(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsJSONPathAssertionItem.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsJSONPathAssertionItem.java index 93bccc82b5..e7cd653fa7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsJSONPathAssertionItem.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsJSONPathAssertionItem.java @@ -4,18 +4,27 @@ import lombok.Data; import org.apache.commons.lang3.StringUtils; /** - * * JSONPath断言 + * * @Author: jianxing * @CreateTime: 2023-11-23 14:04 */ @Data public class MsJSONPathAssertionItem extends MsBodyAssertionItem { + /** + * 表达式 + */ private String expression; + /** + * 匹配条件 + * 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition} + */ private String condition; + /** + * 匹配值 + */ private String expectedValue; - public boolean isValid() { return StringUtils.isNotBlank(expression) && StringUtils.isNotBlank(condition) && StringUtils.isNotBlank(expectedValue); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertion.java index 6dedf8d041..3f880cb127 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertion.java @@ -1,5 +1,6 @@ package io.metersphere.api.dto.request.assertion.body; +import jakarta.validation.Valid; import lombok.Data; import java.util.List; @@ -14,5 +15,6 @@ public class MsRegexAssertion { /** * 断言列表 */ + @Valid private List assertions; } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertionItem.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertionItem.java index 2c66ee2bd3..d4b8179def 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertionItem.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsRegexAssertionItem.java @@ -10,6 +10,9 @@ import org.apache.commons.lang3.StringUtils; */ @Data public class MsRegexAssertionItem extends MsBodyAssertionItem { + /** + * 表达式 + */ private String expression; public boolean isValid() { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertion.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertion.java index c8360199d6..32f914b8b7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertion.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertion.java @@ -1,6 +1,7 @@ package io.metersphere.api.dto.request.assertion.body; +import io.metersphere.system.valid.EnumValue; import lombok.Data; import java.util.List; @@ -14,11 +15,12 @@ import java.util.List; public class MsXPathAssertion { /** * 响应内容格式 - * xml 或者 html + * 取值参考 {@link ResponseFormat} */ + @EnumValue(enumClass = ResponseFormat.class) private String responseFormat; /** - * xpath断言 + * xpath断言列表 */ private List assertions; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertionItem.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertionItem.java index 317a7609a5..bdf5c70139 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertionItem.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/assertion/body/MsXPathAssertionItem.java @@ -11,7 +11,13 @@ import org.apache.commons.lang3.StringUtils; */ @Data public class MsXPathAssertionItem extends MsBodyAssertionItem { + /** + * 表达式 + */ private String expression; + /** + * 匹配值 + */ private String expectedValue; public boolean isValid() { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/Header.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/Header.java index 386da335a0..88d4a74eb2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/Header.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/Header.java @@ -3,6 +3,7 @@ package io.metersphere.api.dto.request.http; import lombok.Data; /** + * 请求头 * @Author: jianxing * @CreateTime: 2023-11-06 16:59 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueEnableParam.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueEnableParam.java index 2d62bc1b17..22c76742a1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueEnableParam.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueEnableParam.java @@ -1,8 +1,10 @@ package io.metersphere.api.dto.request.http; +import jakarta.validation.constraints.Size; import lombok.Data; /** + * 可以启用禁用的键值对参数 * @Author: jianxing * @CreateTime: 2023-11-06 17:27 */ @@ -10,10 +12,12 @@ import lombok.Data; public class KeyValueEnableParam extends KeyValueParam { /** * 是否启用 + * 默认启用 */ private Boolean enable = true; /** * 描述 */ + @Size(max = 500) private String description; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParam.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParam.java index cc3d706e00..01e03e390c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParam.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParam.java @@ -1,9 +1,11 @@ package io.metersphere.api.dto.request.http; +import jakarta.validation.constraints.Size; import lombok.Data; import org.apache.commons.lang3.StringUtils; /** + * 键值对参数 * @Author: jianxing * @CreateTime: 2023-11-06 17:27 */ @@ -12,10 +14,12 @@ public class KeyValueParam { /** * 键 */ + @Size(max = 100) private String key; /** * 值 */ + @Size(max = 100) private String value; public boolean isValid() { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParamType.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParamType.java new file mode 100644 index 0000000000..bd4dbd3697 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/KeyValueParamType.java @@ -0,0 +1,43 @@ +package io.metersphere.api.dto.request.http; + +import io.metersphere.sdk.constants.ValueEnum; + +/** + * 键值对参数的参数类型 + * rest 参数和 query 参数 + * @Author: jianxing + * @CreateTime: 2024-01-27 11:22 + */ +public enum KeyValueParamType implements ValueEnum { + /** + * 字符串类型 + * 默认 application/text + */ + STRING("string"), + /** + * 整型 + * 默认 application/text + */ + INTEGER("integer"), + /** + * 数值型 + * 默认 application/text + */ + NUMBER("number"), + /** + * 数组 + * 默认 application/text + */ + ARRAY("array"); + + private String value; + + KeyValueParamType(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java index e5b47486fb..ad43ba7067 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPConfig.java @@ -1,16 +1,37 @@ package io.metersphere.api.dto.request.http; +import jakarta.validation.constraints.Size; import lombok.Data; /** + * http 的其他配置项 + * * @Author: jianxing * @CreateTime: 2023-11-07 10:47 */ @Data public class MsHTTPConfig { + /** + * 连接超时 + */ private Long connectTimeout; + /** + * 响应超时 + */ private Long responseTimeout; + /** + * 证书别名 + */ + @Size(max = 200) private String certificateAlias; + /** + * 是否跟随重定向 + * 默认 true + */ private Boolean followRedirects = true; + /** + * 是否自动重定向 + * 默认 false + */ private Boolean autoRedirects = false; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java index a968f119ab..9148d1c25f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/MsHTTPElement.java @@ -3,50 +3,69 @@ package io.metersphere.api.dto.request.http; import io.metersphere.api.dto.request.http.auth.HTTPAuth; import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.plugin.api.spi.AbstractMsTestElement; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; import java.util.List; - +/** + * Http接口详情 + *
+ * 其中包括:接口调试、接口定义、接口用例、场景的自定义请求 的详情
+ * 接口协议插件的接口详情也类似
+ * 
+ */ @Data @EqualsAndHashCode(callSuper = true) public class MsHTTPElement extends AbstractMsTestElement { - // todo 完善字段校验 /** * 完整请求地址 + * 自定义请求时,使用该字段 */ + @Size(max = 500) private String url; /** * 接口定义和用例的请求路径 */ + @Size(max = 500) private String path; /** * 请求方法 */ + @NotBlank + @Size(max = 10) private String method; /** * 请求体 */ + @Valid private Body body; /** * 请求头 */ + @Valid private List
headers; /** * rest参数 */ + @Valid private List rest; /** * query参数 */ + @Valid private List query; /** * 其他配置 */ + @Valid private MsHTTPConfig otherConfig; /** * 认证配置 */ + @Valid private HTTPAuth authConfig; } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/QueryParam.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/QueryParam.java index 90bd9f4034..824f04a054 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/QueryParam.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/QueryParam.java @@ -1,8 +1,10 @@ package io.metersphere.api.dto.request.http; +import io.metersphere.system.valid.EnumValue; import lombok.Data; /** + * query 参数 * @Author: jianxing * @CreateTime: 2023-11-06 16:59 */ @@ -11,10 +13,11 @@ public class QueryParam extends KeyValueEnableParam { /** * 参数类型 - * 默认string,可选integer、number、array - * todo + * 取值参考 {@link KeyValueParamType} + * 默认String */ - private String paramType; + @EnumValue(enumClass = KeyValueParamType.class) + private String paramType = KeyValueParamType.STRING.getValue(); /** * 是否必填 */ @@ -29,6 +32,7 @@ public class QueryParam extends KeyValueEnableParam { private Integer maxLength; /** * 是否编码 + * 默认 false */ private Boolean encode = false; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/RestParam.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/RestParam.java index ecdf4ce8ca..ab8fb49bcb 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/RestParam.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/RestParam.java @@ -1,8 +1,10 @@ package io.metersphere.api.dto.request.http; +import io.metersphere.system.valid.EnumValue; import lombok.Data; /** + * rest参数 * @Author: jianxing * @CreateTime: 2023-11-06 16:59 */ @@ -10,10 +12,11 @@ import lombok.Data; public class RestParam extends KeyValueEnableParam { /** * 参数类型 - * 默认string,可选integer、number、array - * todo + * 取值参考 {@link KeyValueParamType} + * 默认String */ - private String paramType; + @EnumValue(enumClass = KeyValueParamType.class) + private String paramType = KeyValueParamType.STRING.getValue(); /** * 是否必填 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java index 30f8ae34a4..d0e66696c1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/auth/HTTPAuth.java @@ -5,6 +5,14 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Data; /** + * http 认证配置 + *
+ * 该参数传参时,需要传入 authType 字段,用于区分是哪种认证方式
+ * authType 取值为:
+ *   BASIC ({@link BasicAuth})
+ *   DIGEST ({@link DigestAuth})
+ *   NONE ({@link NoAuth})
+ * 
* @Author: jianxing * @CreateTime: 2023-11-07 11:00 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BinaryBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BinaryBody.java index eff6557b3a..6558b883a2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BinaryBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BinaryBody.java @@ -4,11 +4,14 @@ import io.metersphere.api.dto.ApiFile; import lombok.Data; /** + * binary 请求体 * @Author: jianxing * @CreateTime: 2023-11-06 18:25 */ @Data -public class BinaryBody { - private ApiFile bodyFile; +public class BinaryBody extends ApiFile{ + /** + * 描述 + */ private String description; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/Body.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/Body.java index b48a2f5419..eacc722d2a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/Body.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/Body.java @@ -1,11 +1,15 @@ package io.metersphere.api.dto.request.http.body; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; import java.util.HashMap; import java.util.Map; /** + * 请求体 * @Author: jianxing * @CreateTime: 2023-11-06 16:59 */ @@ -13,18 +17,58 @@ import java.util.Map; public class Body { /** * 当前选择的请求体类型 - * @see BodyType + * 可选值为 {@link BodyType} * 同时持久化多个类型的请求体 */ + @NotBlank + @Size(max = 20) private String bodyType; + /** + * None 请求体 + * 当 bodyType 为 NONE 时,使用该字段 + */ private NoneBody noneBody; + /** + * form-data 请求体 + * 当 bodyType 为 FORM_DATA 时,使用该字段 + */ + @Valid private FormDataBody formDataBody; + /** + * x-www-form-urlencoded 请求体 + * 当 bodyType 为 WWW_FORM 时,使用该字段 + */ + @Valid private WWWFormBody wwwFormBody; + /** + * json 请求体 + * 当 bodyType 为 JSON 时,使用该字段 + */ + @Valid private JsonBody jsonBody; + /** + * xml 请求体 + * 当 bodyType 为 XML 时,使用该字段 + */ + @Valid private XmlBody xmlBody; + /** + * raw 请求体 + * 当 bodyType 为 RAW 时,使用该字段 + */ + @Valid private RawBody rawBody; + /** + * binary 请求体 + * 当 bodyType 为 BINARY 时,使用该字段 + */ + @Valid private BinaryBody binaryBody; + /** + * 请求体类型与请求体类的映射 + * 不需要传惨 + */ private static Map bodyTypeClassMap = new HashMap<>(); static { @@ -54,13 +98,37 @@ public class Body { } + /** + * 请求体类型 + */ public enum BodyType { + /** + * 二进制文件 + */ BINARY, + /** + * form-data + */ FORM_DATA, + /** + * none + */ NONE, + /** + * raw + */ RAW, + /** + * x-www-form-urlencoded + */ WWW_FORM, + /** + * xml + */ XML, + /** + * json + */ JSON } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BodyParamType.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BodyParamType.java new file mode 100644 index 0000000000..3a939ed10b --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/BodyParamType.java @@ -0,0 +1,57 @@ +package io.metersphere.api.dto.request.http.body; + +/** + * 请求体键值参数的参数类型 + * x-www-form-urlencoded 和 form-data + * @Author: jianxing + * @CreateTime: 2024-01-26 10:59 + */ + +import io.metersphere.sdk.constants.ValueEnum; + +/** + * + */ +public enum BodyParamType implements ValueEnum { + /** + * 字符串类型 + * 默认 application/text + */ + STRING("string"), + /** + * 整型 + * 默认 application/text + */ + INTEGER("integer"), + /** + * 数值型 + * 默认 application/text + */ + NUMBER("number"), + /** + * 数组 + * 默认 application/text + */ + ARRAY("array"), + /** + * 文件类型 + * 默认 application/octet-stream + */ + FILE("file"), + /** + * json 类型 + * 默认 application/json + */ + JSON("json"); + + private String value; + + BodyParamType(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataBody.java index d6c1f078d4..c39056968c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataBody.java @@ -10,5 +10,8 @@ import java.util.List; */ @Data public class FormDataBody { + /** + * form-data 请求体的键值对列表 + */ private List fromValues; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataKV.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataKV.java index 085003194b..757dc35f7b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataKV.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/FormDataKV.java @@ -1,21 +1,29 @@ package io.metersphere.api.dto.request.http.body; import io.metersphere.api.dto.ApiFile; +import jakarta.validation.Valid; import lombok.Data; import org.apache.commons.lang3.StringUtils; import java.util.List; /** + * form-data 请求体的键值对 * @Author: jianxing * @CreateTime: 2023-11-06 18:11 */ @Data public class FormDataKV extends WWWFormKV { + /** + * 参数的文件列表 + * 当 paramType 为 FILE 时,参数值使用该字段 + * 其他类型使用 value字段 + */ + @Valid private List files; public boolean isFile() { - return StringUtils.equalsIgnoreCase(getParamType(), WWWFormParamType.FILE.name()); + return StringUtils.equalsIgnoreCase(getParamType(), BodyParamType.FILE.getValue()); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/JsonBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/JsonBody.java index 82ca9e7378..405b300ae4 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/JsonBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/JsonBody.java @@ -1,9 +1,11 @@ package io.metersphere.api.dto.request.http.body; import io.metersphere.api.dto.schema.JsonSchemaItem; +import jakarta.validation.Valid; import lombok.Data; /** + * json 请求体 * @Author: jianxing * @CreateTime: 2023-11-06 18:25 */ @@ -11,19 +13,23 @@ import lombok.Data; public class JsonBody { /** * 是否启用 json-schema + * 默认false */ private Boolean enableJsonSchema = false; /** - * 没有启用 json-schema 时的 json 参数值 + * json 参数值 + * 当 enableJsonSchema 为 false 时使用该值 */ private String jsonValue; /** * 启用 json-schema 时的参数对象 - * todo json-schema 编辑器待调研,暂时使用 Object 类型 + * 当 enableJsonSchema 为 true 时使用该值 */ + @Valid private JsonSchemaItem jsonSchema; /** - * 是否开启转换 + * 是否开启动态转换 + * 默认为 false */ - private Boolean enable = false; + private Boolean enableTransition = false; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/RawBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/RawBody.java index 10c52e9590..8b4a8de2f7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/RawBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/RawBody.java @@ -3,10 +3,14 @@ package io.metersphere.api.dto.request.http.body; import lombok.Data; /** + * raw 请求体 * @Author: jianxing * @CreateTime: 2023-11-06 18:25 */ @Data public class RawBody { + /** + * 请求体值 + */ private String value; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormBody.java index 17c2db2a59..54cde69b1c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormBody.java @@ -1,14 +1,17 @@ package io.metersphere.api.dto.request.http.body; +import jakarta.validation.Valid; import lombok.Data; import java.util.List; /** + * x-www-form-urlencoded 请求体的键值对列表 * @Author: jianxing * @CreateTime: 2023-11-06 16:59 */ @Data public class WWWFormBody { + @Valid private List fromValues; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormKV.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormKV.java index 71b46cfc5c..44d83064cf 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormKV.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/WWWFormKV.java @@ -1,9 +1,13 @@ package io.metersphere.api.dto.request.http.body; import io.metersphere.api.dto.request.http.KeyValueEnableParam; +import io.metersphere.system.valid.EnumValue; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; /** + * x-www-form-urlencoded 请求体键值对 * @Author: jianxing * @CreateTime: 2023-11-06 18:11 */ @@ -11,28 +15,33 @@ import lombok.Data; public class WWWFormKV extends KeyValueEnableParam { /** * 参数类型 - * - * @see WWWFormParamType + * 取值参考 {@link BodyParamType} 中的 value 属性 */ + @NotBlank + @Size(max = 20) + @EnumValue(enumClass = BodyParamType.class) private String paramType; + /** + * 是否必填 + * 默认为 false + */ private Boolean required = false; + /** + * 最小长度 + */ private Integer minLength; + /** + * 最大长度 + */ private Integer maxLength; + /** + * 参数的 contentType + */ + @Size(max = 100) private String contentType; + /** + * 是否对参数进行编码 + * 默认 false + */ private Boolean encode = false; - - enum WWWFormParamType { - /** - * 默认 application/text - */ - STRING, INTEGER, NUMBER, ARRAY, - /** - * 默认 application/octet-stream - */ - FILE, - /** - * 默认 application/json - */ - JSON - } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/XmlBody.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/XmlBody.java index d1efe49014..037ec072d5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/XmlBody.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/http/body/XmlBody.java @@ -3,10 +3,14 @@ package io.metersphere.api.dto.request.http.body; import lombok.Data; /** + * xml 请求体 * @Author: jianxing * @CreateTime: 2023-11-06 18:25 */ @Data public class XmlBody { + /** + * 请求体值 + */ private String value; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ExtractPostProcessor.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ExtractPostProcessor.java index d48cdd4ea3..9ddb699404 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ExtractPostProcessor.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ExtractPostProcessor.java @@ -7,6 +7,7 @@ import lombok.Data; import java.util.List; /** + * 提取处理器配置 * @Author: jianxing * @CreateTime: 2023-11-22 11:08 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessor.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessor.java index a9769b6997..f8b00f5256 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessor.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessor.java @@ -2,9 +2,20 @@ package io.metersphere.api.dto.request.processors; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; /** + * 前后置处理器配置 + *
+ * 该参数传参时,需要传入 processorType 字段,用于区分是哪种认证处理器
+ * processorType 取值为:
+ *   SCRIPT {@link ScriptProcessor}
+ *   SQL {@link SQLProcessor}
+ *   TIME_WAITING {@link TimeWaitingProcessor}
+ *   EXTRACT {@link ExtractPostProcessor}
+ * 
  * @Author: jianxing
  * @CreateTime: 2023-11-07  10:17
  */
@@ -20,6 +31,8 @@ public abstract class MsProcessor {
     /**
      * 名称
      */
+    @NotBlank
+    @Size(max = 100)
     private String name;
     /**
      * 是否启用
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessorConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessorConfig.java
index 27a35b8a29..b6b2866d2f 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessorConfig.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/MsProcessorConfig.java
@@ -1,10 +1,12 @@
 package io.metersphere.api.dto.request.processors;
 
+import jakarta.validation.Valid;
 import lombok.Data;
 
 import java.util.List;
 
 /**
+ * 前后置处理器配置
  * @Author: jianxing
  * @CreateTime: 2023-11-07  10:17
  */
@@ -12,10 +14,12 @@ import java.util.List;
 public class MsProcessorConfig {
     /**
      * 是否启用全局前置
+     * 默认为 false
      */
-    private Boolean enableGlobal;
+    private Boolean enableGlobal = false;
     /**
-     * 处理器
+     * 处理器列表
      */
+    @Valid
     private List processors;
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/SQLProcessor.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/SQLProcessor.java
index 8a4b647805..8b13f372e1 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/SQLProcessor.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/SQLProcessor.java
@@ -3,11 +3,15 @@ package io.metersphere.api.dto.request.processors;
 import com.fasterxml.jackson.annotation.JsonTypeName;
 import io.metersphere.api.dto.request.http.KeyValueEnableParam;
 import io.metersphere.api.dto.request.http.KeyValueParam;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 import java.util.List;
 
 /**
+ * SQL 处理器
  * @Author: jianxing
  * @CreateTime: 2023-11-06  21:12
  */
@@ -25,25 +29,32 @@ public class SQLProcessor extends MsProcessor {
     /**
      * 存储结果
      */
+    @Size(max = 200)
     private String resultVariable;
     /**
      * 按列存储
      */
+    @Size(max = 200)
     private String variableNames;
     /**
      * 变量列表
      */
+    @Valid
     private List variables;
     /**
      * 环境ID
      */
+    @Size(max = 50)
     private String environmentId;
     /**
      * 数据源ID
      */
+    @NotBlank
+    @Size(max = 50)
     private String dataSourceId;
     /**
      * 提取参数
      */
+    @Valid
     private List extractParams;
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ScriptProcessor.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ScriptProcessor.java
index 7807899d82..e76787a3d3 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ScriptProcessor.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/ScriptProcessor.java
@@ -3,6 +3,8 @@ package io.metersphere.api.dto.request.processors;
 import com.fasterxml.jackson.annotation.JsonTypeName;
 import io.metersphere.api.dto.request.http.KeyValueParam;
 import io.metersphere.project.constants.ScriptLanguageType;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 import java.util.List;
@@ -20,19 +22,23 @@ public class ScriptProcessor extends MsProcessor {
     private String script;
     /**
      * 脚本语言
-     * @see ScriptLanguageType
+     * {@link ScriptLanguageType}
      */
+    @Size(max = 20)
     private String scriptLanguage;
     /**
      * 是否启用公共脚本
+     * 默认为 false
      */
     private Boolean enableCommonScript = false;
     /**
-     * 脚本ID
+     * 公共脚本ID
      */
+    @Size(max = 50)
     private String scriptId;
     /**
      * 公共脚本入参
      */
+    @Valid
     private List params;
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/TimeWaitingProcessor.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/TimeWaitingProcessor.java
index 881892550f..972e414334 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/TimeWaitingProcessor.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/TimeWaitingProcessor.java
@@ -4,11 +4,16 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
 import lombok.Data;
 
 /**
+ * 等待时间处理器
  * @Author: jianxing
  * @CreateTime: 2023-11-07  09:59
  */
 @Data
 @JsonTypeName("TIME_WAITING")
 public class TimeWaitingProcessor extends MsProcessor {
+    /**
+     * 等待时间
+     * 单位:毫秒
+     */
     private Integer delay;
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/MsExtract.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/MsExtract.java
index 16d7155b2a..9ea7926bca 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/MsExtract.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/MsExtract.java
@@ -2,9 +2,21 @@ package io.metersphere.api.dto.request.processors.extract;
 
 import com.fasterxml.jackson.annotation.JsonSubTypes;
 import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import io.metersphere.system.valid.EnumValue;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 import org.apache.commons.lang3.StringUtils;
 
+/**
+ * 提取处理器
+ * 
+ * 该参数传参时,需要传入 extractType 字段,用于区分是哪种提取
+ * extractType 取值为:
+ *   REGEX {@link RegexExtract}
+ *   JSON_PATH {@link JSONPathExtract}
+ *   X_PATH {@link XPathExtract}
+ * 
+ */
 @Data
 @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "extractType")
 @JsonSubTypes({
@@ -16,14 +28,19 @@ public abstract class MsExtract {
     /**
      * 变量名
      */
+    @Size(max = 100)
     private String variableName;
     /**
      * 参数类型
+     * 取值参考 {@link MsExtractType}
      */
+    @Size(max = 100)
+    @EnumValue(enumClass = MsExtractType.class)
     private String variableType;
     /**
      * 表达式
      */
+    @Size(max = 200)
     private String expression;
     /**
      * 是否启用
@@ -33,4 +50,19 @@ public abstract class MsExtract {
     public boolean isValid() {
         return StringUtils.isNotBlank(variableName) && StringUtils.isNotBlank(expression);
     }
+
+    public enum MsExtractType {
+        /**
+         * 临时参数
+         */
+        TEMPORARY,
+        /**
+         * 环境参数
+         */
+        ENVIRONMENT,
+        /**
+         * 全局参数
+         */
+        GLOBAL;
+    }
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/RegexExtract.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/RegexExtract.java
index c1e15354a4..fb58122c98 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/RegexExtract.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/RegexExtract.java
@@ -1,6 +1,7 @@
 package io.metersphere.api.dto.request.processors.extract;
 
 import com.fasterxml.jackson.annotation.JsonTypeName;
+import io.metersphere.system.valid.EnumValue;
 import lombok.Data;
 
 @Data
@@ -8,54 +9,43 @@ import lombok.Data;
 public class RegexExtract extends ResultMatchingExtract {
     /**
      * 表达式匹配规则
-     * @see ExpressionRuleType
+     * 取值参考 {@link ExpressionRuleType} 中的 value
+     * 默认为表达式匹配
      */
-    private String expressionMatchingRule;
+    @EnumValue(enumClass = ExpressionRuleType.class)
+    private String expressionMatchingRule = ExpressionRuleType.EXPRESSION.name();
     /**
      * 提取范围
-     * @see ExtractScope
+     * 取值参考 {@link ExtractScope}
      */
+    @EnumValue(enumClass = ExtractScope.class)
     private String extractScope;
 
+    /**
+     * 表达式匹配规则
+     */
     public enum ExpressionRuleType {
         /**
          * 匹配表达式
          */
-        EXPRESSION("$1$"),
+        EXPRESSION,
         /**
          * 匹配组
          */
-        GROUP("$0$");
-
-        private String value;
-
-        ExpressionRuleType(String value) {
-            this.value = value;
-        }
-
-        public String getValue() {
-            return value;
-        }
+        GROUP;
     }
 
+    /**
+     * 提取对象
+     */
     public enum ExtractScope {
-        BODY("false"),
-        REQUEST_HEADERS("request_headers"),
-        UNESCAPED_BODY("unescaped"),
-        BODY_AS_DOCUMENT("as_document"),
-        RESPONSE_HEADERS("true"),
-        URL("URL"),
-        RESPONSE_CODE("code"),
-        RESPONSE_MESSAGE("message");
-
-        private String value;
-
-        ExtractScope(String value) {
-            this.value = value;
-        }
-
-        public String getValue() {
-            return value;
-        }
+        BODY,
+        REQUEST_HEADERS,
+        UNESCAPED_BODY,
+        BODY_AS_DOCUMENT,
+        RESPONSE_HEADERS,
+        URL,
+        RESPONSE_CODE,
+        RESPONSE_MESSAGE;
     }
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/ResultMatchingExtract.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/ResultMatchingExtract.java
index ab2bfa7bf2..4df858bdbb 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/ResultMatchingExtract.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/ResultMatchingExtract.java
@@ -1,19 +1,27 @@
 package io.metersphere.api.dto.request.processors.extract;
 
+import io.metersphere.system.valid.EnumValue;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 @Data
 public abstract class ResultMatchingExtract extends MsExtract {
     /**
      * 结果匹配规则
-     * 值为 ResultMatchingRuleType
+     * 取值参考 {@link ResultMatchingRuleType}
+     * 默认随机匹配
      */
-    private String resultMatchingRule;
+    @Size(max = 100)
+    @EnumValue(enumClass = ResultMatchingRuleType.class)
+    private String resultMatchingRule = ResultMatchingRuleType.RANDOM.name();
     /**
      * 匹配第几条结果
      */
     private Integer resultMatchingRuleNum;
 
+    /**
+     * 结果匹配规则
+     */
     public enum ResultMatchingRuleType {
         /**
          * 随机匹配
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/XPathExtract.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/XPathExtract.java
index ce920a7741..649499351e 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/XPathExtract.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/processors/extract/XPathExtract.java
@@ -1,6 +1,7 @@
 package io.metersphere.api.dto.request.processors.extract;
 
 import com.fasterxml.jackson.annotation.JsonTypeName;
+import io.metersphere.system.valid.EnumValue;
 import lombok.Data;
 
 /**
@@ -9,6 +10,11 @@ import lombok.Data;
 @Data
 @JsonTypeName("X_PATH")
 public class XPathExtract extends ResultMatchingExtract {
+    /**
+     * 提取范围
+     * 取值参考 {@link ResponseFormat}
+     */
+    @EnumValue(enumClass = ResponseFormat.class)
     private String responseFormat;
 
     public enum ResponseFormat {
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 6fd5c16f60..5afeaa4cfa 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
@@ -1,6 +1,11 @@
 package io.metersphere.api.dto.schema;
 
 
+import io.metersphere.sdk.constants.ValueEnum;
+import io.metersphere.system.valid.EnumValue;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 import java.math.BigDecimal;
@@ -8,22 +13,63 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * json-schema 参数项
+ */
 @Data
 public class JsonSchemaItem {
+    /**
+     * 示例
+     */
     private Object example;
+    /**
+     * 参数ID
+     */
+    @NotBlank
+    @Size(max = 50)
     private String id;
+    /**
+     * 参数名称
+     */
+    @Size(max = 200)
     private String title;
-    private String type = "string";
+    /**
+     * 参数类型
+     * 取值范围,参考 {@link JsonSchemaItemType}
+     * 默认为 string
+     */
+    @EnumValue(enumClass = JsonSchemaItemType.class)
+    private String type = JsonSchemaItemType.STRING.value;
+    /**
+     * 参数描述
+     */
     private String description;
+    /**
+     * 子级参数
+     * 当 type 为 object 或者 array 时,使用该值
+     */
+    @Valid
     private JsonSchemaItem items;
     private Map mock;
     private Map properties;
     private JsonSchemaItem additionalProperties;
     private List required;
     private String pattern;
+    /**
+     * 最大长度
+     */
     private Integer maxLength;
+    /**
+     * 最小长度
+     */
     private Integer minLength;
+    /**
+     * 最小值
+     */
     private BigDecimal minimum;
+    /**
+     * 最大值
+     */
     private BigDecimal maximum;
     private String schema;
     private String format;
@@ -55,4 +101,28 @@ public class JsonSchemaItem {
             this.items = new JsonSchemaItem();
         }
     }
+
+    /**
+     * json-schema 参数类型
+     */
+    enum JsonSchemaItemType implements ValueEnum {
+        STRING("string"),
+        NUMBER("number"),
+        INTEGER("integer"),
+        BOOLEAN("boolean"),
+        OBJECT("object"),
+        ARRAY("array"),
+        NULL("null");
+
+        private String value;
+
+        JsonSchemaItemType(String value) {
+            this.value = value;
+        }
+
+        @Override
+        public String getValue() {
+            return value;
+        }
+    }
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBinaryBodyConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBinaryBodyConverter.java
index 4a331cbc68..83886f49c7 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBinaryBodyConverter.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBinaryBodyConverter.java
@@ -14,8 +14,7 @@ import org.apache.jmeter.protocol.http.util.HTTPFileArg;
 public class MsBinaryBodyConverter extends MsBodyConverter {
     @Override
     public void parse(HTTPSamplerProxy sampler, BinaryBody body, ParameterConfig config) {
-        ApiFile bodyFile = body.getBodyFile();
-        HTTPFileArg httpFileArg = getHttpFileArg(bodyFile);
+        HTTPFileArg httpFileArg = getHttpFileArg(body);
         sampler.setHTTPFiles(new HTTPFileArg[]{httpFileArg});
     }
 }
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/extract/RegexExtractConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/extract/RegexExtractConverter.java
index 540f091bc6..11e0d83284 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/extract/RegexExtractConverter.java
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/extract/RegexExtractConverter.java
@@ -8,6 +8,8 @@ import org.apache.jmeter.save.SaveService;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jorphan.collections.HashTree;
 
+import java.util.HashMap;
+
 import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.REGEX_EXTRACTOR_GUI;
 
 /**
@@ -23,18 +25,42 @@ public class RegexExtractConverter extends ExtractConverter {
         extractor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(REGEX_EXTRACTOR_GUI));
         extractor.setRefName(msExtract.getVariableName());
         extractor.setRegex(msExtract.getExpression());
-        extractor.setUseField(msExtract.getExtractScope());
         extractor.setEnabled(msExtract.getEnable());
-
+        extractor.setUseField(getUseField(msExtract.getExtractScope()));
+        extractor.setTemplate(getTemplate(msExtract.getExpressionMatchingRule()));
         // 处理匹配多条等匹配规则
         extractor.setMatchNumber(parseResultMatchingRule(msExtract));
-
-        // $1$提取 JSON 响应中的第一个匹配项 $0$用于提取整个 JSON 响应
-        if (StringUtils.isBlank(msExtract.getExpressionMatchingRule())) {
-            extractor.setTemplate(RegexExtract.ExpressionRuleType.EXPRESSION.getValue());
-        } else {
-            extractor.setTemplate(msExtract.getExpressionMatchingRule());
-        }
         hashTree.add(extractor);
     }
+
+    private String getTemplate(String expressionMatchingRule) {
+        // $1$提取 JSON 响应中的第一个匹配项 $0$用于提取整个 JSON 响应
+        HashMap ruleValueMap = new HashMap<>() {{
+            put(RegexExtract.ExpressionRuleType.EXPRESSION.name(), "$1$");
+            put(RegexExtract.ExpressionRuleType.GROUP.name(), "$0$");
+        }};
+        if (StringUtils.isBlank(expressionMatchingRule)) {
+            return ruleValueMap.get(RegexExtract.ExpressionRuleType.EXPRESSION.name());
+        } else {
+            return ruleValueMap.get(expressionMatchingRule);
+        }
+    }
+
+    private String getUseField(String extractScope) {
+        HashMap extractScopeMap = new HashMap<>() {{
+            put(RegexExtract.ExtractScope.BODY.name(), "false");
+            put(RegexExtract.ExtractScope.REQUEST_HEADERS.name(), "request_headers");
+            put(RegexExtract.ExtractScope.UNESCAPED_BODY.name(), "unescaped");
+            put(RegexExtract.ExtractScope.BODY_AS_DOCUMENT.name(), "as_document");
+            put(RegexExtract.ExtractScope.RESPONSE_HEADERS.name(), "true");
+            put(RegexExtract.ExtractScope.URL.name(), "URL");
+            put(RegexExtract.ExtractScope.RESPONSE_CODE.name(), "code");
+            put(RegexExtract.ExtractScope.RESPONSE_MESSAGE.name(), "message");
+        }};
+        if (StringUtils.isNotBlank(extractScope)) {
+            return extractScopeMap.get(extractScope);
+        } else {
+            return RegexExtract.ExtractScope.BODY.name();
+        }
+    }
 }
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 e00a30ec0e..d00944de6a 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
@@ -24,6 +24,7 @@ import io.metersphere.plugin.api.dto.ParameterConfig;
 import io.metersphere.plugin.api.spi.AbstractMsTestElement;
 import io.metersphere.project.constants.ScriptLanguageType;
 import io.metersphere.sdk.constants.MsAssertionCondition;
+import io.metersphere.sdk.util.BeanUtils;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -93,10 +94,7 @@ public class MsHTTPElementTest {
         xmlBody.setValue("");
         body.setXmlBody(xmlBody);
 
-        BinaryBody binaryBody = new BinaryBody();
-        binaryBody.setBodyFile(bodyFile);
-        body.setBinaryBody(binaryBody);
-
+        body.setBinaryBody(BeanUtils.copyBean(new BinaryBody(), bodyFile));
         return body;
     }