From b596082f6d26385f58ec8fc123b9b7634dddd11b Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 11 May 2021 18:10:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8DJSONSchema=20Number=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=B0=8F=E6=95=B0=E7=82=B9=E5=90=8E=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E7=BB=93=E6=9E=9C=E4=B8=8D=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/json/JSONSchemaGenerator.java | 21 ++++++++++++++++++- .../scenario/component/ApiComponent.vue | 4 ++-- .../scenario/component/LoopController.vue | 6 ++++-- 3 files changed, 26 insertions(+), 5 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 9c9321abb0..3706ad826a 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java @@ -143,7 +143,7 @@ public class JSONSchemaGenerator { // TODO 6.3.3 in json-schema-validation } - } else if (propertyObjType.equals("integer") || propertyObjType.equals("number")) { + } else if (propertyObjType.equals("integer")) { // 先设置空值 concept.put(propertyName, 0); if (object.has("default")) { @@ -183,6 +183,25 @@ public class JSONSchemaGenerator { } // Section 6.2.5 in json-schema-validation. Resolved as OCL + } else if (propertyObjType.equals("number")) { + // 先设置空值 + concept.put(propertyName, 0); + if (object.has("default")) { + concept.put(propertyName, object.get("default")); + } + if (object.has("mock") && object.get("mock").getAsJsonObject() != null && StringUtils.isNotEmpty(object.get("mock").getAsJsonObject().get("mock").getAsString())) { + try { + Number value = object.get("mock").getAsJsonObject().get("mock").getAsNumber(); + if (value.toString().indexOf(".") == -1) { + concept.put(propertyName, value.intValue()); + } else { + concept.put(propertyName, value.floatValue()); + } + } catch (Exception e) { + String value = ScriptEngineUtils.calculate(object.get("mock").getAsJsonObject().get("mock").getAsString()); + concept.put(propertyName, value); + } + } } else if (propertyObjType.equals("boolean")) { // 先设置空值 concept.put(propertyName, false); diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 7e06b5b9e5..2fc6e2f559 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -58,7 +58,7 @@
- +
@@ -168,7 +168,7 @@ watch: { envMap() { this.getEnvironments(); - } + }, }, computed: { displayColor() { diff --git a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue index 277bc66639..416844363e 100644 --- a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue @@ -12,7 +12,7 @@ @@ -280,6 +280,7 @@ if (item.type === "HTTPSamplerProxy" || item.type === "DubboSampler" || item.type === "JDBCSampler" || item.type === "TCPSampler") { item.result = this.requestResult; item.activeName = this.activeName; + item.active = true; item.requestResult = undefined; } if (item.hashTree && item.hashTree.length > 0) { @@ -318,11 +319,12 @@ this.activeName = this.requestResult && this.requestResult.scenarios && this.requestResult.scenarios !== null && this.requestResult.scenarios.length > 0 ? this.requestResult.scenarios[0].name : ""; // 把请求结果分给各个请求 this.setResult(this.controller.hashTree); - this.$emit("refReload"); + this.$emit("refReload",this.node); } catch (e) { throw e; } this.loading = false; + this.node.expanded = true; this.reload(); } else { setTimeout(this.getReport, 2000);