fix(接口测试): 修复脚本中使用API导入,生成的代码中没有json-schema参数的缺陷
--bug=1027752 --user=王孝刚 【项目设置】github#25553,API 请求体开启 json-schema 后,在代码片段使用API导入,生成的代码使用的接口参数非最新数据 https://www.tapd.cn/55049933/s/1392604
This commit is contained in:
parent
6b82558cff
commit
530c3b498e
|
@ -14,9 +14,11 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||||
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult;
|
import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult;
|
||||||
import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest;
|
import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest;
|
||||||
import io.metersphere.api.exec.api.ApiExecuteService;
|
import io.metersphere.api.exec.api.ApiExecuteService;
|
||||||
|
import io.metersphere.api.exec.generator.JSONSchemaParser;
|
||||||
import io.metersphere.api.jmeter.JMeterService;
|
import io.metersphere.api.jmeter.JMeterService;
|
||||||
import io.metersphere.api.parse.ApiImportParser;
|
import io.metersphere.api.parse.ApiImportParser;
|
||||||
import io.metersphere.api.parse.api.ApiDefinitionImport;
|
import io.metersphere.api.parse.api.ApiDefinitionImport;
|
||||||
|
@ -327,6 +329,20 @@ public class ApiDefinitionService {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
List<ApiDefinitionResult> resList = extApiDefinitionMapper.listByIds(request.getIds());
|
List<ApiDefinitionResult> resList = extApiDefinitionMapper.listByIds(request.getIds());
|
||||||
|
resList.forEach(item -> {
|
||||||
|
MsTestElement msTestElement = JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||||
|
if (msTestElement instanceof MsHTTPSamplerProxy) {
|
||||||
|
MsHTTPSamplerProxy requestBody = (MsHTTPSamplerProxy) msTestElement;
|
||||||
|
Body body = requestBody.getBody();
|
||||||
|
if (StringUtils.isNotBlank(body.getType()) && StringUtils.equals(body.getType(), Body.JSON_STR)) {
|
||||||
|
if (StringUtils.isNotEmpty(body.getFormat()) && body.getJsonSchema() != null && Body.JSON_SCHEMA.equals(body.getFormat())) {
|
||||||
|
body.setRaw(JSONSchemaParser.preview(JSONUtil.toJSONString(body.getJsonSchema())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.setRequest(JSONUtil.toJSONString(requestBody));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
// 排序
|
// 排序
|
||||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||||
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||||
|
@ -1741,7 +1757,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiDefinitionResult> getApiByIds(List<String> ids) {
|
public List<ApiDefinitionResult> getApiByIds(List<String> ids) {
|
||||||
if(CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
List<ApiDefinitionResult> list = extApiDefinitionMapper.selectApiByIds(ids);
|
List<ApiDefinitionResult> list = extApiDefinitionMapper.selectApiByIds(ids);
|
||||||
buildCustomField(list);
|
buildCustomField(list);
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.MsTestPlan;
|
import io.metersphere.api.dto.definition.request.MsTestPlan;
|
||||||
import io.metersphere.api.dto.definition.request.MsThreadGroup;
|
import io.metersphere.api.dto.definition.request.MsThreadGroup;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||||
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
|
import io.metersphere.api.exec.generator.JSONSchemaParser;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.*;
|
import io.metersphere.base.mapper.ext.*;
|
||||||
|
@ -115,10 +117,10 @@ public class ApiTestCaseService {
|
||||||
private BaseProjectService baseProjectService;
|
private BaseProjectService baseProjectService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
|
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
|
||||||
|
|
||||||
private static final String DEFAULT_TIME_DATE = "-3D";
|
private static final String DEFAULT_TIME_DATE = "-3D";
|
||||||
|
|
||||||
//查询测试用例详情
|
//查询测试用例详情
|
||||||
public ApiTestCaseWithBLOBs getInfoJenkins(String id) {
|
public ApiTestCaseWithBLOBs getInfoJenkins(String id) {
|
||||||
ApiTestCaseWithBLOBs apiTest = apiTestCaseMapper.selectByPrimaryKey(id);
|
ApiTestCaseWithBLOBs apiTest = apiTestCaseMapper.selectByPrimaryKey(id);
|
||||||
|
@ -286,11 +288,12 @@ public class ApiTestCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiTestCaseInfo> selectByCaseIds(List<String> ids) {
|
public List<ApiTestCaseInfo> selectByCaseIds(List<String> ids) {
|
||||||
if(CollectionUtils.isEmpty(ids)){
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return extApiTestCaseMapper.selectByCaseIds(ids);
|
return extApiTestCaseMapper.selectByCaseIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiTestCaseInfo getResult(String id) {
|
public ApiTestCaseInfo getResult(String id) {
|
||||||
return extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id);
|
return extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
@ -439,7 +442,7 @@ public class ApiTestCaseService {
|
||||||
requestOrg,
|
requestOrg,
|
||||||
test.getRequest(),
|
test.getRequest(),
|
||||||
test.getCreateUserId()
|
test.getCreateUserId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// 存储附件关系
|
// 存储附件关系
|
||||||
extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name());
|
extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name());
|
||||||
|
@ -514,7 +517,7 @@ public class ApiTestCaseService {
|
||||||
null,
|
null,
|
||||||
test.getRequest(),
|
test.getRequest(),
|
||||||
test.getCreateUserId()
|
test.getCreateUserId()
|
||||||
);
|
);
|
||||||
// 存储附件关系
|
// 存储附件关系
|
||||||
extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name());
|
extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name());
|
||||||
return test;
|
return test;
|
||||||
|
@ -847,6 +850,20 @@ public class ApiTestCaseService {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
list = extApiTestCaseMapper.getCaseInfo(request);
|
list = extApiTestCaseMapper.getCaseInfo(request);
|
||||||
|
list.forEach(item -> {
|
||||||
|
MsTestElement msTestElement = JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||||
|
if (msTestElement instanceof MsHTTPSamplerProxy) {
|
||||||
|
MsHTTPSamplerProxy requestBody = (MsHTTPSamplerProxy) JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||||
|
Body body = requestBody.getBody();
|
||||||
|
if (StringUtils.isNotBlank(body.getType()) && StringUtils.equals(body.getType(), Body.JSON_STR)) {
|
||||||
|
if (StringUtils.isNotEmpty(body.getFormat()) && body.getJsonSchema() != null && Body.JSON_SCHEMA.equals(body.getFormat())) {
|
||||||
|
body.setRaw(JSONSchemaParser.preview(JSONUtil.toJSONString(body.getJsonSchema())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.setRequest(JSONUtil.toJSONString(requestBody));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// 排序
|
// 排序
|
||||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||||
|
|
|
@ -177,6 +177,9 @@ export default {
|
||||||
requestBodyKvs.set(arg.name, arg.value);
|
requestBodyKvs.set(arg.name, arg.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (body.type === 'JSON' && body.format === 'JSON-SCHEMA') {
|
||||||
|
requestBody = body.raw;
|
||||||
|
bodyType = 'json';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
requestPath,
|
requestPath,
|
||||||
|
|
|
@ -35,7 +35,6 @@ public class ApiPluginService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PluginMapper pluginMapper;
|
private PluginMapper pluginMapper;
|
||||||
PluginManager pluginManager = new PluginManager();
|
|
||||||
public List<PluginWithBLOBs> addApiPlugin(MultipartFile file) {
|
public List<PluginWithBLOBs> addApiPlugin(MultipartFile file) {
|
||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
String path = FileUtils.create(id, file);
|
String path = FileUtils.create(id, file);
|
||||||
|
@ -83,6 +82,7 @@ public class ApiPluginService {
|
||||||
private List<PluginResourceDTO> getMethod(String path, String fileName, MultipartFile file) {
|
private List<PluginResourceDTO> getMethod(String path, String fileName, MultipartFile file) {
|
||||||
List<PluginResourceDTO> resources = new LinkedList<>();
|
List<PluginResourceDTO> resources = new LinkedList<>();
|
||||||
validatePluginType(path);
|
validatePluginType(path);
|
||||||
|
PluginManager pluginManager = new PluginManager();
|
||||||
try {
|
try {
|
||||||
PluginManagerUtil.loadPlugin(path, pluginManager,file);
|
PluginManagerUtil.loadPlugin(path, pluginManager,file);
|
||||||
PluginClassLoader classLoader = pluginManager.getClassLoader(path);
|
PluginClassLoader classLoader = pluginManager.getClassLoader(path);
|
||||||
|
|
Loading…
Reference in New Issue