From d926da8124139002e7f37121b36cd79cc8e1f13f Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 17 Sep 2021 11:11:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E5=88=9B=E5=BB=BA=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E6=B5=8B=E8=AF=95=E5=A4=B1=E8=B4=A5=E3=80=81json-sche?= =?UTF-8?q?ma=E8=BD=AC=E6=8D=A2=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复接口用例创建性能测试失败、json-schema转换报错的问题 --- .../commons/json/JSONSchemaGenerator.java | 22 +++++++++--- .../scenario/maximize/MaximizeScenario.vue | 1 + .../components/list/ApiCaseSimpleList.vue | 27 ++++++++++++++- .../components/reference/ApiExtendBtns.vue | 34 +++++++++++++++---- .../common/json-schema/JsonSchemaEditor.vue | 8 +++-- 5 files changed, 77 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java index 3c00f6cab5..1a41c9b5b6 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java @@ -289,12 +289,26 @@ public class JSONSchemaGenerator { } private static List analyzeEnumProperty(JsonObject object) { - JsonArray enumValues = object.get("enum").getAsJsonArray(); List list = new LinkedList<>(); - for (JsonElement enumValueElem : enumValues) { - String enumValue = enumValueElem.getAsString(); - list.add(enumValue); + String jsonStr = null; + JsonArray enumValues = null; + try { + enumValues = object.get("enum").getAsJsonArray(); + for (JsonElement enumValueElem : enumValues) { + String enumValue = enumValueElem.getAsString(); + list.add(enumValue); + } + }catch (Exception e){ + jsonStr = object.get("enum").getAsString(); } + + if(jsonStr != null && list.isEmpty()){ + String [] arrs = jsonStr.split("\n"); + for (String str: arrs) { + list.add(str); + } + } + return list; } diff --git a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue index 6e79afb365..7ddbaf1855 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue @@ -370,6 +370,7 @@ export default { this.selectedNode = node; this.$store.state.selectStep = data; this.buttonData = buttons(this); + this.reload(); this.initPlugins(); }, suggestClick(node) { diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index 757ecbddd8..53174d2d46 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -206,7 +206,7 @@ import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn"; import MsBatchEdit from "../basis/BatchEdit"; import {API_METHOD_COLOUR, CASE_PRIORITY, DUBBO_METHOD, REQ_METHOD, SQL_METHOD, TCP_METHOD} from "../../model/JsonData"; -import {getBodyUploadFiles, getCurrentProjectID, getUUID} from "@/common/js/utils"; +import {getBodyUploadFiles, getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils"; import PriorityTableItem from "../../../../track/common/tableItems/planview/PriorityTableItem"; import MsApiCaseTableExtendBtns from "../reference/ApiCaseTableExtendBtns"; import MsReferenceView from "../reference/ReferenceView"; @@ -230,6 +230,7 @@ import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOpe import ApiCaseBatchRun from "@/business/components/api/definition/components/list/ApiCaseBatchRun"; import MsRequestResultTail from "../../../../api/definition/components/response/RequestResultTail"; import {editApiTestCaseOrder} from "@/network/api"; +import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting"; export default { name: "ApiCaseSimpleList", @@ -960,6 +961,18 @@ export default { } } }, + sortHashTree(stepArray) { + if (stepArray) { + for (let i in stepArray) { + if (!stepArray[i].clazzName) { + stepArray[i].clazzName = TYPE_TO_C.get(stepArray[i].type); + } + if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) { + this.sortHashTree(stepArray[i].hashTree); + } + } + } + }, createPerformance(row, environment) { /** * 思路:调用后台创建性能测试的方法,把当前案例的hashTree在后台转化为jmx并文件创建性能测试。 @@ -972,6 +985,7 @@ export default { this.$warning(this.$t('api_test.environment.select_environment')); return; } + let projectId = getCurrentProjectID(); let runData = []; let singleLoading = true; row.request = JSON.parse(row.request); @@ -983,17 +997,28 @@ export default { runData.push(row.request); /*触发执行操作*/ let testPlan = new TestPlan(); + testPlan.clazzName = TYPE_TO_C.get(testPlan.type); let threadGroup = new ThreadGroup(); + threadGroup.clazzName = TYPE_TO_C.get(threadGroup.type); threadGroup.hashTree = []; testPlan.hashTree = [threadGroup]; runData.forEach(item => { + item.projectId = projectId; + if (!item.clazzName) { + item.clazzName = TYPE_TO_C.get(item.type); + } threadGroup.hashTree.push(item); }); + this.sortHashTree(testPlan.hashTree); let reqObj = { id: row.id, testElement: testPlan, + clazzName: this.clazzName ? this.clazzName : TYPE_TO_C.get(this.type), name: row.name, projectId: this.projectId, + environmentMap: new Map([ + [projectId, environment.id] + ]), }; let bodyFiles = getBodyUploadFiles(reqObj, runData); reqObj.reportId = "run"; diff --git a/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue b/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue index 00d1d84c8e..bf7fbc2223 100644 --- a/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue +++ b/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue @@ -14,9 +14,10 @@