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 9148d1c25f..afa7ed6ffc 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,6 +3,8 @@ 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 io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.system.valid.EnumValue; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; @@ -34,9 +36,11 @@ public class MsHTTPElement extends AbstractMsTestElement { private String path; /** * 请求方法 + * 取值参考:{@link HttpMethodConstants} */ @NotBlank @Size(max = 10) + @EnumValue(enumClass = HttpMethodConstants.class) private String method; /** * 请求体 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 c39056968c..2f8208659c 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 @@ -13,5 +13,5 @@ public class FormDataBody { /** * form-data 请求体的键值对列表 */ - private List fromValues; + private List formValues; } 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 757dc35f7b..aef778b798 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 @@ -2,6 +2,7 @@ package io.metersphere.api.dto.request.http.body; import io.metersphere.api.dto.ApiFile; import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; import lombok.Data; import org.apache.commons.lang3.StringUtils; @@ -22,6 +23,11 @@ public class FormDataKV extends WWWFormKV { */ @Valid private List files; + /** + * 参数的 contentType + */ + @Size(max = 100) + private String contentType; public boolean isFile() { return StringUtils.equalsIgnoreCase(getParamType(), BodyParamType.FILE.getValue()); 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 54cde69b1c..971ab1da83 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 @@ -13,5 +13,5 @@ import java.util.List; @Data public class WWWFormBody { @Valid - private List fromValues; + private List formValues; } 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 460b0c76eb..2abecd4cca 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 @@ -34,11 +34,6 @@ public class WWWFormKV extends KeyValueEnableParam { * 最大长度 */ private Integer maxLength; - /** - * 参数的 contentType - */ - @Size(max = 100) - private String contentType; /** * 是否对参数进行编码 * 默认 false diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java index 02c6fe4555..08b58974bd 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java @@ -166,7 +166,7 @@ public class Swagger3Parser implements ImportParser { private void parseWWWFormBody(JsonSchemaItem item, Body body) { WWWFormBody wwwFormBody = new WWWFormBody(); List required = item.getRequired(); - List formDataKVS = new ArrayList<>(); + List formDataKVS = new ArrayList<>(); item.getProperties().forEach((key, value) -> { if (value != null && !StringUtils.equals(PropertyConstant.OBJECT, value.getType())) { FormDataKV formDataKV = new FormDataKV(); @@ -180,7 +180,7 @@ public class Swagger3Parser implements ImportParser { formDataKVS.add(formDataKV); } }); - wwwFormBody.setFromValues(formDataKVS); + wwwFormBody.setFormValues(formDataKVS); body.setWwwFormBody(wwwFormBody); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBodyConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBodyConverter.java index 03d0b64127..04639bb880 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBodyConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsBodyConverter.java @@ -2,6 +2,7 @@ package io.metersphere.api.parser.jmeter.body; import io.metersphere.api.dto.ApiFile; +import io.metersphere.api.dto.request.http.body.FormDataKV; import io.metersphere.api.dto.request.http.body.WWWFormKV; import io.metersphere.jmeter.mock.Mock; import io.metersphere.plugin.api.dto.ParameterConfig; @@ -36,23 +37,23 @@ public abstract class MsBodyConverter { /** * 解析文本类型的 kv 参数 - * @param textFromValues + * @param textFormValues * @return */ - protected Arguments getArguments(List textFromValues) { + protected Arguments getArguments(List textFormValues) { Arguments arguments = new Arguments(); - textFromValues.forEach(formDataKV -> { + textFormValues.forEach(kv -> { // 处理 mock 函数 - String value = Mock.buildFunctionCallString(formDataKV.getValue()); + String value = Mock.buildFunctionCallString(kv.getValue()); if (value == null) { value = StringUtils.EMPTY; } - HTTPArgument httpArgument = new HTTPArgument(formDataKV.getKey(), value); - httpArgument.setAlwaysEncoded(formDataKV.getEncode()); - if (StringUtils.isNotBlank(formDataKV.getContentType())) { + HTTPArgument httpArgument = new HTTPArgument(kv.getKey(), value); + httpArgument.setAlwaysEncoded(kv.getEncode()); + arguments.addArgument(httpArgument); + if (kv instanceof FormDataKV formDataKV && formDataKV.getContentType() != null) { httpArgument.setContentType(formDataKV.getContentType()); } - arguments.addArgument(httpArgument); }); return arguments; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java index 2cd2a20400..9f740e8165 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java @@ -22,29 +22,29 @@ public class MsFormDataBodyConverter extends MsBodyConverter { @Override public void parse(HTTPSamplerProxy sampler, FormDataBody body, ParameterConfig config) { - List fromValues = body.getFromValues(); - List validFromValues = fromValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList()); - List fileFromValues = validFromValues.stream().filter(FormDataKV::isFile).collect(Collectors.toList()); - List textFromValues = validFromValues.stream().filter(kv -> !kv.isFile()).collect(Collectors.toList()); + List formValues = body.getFormValues(); + List validFormValues = formValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList()); + List fileFormValues = validFormValues.stream().filter(FormDataKV::isFile).collect(Collectors.toList()); + List textFormValues = validFormValues.stream().filter(kv -> !kv.isFile()).collect(Collectors.toList()); sampler.setDoMultipart(true); - sampler.setHTTPFiles(getHttpFileArg(fileFromValues)); - sampler.setArguments(getArguments(textFromValues)); + sampler.setHTTPFiles(getHttpFileArg(fileFormValues)); + sampler.setArguments(getArguments(textFormValues)); } /** * 解析文件类型的参数 * - * @param fileFromValues + * @param fileFormValues * @return */ - private HTTPFileArg[] getHttpFileArg(List fileFromValues) { - if (CollectionUtils.isEmpty(fileFromValues)) { + private HTTPFileArg[] getHttpFileArg(List fileFormValues) { + if (CollectionUtils.isEmpty(fileFormValues)) { return new HTTPFileArg[0]; } List list = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(fileFromValues)) { - fileFromValues.forEach(formDataKV -> { + if (CollectionUtils.isNotEmpty(fileFormValues)) { + fileFormValues.forEach(formDataKV -> { String paramName = formDataKV.getKey(); formDataKV.getFiles().forEach(file -> { HTTPFileArg fileArg = getHttpFileArg(file); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsWWWFormBodyConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsWWWFormBodyConverter.java index 4987b75492..ef1def69c0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsWWWFormBodyConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsWWWFormBodyConverter.java @@ -1,7 +1,7 @@ package io.metersphere.api.parser.jmeter.body; -import io.metersphere.api.dto.request.http.body.FormDataKV; import io.metersphere.api.dto.request.http.body.WWWFormBody; +import io.metersphere.api.dto.request.http.body.WWWFormKV; import io.metersphere.plugin.api.dto.ParameterConfig; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; @@ -15,8 +15,8 @@ import java.util.stream.Collectors; public class MsWWWFormBodyConverter extends MsBodyConverter { @Override public void parse(HTTPSamplerProxy sampler, WWWFormBody body, ParameterConfig config) { - List fromValues = body.getFromValues(); - List validFromValues = fromValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList()); - sampler.setArguments(getArguments(validFromValues)); + List formValues = body.getFormValues(); + List validFormValues = formValues.stream().filter(WWWFormKV::isValid).collect(Collectors.toList()); + sampler.setArguments(getArguments(validFormValues)); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java index bfa7e8c4c3..76b34b805f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/step/ApiStepParser.java @@ -86,11 +86,11 @@ public class ApiStepParser extends StepParser { } if (StringUtils.equals(refBody.getBodyType(), Body.BodyType.FORM_DATA.name()) && valueBody.getFormDataBody() != null && refBody.getFormDataBody() != null) { - replaceKvParam(valueBody.getFormDataBody().getFromValues(), valueBody.getFormDataBody().getFromValues()); + replaceKvParam(valueBody.getFormDataBody().getFormValues(), valueBody.getFormDataBody().getFormValues()); } if (StringUtils.equals(refBody.getBodyType(), Body.BodyType.WWW_FORM.name()) && valueBody.getWwwFormBody() != null && refBody.getWwwFormBody() != null) { - replaceKvParam(valueBody.getWwwFormBody().getFromValues(), valueBody.getWwwFormBody().getFromValues()); + replaceKvParam(valueBody.getWwwFormBody().getFormValues(), valueBody.getWwwFormBody().getFormValues()); } // todo JsonSchema body } 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 165f2cb5b5..495d1d7e0a 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 @@ -517,11 +517,11 @@ public class ApiDefinitionImportUtilService { FormDataBody formDataBody = dbbody.getFormDataBody(); FormDataBody importFormDataBody = importBody.getFormDataBody(); if (ObjectUtils.isNotEmpty(formDataBody) || ObjectUtils.isNotEmpty(importFormDataBody)) { - List fromValues = formDataBody.getFromValues(); - List importFromValues = importFormDataBody.getFromValues(); - if (CollectionUtils.isNotEmpty(fromValues) || CollectionUtils.isNotEmpty(importFromValues)) { - List dbFormKeys = fromValues.stream().map(FormDataKV::getKey).toList(); - List importFormKeys = importFromValues.stream().map(FormDataKV::getKey).toList(); + 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; } @@ -531,11 +531,11 @@ public class ApiDefinitionImportUtilService { WWWFormBody wwwBody = dbbody.getWwwFormBody(); WWWFormBody importWwwBody = importBody.getWwwFormBody(); if (ObjectUtils.isNotEmpty(wwwBody) || ObjectUtils.isNotEmpty(importWwwBody)) { - List wwwValues = wwwBody.getFromValues(); - List importWwwValues = importWwwBody.getFromValues(); + List wwwValues = wwwBody.getFormValues(); + List importWwwValues = importWwwBody.getFormValues(); if (CollectionUtils.isNotEmpty(wwwValues) || CollectionUtils.isNotEmpty(importWwwValues)) { - List dbWwwKeys = wwwValues.stream().map(FormDataKV::getKey).toList(); - List importWwwKeys = importWwwValues.stream().map(FormDataKV::getKey).toList(); + List dbWwwKeys = wwwValues.stream().map(WWWFormKV::getKey).toList(); + List importWwwKeys = importWwwValues.stream().map(WWWFormKV::getKey).toList(); if (paramsIsSame(dbWwwKeys, importWwwKeys)) { return false; } 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 ebdabae87b..2e2320203a 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 @@ -79,11 +79,12 @@ public class MsHTTPElementTest { bodyFile.setFileName("aaa"); formDataFileKV.setFiles(List.of(bodyFile)); formDataFileKV.setKey("fileKey"); - formDataBody.setFromValues(List.of(formDataKV)); + formDataBody.setFormValues(List.of(formDataKV)); body.setFormDataBody(formDataBody); + WWWFormKV wwwFormKV = BeanUtils.copyBean(new WWWFormKV(), formDataKV); WWWFormBody wwwFormBody = new WWWFormBody(); - wwwFormBody.setFromValues(List.of(formDataKV)); + wwwFormBody.setFormValues(List.of(wwwFormKV)); body.setWwwFormBody(wwwFormBody); JsonBody jsonBody = new JsonBody(); @@ -411,7 +412,7 @@ public class MsHTTPElementTest { formDataKV.setRequired(true); formDataKV.setValue("value"); formDataKV.setKey("key"); - formDataBody.setFromValues(List.of(formDataKV)); + formDataBody.setFormValues(List.of(formDataKV)); Body body = new Body(); body.setBodyType(Body.BodyType.FORM_DATA.name()); httpResponse.setBody(body); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java index 51e853028a..f02bd24bba 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java @@ -14,10 +14,6 @@ import java.util.List; public class HttpConfig implements Serializable { @Schema(description = "环境域名") private String url; - @Schema(description = "接口测试") - private Boolean apiTest = true; - @Schema(description = "UI测试") - private Boolean uiTest = false; @Schema(description = "启用条件 NONE/MODULE/PATH") private String type = "NONE"; @Schema(description = "启用条件为PATH时,需要填写的路径/ key为equal时,value为路径,key为contain时,value为包含的路径")