From 3f6e67bb26734604002796876503640df39e6eab Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 7 Sep 2021 14:31:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=9A=8F=E6=9C=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 14 +- .../commons/json/JSONSchemaGenerator.java | 12 +- .../definition/components/body/ApiBody.vue | 14 +- .../request/http/ApiHttpRequestForm.vue | 403 +++++++++--------- .../common/json-schema/schema/editor/main.vue | 17 +- .../json-schema/schema/editor/type/array.js | 5 +- .../json-schema/schema/editor/type/integer.js | 61 +-- .../json-schema/schema/editor/type/number.js | 53 +-- .../json-schema/schema/editor/type/string.js | 65 +-- frontend/src/i18n/zh-CN.js | 6 +- 10 files changed, 349 insertions(+), 301 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index ccd62bac8c..8f9ad954d0 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -440,13 +440,23 @@ xmindjbehaveplugin 0.8 - + io.metersphere metersphere-plugin-core 1.0 - + + + com.apifan.common + common-random + 1.0.7 + + + com.github.mifmif + generex + 1.0.2 + 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 6d3dedb8c3..3c00f6cab5 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java @@ -16,17 +16,15 @@ public class JSONSchemaGenerator { } private static void analyzeSchema(String json, JSONObject rootObj) { - // Let's start with the root element of the file - JsonObject rootElement = null; try { - JsonParser jsonParser = new JsonParser(); - JsonElement inputElement = jsonParser.parse(json); - rootElement = inputElement.getAsJsonObject(); + Gson gson = new Gson(); + JsonElement element = gson.fromJson(json, JsonElement.class); + JsonObject rootElement = element.getAsJsonObject(); + analyzeRootSchemaElement(rootElement, rootObj); } catch (Exception e) { e.printStackTrace(); } - analyzeRootSchemaElement(rootElement, rootObj); } private static void analyzeRootSchemaElement(JsonObject rootElement, JSONObject rootObj) { @@ -232,7 +230,7 @@ public class JSONSchemaGenerator { String value = ScriptEngineUtils.buildFunctionCallString(itemsObject.get("mock").getAsJsonObject().get("mock").getAsString()); array.add(value); } else { - array.add(null); + array.add(""); } } else if (itemsObject.has("type") && itemsObject.get("type").getAsString().equals("number")) { if (itemsObject.has("default")) { diff --git a/frontend/src/business/components/api/definition/components/body/ApiBody.vue b/frontend/src/business/components/api/definition/components/body/ApiBody.vue index 4758851de7..e499688afa 100644 --- a/frontend/src/business/components/api/definition/components/body/ApiBody.vue +++ b/frontend/src/business/components/api/definition/components/body/ApiBody.vue @@ -126,6 +126,18 @@ export default { codeEditActive: true }; }, + watch:{ + 'body.raw'(){ + if(this.body.format !== 'JSON-SCHEMA' && this.body.raw){ + try { + const MsConvert = new Convert(); + this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw)); + }catch (ex){ + this.body.jsonSchema = ""; + } + } + } + }, methods: { reloadCodeEdit() { this.codeEditActive = false; @@ -136,7 +148,7 @@ export default { formatChange() { const MsConvert = new Convert(); if (this.body.format === 'JSON-SCHEMA') { - if (this.body.raw) { + if (this.body.raw && !this.body.jsonSchema) { this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw)); } } else { diff --git a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue index 634db1891f..53113ff027 100644 --- a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue @@ -8,14 +8,14 @@ - {{$t('api_test.request.headers')}} + {{ $t('api_test.request.headers') }}
-
{{headers.length-1}}
+
{{ headers.length - 1 }}
- {{$t("commons.batch_add")}} + {{ $t("commons.batch_add") }}
@@ -23,13 +23,13 @@ - {{$t('api_test.definition.request.query_param')}} + {{ $t('api_test.definition.request.query_param') }}
-
{{request.arguments.length-1}}
+
{{ request.arguments.length - 1 }}
- {{$t("commons.batch_add")}} + {{ $t("commons.batch_add") }}
@@ -38,14 +38,14 @@ - {{$t('api_test.definition.request.rest_param')}} + {{ $t('api_test.definition.request.rest_param') }}
-
{{request.rest.length-1}}
+
{{ request.rest.length - 1 }}
- {{$t("commons.batch_add")}} + {{ $t("commons.batch_add") }}
@@ -58,7 +58,7 @@ - {{$t('api_test.definition.request.auth_config')}} + {{ $t('api_test.definition.request.auth_config') }} @@ -67,11 +67,11 @@ - - - - - + + + @@ -84,206 +84,211 @@ diff --git a/frontend/src/business/components/common/json-schema/schema/editor/main.vue b/frontend/src/business/components/common/json-schema/schema/editor/main.vue index 494fc27faa..5ee4971a2b 100644 --- a/frontend/src/business/components/common/json-schema/schema/editor/main.vue +++ b/frontend/src/business/components/common/json-schema/schema/editor/main.vue @@ -50,11 +50,10 @@

基础设置

- - - - -
{{ $t('schema.'+key)}}
+ + +
+ @@ -64,10 +63,14 @@ + + - - +