refactor(接口测试): 优化接口导入

This commit is contained in:
wxg0103 2024-05-14 11:13:58 +08:00 committed by Craftsman
parent 30bbd3db45
commit 990e6e5ca1
3 changed files with 26 additions and 19 deletions

View File

@ -144,7 +144,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
Content content = requestBody.getContent();
if (content != null) {
content.forEach((key, value) -> {
setBodyData(key, value, body);
setResponseBodyData(key, value, body);
});
} else {
body.setBodyType(Body.BodyType.NONE.name());
@ -186,7 +186,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
responseBody.forEach((key, value) -> {
HttpResponse httpResponse = new HttpResponse();
//TODO headers
httpResponse.setStatusCode(StringUtils.equals("default", key) ? "200" :key);
httpResponse.setStatusCode(StringUtils.equals("default", key) ? "200" : key);
ResponseBody body = new ResponseBody();
Map<String, io.swagger.v3.oas.models.headers.Header> headers = value.getHeaders();
if (MapUtils.isNotEmpty(headers)) {
@ -202,7 +202,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
}
if (value.getContent() != null) {
value.getContent().forEach((k, v) -> {
setBodyData(k, v, body);
setResponseBodyData(k, v, body);
});
} else {
body.setBodyType(Body.BodyType.NONE.name());
@ -214,7 +214,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
}
private void setBodyData(String k, io.swagger.v3.oas.models.media.MediaType value, ResponseBody body) {
private void setResponseBodyData(String k, io.swagger.v3.oas.models.media.MediaType value, ResponseBody body) {
//TODO body 默认如果json格式
JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema());
switch (k) {
@ -261,7 +261,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
}
}
private void setBodyData(String k, io.swagger.v3.oas.models.media.MediaType value, Body body) {
private void setResponseBodyData(String k, io.swagger.v3.oas.models.media.MediaType value, Body body) {
//TODO body 默认如果json格式
JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema());
switch (k) {
@ -607,9 +607,17 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
return true;
}
}
if (schema instanceof Schema<?> items) {
return isRef(items, level + 1);
if (schema instanceof IntegerSchema) {
return false;
}
if (schema instanceof StringSchema) {
return false;
}
if (schema instanceof NumberSchema) {
return false;
}
if (schema instanceof BooleanSchema) {
return false;
}
return false;
@ -619,13 +627,13 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
Map<String, Schema> properties = objectSchema.getProperties();
if (MapUtils.isNotEmpty(properties)) {
for (Schema value : properties.values()) {
if (value instanceof ArraySchema && isRef(((ArraySchema) value).getItems(), level + 1)) {
if (value instanceof ArraySchema && isRef(((ArraySchema) value).getItems(), level + 1) && level > 20) {
return true;
}
if (value instanceof ObjectSchema && isRef(value, level + 1)) {
if (value instanceof ObjectSchema && isRef(value, level + 1) && level > 20) {
return true;
}
if (value instanceof Schema<?> items && isRef(items, level + 1)) {
if (value instanceof Schema<?> items && isRef(items, level + 1) && level > 20) {
return true;
}
}

View File

@ -2,7 +2,6 @@ package io.metersphere.api.service.definition;
import io.metersphere.api.constants.ApiConstants;
import io.metersphere.api.constants.ApiDefinitionDocType;
import io.metersphere.sdk.constants.ApiFileResourceType;
import io.metersphere.api.constants.ApiResourceType;
import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.*;
@ -26,7 +25,7 @@ import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.service.EnvironmentService;
import io.metersphere.project.service.MoveNodeService;
import io.metersphere.project.service.ProjectService;
import io.metersphere.sdk.constants.ApiReportStatus;
import io.metersphere.sdk.constants.ApiFileResourceType;
import io.metersphere.sdk.constants.ApplicationNumScope;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.ModuleConstants;
@ -441,13 +440,13 @@ public class ApiDefinitionService extends MoveNodeService {
private void processApiDefinitions(List<ApiDefinitionDTO> list, String projectId) {
Set<String> userIds = extractUserIds(list);
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
List<String> apiDefinitionIds = list.stream().map(ApiDefinitionDTO::getId).toList();
/* List<String> apiDefinitionIds = list.stream().map(ApiDefinitionDTO::getId).toList();
List<ApiCaseComputeDTO> apiCaseComputeList = extApiDefinitionMapper.selectApiCaseByIdsAndStatusIsNotTrash(apiDefinitionIds, projectId);
Map<String, ApiCaseComputeDTO> resultMap = apiCaseComputeList.stream().collect(Collectors.toMap(ApiCaseComputeDTO::getApiDefinitionId, Function.identity()));
List<ApiDefinitionCustomFieldDTO> customFields = extApiDefinitionCustomFieldMapper.getApiCustomFields(apiDefinitionIds, projectId);
Map<String, List<ApiDefinitionCustomFieldDTO>> customFieldMap = customFields.stream().collect(Collectors.groupingBy(ApiDefinitionCustomFieldDTO::getApiId));
*/
list.forEach(item -> {
// Convert User IDs to Names
item.setCreateUserName(userMap.get(item.getCreateUser()));
@ -455,7 +454,7 @@ public class ApiDefinitionService extends MoveNodeService {
item.setUpdateUserName(userMap.get(item.getUpdateUser()));
// Custom Fields
item.setCustomFields(customFieldMap.get(item.getId()));
/*item.setCustomFields(customFieldMap.get(item.getId()));
// Calculate API Case Metrics
ApiCaseComputeDTO apiCaseComputeDTO = resultMap.get(item.getId());
@ -476,7 +475,7 @@ public class ApiDefinitionService extends MoveNodeService {
item.setCaseTotal(0);
item.setCasePassRate("-");
item.setCaseStatus("-");
}
}*/
});
}

View File

@ -58,10 +58,10 @@ public class BugEditRequest implements Serializable {
@Schema(description = "用例ID")
private String caseId;
@Schema(description = "测试计划ID")
@Schema(description = "测试计划ID,通过测试计划创建的必填")
private String testPlanId;
@Schema(description = "测试计划管理的用例ID")
@Schema(description = "测试计划关联的用例ID, 通过测试计划创建的必填值是关联的id而不是用例id")
private String testPlanCaseId;
@Schema(description = "复制的附件")