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 @@ + + - - +
基础设置