refactor(接口测试): 优化接口导入默认参数的构造

This commit is contained in:
wxg0103 2024-03-12 16:09:44 +08:00 committed by Craftsman
parent 37c5925241
commit 1717198ca8
5 changed files with 23 additions and 4 deletions

View File

@ -19,8 +19,8 @@ public class HTTPAuthConfig {
*/ */
@EnumValue(enumClass = HTTPAuthType.class) @EnumValue(enumClass = HTTPAuthType.class)
private String authType = HTTPAuthType.NONE.name(); private String authType = HTTPAuthType.NONE.name();
private BasicAuth basicAuth; private BasicAuth basicAuth = new BasicAuth();
private DigestAuth digestAuth; private DigestAuth digestAuth = new DigestAuth();
public boolean isHTTPAuthValid() { public boolean isHTTPAuthValid() {
HashMap<String, HTTPAuth> httpAuthHashMap = HashMap.newHashMap(2); HashMap<String, HTTPAuth> httpAuthHashMap = HashMap.newHashMap(2);

View File

@ -2,6 +2,7 @@ package io.metersphere.api.dto.request.http.body;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -13,5 +14,5 @@ public class FormDataBody {
/** /**
* form-data 请求体的键值对列表 * form-data 请求体的键值对列表
*/ */
private List<FormDataKV> formValues; private List<FormDataKV> formValues = new ArrayList<>();
} }

View File

@ -3,6 +3,7 @@ package io.metersphere.api.dto.request.http.body;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -13,5 +14,5 @@ import java.util.List;
@Data @Data
public class WWWFormBody { public class WWWFormBody {
@Valid @Valid
private List<WWWFormKV> formValues; private List<WWWFormKV> formValues = new ArrayList<>();
} }

View File

@ -6,6 +6,7 @@ import io.metersphere.api.dto.converter.ApiDefinitionImportDetail;
import io.metersphere.api.dto.definition.HttpResponse; import io.metersphere.api.dto.definition.HttpResponse;
import io.metersphere.api.dto.definition.ResponseBody; import io.metersphere.api.dto.definition.ResponseBody;
import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.ImportRequest;
import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.*; import io.metersphere.api.dto.request.http.*;
import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.api.dto.request.http.auth.NoAuth;
import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.request.http.body.*;
@ -13,6 +14,7 @@ import io.metersphere.api.dto.schema.JsonSchemaItem;
import io.metersphere.api.parser.ImportParser; import io.metersphere.api.parser.ImportParser;
import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.api.utils.JsonSchemaBuilder; import io.metersphere.api.utils.JsonSchemaBuilder;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.constants.PropertyConstant; import io.metersphere.project.constants.PropertyConstant;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
@ -137,6 +139,12 @@ public class Swagger3Parser<T> implements ImportParser<ApiDefinitionImport> {
parseParameters(pathItem, request); parseParameters(pathItem, request);
//构建请求体 //构建请求体
parseRequestBody(operation.getRequestBody(), request.getBody()); parseRequestBody(operation.getRequestBody(), request.getBody());
//构造 children
LinkedList<AbstractMsTestElement> children = new LinkedList<>();
children.add(new MsCommonElement());
request.setChildren(children);
//认证
request.setAuthConfig(new NoAuth());
apiDefinitionDTO.setRequest(request); apiDefinitionDTO.setRequest(request);
//解析请求内容 //解析请求内容
@ -150,6 +158,13 @@ public class Swagger3Parser<T> implements ImportParser<ApiDefinitionImport> {
} }
private void parseRequestBody(RequestBody requestBody, Body body) { private void parseRequestBody(RequestBody requestBody, Body body) {
body.setBinaryBody(new BinaryBody());
body.setFormDataBody(new FormDataBody());
body.setXmlBody(new XmlBody());
body.setRawBody(new RawBody());
body.setNoneBody(new NoneBody());
body.setJsonBody(new JsonBody());
body.setWwwFormBody(new WWWFormBody());
if (requestBody != null) { if (requestBody != null) {
Content content = requestBody.getContent(); Content content = requestBody.getContent();
if (content != null) { if (content != null) {

View File

@ -24,6 +24,8 @@ public class HttpConfig implements Serializable {
private String protocol = HttpProtocolType.HTTP.name(); private String protocol = HttpProtocolType.HTTP.name();
@Schema(description = "环境域名") @Schema(description = "环境域名")
private String hostname; private String hostname;
@Schema(description = "完整url")
private String url;
/** /**
* 启用条件 * 启用条件
* {@link HttpConfigMatchType} * {@link HttpConfigMatchType}