diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 49ccfad8ef..810dae7540 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -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.MsJDBCSampler; 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.SwaggerUrlRequest; import io.metersphere.api.exec.api.ApiExecuteService; +import io.metersphere.api.exec.generator.JSONSchemaParser; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.parse.ApiImportParser; import io.metersphere.api.parse.api.ApiDefinitionImport; @@ -327,6 +329,20 @@ public class ApiDefinitionService { return new ArrayList<>(); } List 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 fixedOrderComparator = new FixedOrderComparator(request.getIds()); fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE); @@ -1741,7 +1757,7 @@ public class ApiDefinitionService { } public List getApiByIds(List ids) { - if(CollectionUtils.isNotEmpty(ids)) { + if (CollectionUtils.isNotEmpty(ids)) { List list = extApiDefinitionMapper.selectApiByIds(ids); buildCustomField(list); return list; diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index cb2c062605..4b7b3c9eb9 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -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.MsThreadGroup; 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.mapper.*; import io.metersphere.base.mapper.ext.*; @@ -115,10 +117,10 @@ public class ApiTestCaseService { private BaseProjectService baseProjectService; - private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; private static final String DEFAULT_TIME_DATE = "-3D"; + //查询测试用例详情 public ApiTestCaseWithBLOBs getInfoJenkins(String id) { ApiTestCaseWithBLOBs apiTest = apiTestCaseMapper.selectByPrimaryKey(id); @@ -286,11 +288,12 @@ public class ApiTestCaseService { } public List selectByCaseIds(List ids) { - if(CollectionUtils.isEmpty(ids)){ + if (CollectionUtils.isEmpty(ids)) { return new ArrayList<>(); } return extApiTestCaseMapper.selectByCaseIds(ids); } + public ApiTestCaseInfo getResult(String id) { return extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id); } @@ -439,7 +442,7 @@ public class ApiTestCaseService { requestOrg, test.getRequest(), test.getCreateUserId() - ); + ); } // 存储附件关系 extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name()); @@ -514,7 +517,7 @@ public class ApiTestCaseService { null, test.getRequest(), test.getCreateUserId() - ); + ); // 存储附件关系 extFileAssociationService.saveApi(test.getId(), request.getRequest(), FileAssociationTypeEnums.CASE.name()); return test; @@ -847,6 +850,20 @@ public class ApiTestCaseService { list = new ArrayList<>(); } else { 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 fixedOrderComparator = new FixedOrderComparator(request.getIds()); diff --git a/api-test/frontend/src/business/automation/scenario/common/function/ScriptNavMenu.vue b/api-test/frontend/src/business/automation/scenario/common/function/ScriptNavMenu.vue index a4a3d2ddc7..914b76ddc6 100644 --- a/api-test/frontend/src/business/automation/scenario/common/function/ScriptNavMenu.vue +++ b/api-test/frontend/src/business/automation/scenario/common/function/ScriptNavMenu.vue @@ -177,6 +177,9 @@ export default { requestBodyKvs.set(arg.name, arg.value); } }); + } else if (body.type === 'JSON' && body.format === 'JSON-SCHEMA') { + requestBody = body.raw; + bodyType = 'json'; } return { requestPath, diff --git a/system-setting/backend/src/main/java/io/metersphere/service/ApiPluginService.java b/system-setting/backend/src/main/java/io/metersphere/service/ApiPluginService.java index b2af6bc49d..f07e2a0f1f 100644 --- a/system-setting/backend/src/main/java/io/metersphere/service/ApiPluginService.java +++ b/system-setting/backend/src/main/java/io/metersphere/service/ApiPluginService.java @@ -35,7 +35,6 @@ public class ApiPluginService { @Resource private PluginMapper pluginMapper; - PluginManager pluginManager = new PluginManager(); public List addApiPlugin(MultipartFile file) { String id = UUID.randomUUID().toString(); String path = FileUtils.create(id, file); @@ -83,6 +82,7 @@ public class ApiPluginService { private List getMethod(String path, String fileName, MultipartFile file) { List resources = new LinkedList<>(); validatePluginType(path); + PluginManager pluginManager = new PluginManager(); try { PluginManagerUtil.loadPlugin(path, pluginManager,file); PluginClassLoader classLoader = pluginManager.getClassLoader(path);