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(); Content content = requestBody.getContent();
if (content != null) { if (content != null) {
content.forEach((key, value) -> { content.forEach((key, value) -> {
setBodyData(key, value, body); setResponseBodyData(key, value, body);
}); });
} else { } else {
body.setBodyType(Body.BodyType.NONE.name()); body.setBodyType(Body.BodyType.NONE.name());
@ -186,7 +186,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
responseBody.forEach((key, value) -> { responseBody.forEach((key, value) -> {
HttpResponse httpResponse = new HttpResponse(); HttpResponse httpResponse = new HttpResponse();
//TODO headers //TODO headers
httpResponse.setStatusCode(StringUtils.equals("default", key) ? "200" :key); httpResponse.setStatusCode(StringUtils.equals("default", key) ? "200" : key);
ResponseBody body = new ResponseBody(); ResponseBody body = new ResponseBody();
Map<String, io.swagger.v3.oas.models.headers.Header> headers = value.getHeaders(); Map<String, io.swagger.v3.oas.models.headers.Header> headers = value.getHeaders();
if (MapUtils.isNotEmpty(headers)) { if (MapUtils.isNotEmpty(headers)) {
@ -202,7 +202,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
} }
if (value.getContent() != null) { if (value.getContent() != null) {
value.getContent().forEach((k, v) -> { value.getContent().forEach((k, v) -> {
setBodyData(k, v, body); setResponseBodyData(k, v, body);
}); });
} else { } else {
body.setBodyType(Body.BodyType.NONE.name()); 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格式 //TODO body 默认如果json格式
JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema()); JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema());
switch (k) { 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格式 //TODO body 默认如果json格式
JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema()); JsonSchemaItem jsonSchemaItem = parseSchema(value.getSchema());
switch (k) { switch (k) {
@ -607,9 +607,17 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
return true; return true;
} }
} }
if (schema instanceof IntegerSchema) {
if (schema instanceof Schema<?> items) { return false;
return isRef(items, level + 1); }
if (schema instanceof StringSchema) {
return false;
}
if (schema instanceof NumberSchema) {
return false;
}
if (schema instanceof BooleanSchema) {
return false;
} }
return false; return false;
@ -619,13 +627,13 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
Map<String, Schema> properties = objectSchema.getProperties(); Map<String, Schema> properties = objectSchema.getProperties();
if (MapUtils.isNotEmpty(properties)) { if (MapUtils.isNotEmpty(properties)) {
for (Schema value : properties.values()) { 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; return true;
} }
if (value instanceof ObjectSchema && isRef(value, level + 1)) { if (value instanceof ObjectSchema && isRef(value, level + 1) && level > 20) {
return true; return true;
} }
if (value instanceof Schema<?> items && isRef(items, level + 1)) { if (value instanceof Schema<?> items && isRef(items, level + 1) && level > 20) {
return true; 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.ApiConstants;
import io.metersphere.api.constants.ApiDefinitionDocType; import io.metersphere.api.constants.ApiDefinitionDocType;
import io.metersphere.sdk.constants.ApiFileResourceType;
import io.metersphere.api.constants.ApiResourceType; import io.metersphere.api.constants.ApiResourceType;
import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.*; 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.EnvironmentService;
import io.metersphere.project.service.MoveNodeService; import io.metersphere.project.service.MoveNodeService;
import io.metersphere.project.service.ProjectService; 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.ApplicationNumScope;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.ModuleConstants;
@ -441,13 +440,13 @@ public class ApiDefinitionService extends MoveNodeService {
private void processApiDefinitions(List<ApiDefinitionDTO> list, String projectId) { private void processApiDefinitions(List<ApiDefinitionDTO> list, String projectId) {
Set<String> userIds = extractUserIds(list); Set<String> userIds = extractUserIds(list);
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds)); 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); List<ApiCaseComputeDTO> apiCaseComputeList = extApiDefinitionMapper.selectApiCaseByIdsAndStatusIsNotTrash(apiDefinitionIds, projectId);
Map<String, ApiCaseComputeDTO> resultMap = apiCaseComputeList.stream().collect(Collectors.toMap(ApiCaseComputeDTO::getApiDefinitionId, Function.identity())); Map<String, ApiCaseComputeDTO> resultMap = apiCaseComputeList.stream().collect(Collectors.toMap(ApiCaseComputeDTO::getApiDefinitionId, Function.identity()));
List<ApiDefinitionCustomFieldDTO> customFields = extApiDefinitionCustomFieldMapper.getApiCustomFields(apiDefinitionIds, projectId); List<ApiDefinitionCustomFieldDTO> customFields = extApiDefinitionCustomFieldMapper.getApiCustomFields(apiDefinitionIds, projectId);
Map<String, List<ApiDefinitionCustomFieldDTO>> customFieldMap = customFields.stream().collect(Collectors.groupingBy(ApiDefinitionCustomFieldDTO::getApiId)); Map<String, List<ApiDefinitionCustomFieldDTO>> customFieldMap = customFields.stream().collect(Collectors.groupingBy(ApiDefinitionCustomFieldDTO::getApiId));
*/
list.forEach(item -> { list.forEach(item -> {
// Convert User IDs to Names // Convert User IDs to Names
item.setCreateUserName(userMap.get(item.getCreateUser())); item.setCreateUserName(userMap.get(item.getCreateUser()));
@ -455,7 +454,7 @@ public class ApiDefinitionService extends MoveNodeService {
item.setUpdateUserName(userMap.get(item.getUpdateUser())); item.setUpdateUserName(userMap.get(item.getUpdateUser()));
// Custom Fields // Custom Fields
item.setCustomFields(customFieldMap.get(item.getId())); /*item.setCustomFields(customFieldMap.get(item.getId()));
// Calculate API Case Metrics // Calculate API Case Metrics
ApiCaseComputeDTO apiCaseComputeDTO = resultMap.get(item.getId()); ApiCaseComputeDTO apiCaseComputeDTO = resultMap.get(item.getId());
@ -476,7 +475,7 @@ public class ApiDefinitionService extends MoveNodeService {
item.setCaseTotal(0); item.setCaseTotal(0);
item.setCasePassRate("-"); item.setCasePassRate("-");
item.setCaseStatus("-"); item.setCaseStatus("-");
} }*/
}); });
} }

View File

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