From 8c35d73a39d981231fa7860765be776204f8d956 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 1 Apr 2022 10:59:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=A4=A7=E6=96=87=E4=BB=B6JSON=E8=BD=ACSc?= =?UTF-8?q?hema=E6=A0=BC=E5=BC=8F=E5=8D=A1=E9=A1=BF=E7=8E=B0=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1011847 --user=赵勇 【接口测试】json太大,导入到接口定义和作为请求体发送会报错 https://www.tapd.cn/55049933/s/1128606 --- .../parse/JmeterDefinitionParser.java | 2 +- .../dto/definition/parse/Swagger2Parser.java | 6 ++-- .../io/metersphere/api/dto/scenario/Body.java | 35 +++++++++++-------- .../api/parse/ApiImportAbstractParser.java | 4 +-- .../api/parse/HarScenarioAbstractParser.java | 2 +- .../parse/PostmanAbstractParserParser.java | 2 +- .../service/HistoricalDataUpgradeService.java | 2 +- .../common/json-schema/convert/convert.js | 3 +- .../common/json-schema/import/ImportJson.vue | 1 - .../common/json-schema/schema/editor/main.vue | 9 +++-- 10 files changed, 39 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java index 60ffd132ca..445bfc9285 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java @@ -723,7 +723,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser implements ApiImportParser { bodyType = Body.FORM_DATA; break; case "application/json": - bodyType = Body.JSON; + bodyType = Body.JSON_STR; break; case "application/xml": bodyType = Body.XML; @@ -96,7 +96,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { case Body.WWW_FROM: contentType = "application/x-www-form-urlencoded"; break; - case Body.JSON: + case Body.JSON_STR: contentType = "application/json"; break; case Body.XML: diff --git a/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java index f96050fb41..a7f88abacc 100644 --- a/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java @@ -200,7 +200,7 @@ public abstract class HarScenarioAbstractParser extends ApiImportAbstractPars String bodyType = ""; switch (raw.getString("language")) { case "json": - bodyType = Body.JSON; + bodyType = Body.JSON_STR; break; case "xml": bodyType = Body.XML; diff --git a/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java b/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java index a8d95dc9ed..3b86db638a 100644 --- a/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java @@ -155,7 +155,7 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa String bodyType = ""; switch (raw.getString("language")) { case "json": - bodyType = Body.JSON; + bodyType = Body.JSON_STR; break; case "xml": bodyType = Body.XML; diff --git a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java index de62122d07..7f45d951eb 100644 --- a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java +++ b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java @@ -131,7 +131,7 @@ public class HistoricalDataUpgradeService { } if ("json".equals(request1.getBody().getFormat())) { if ("Raw".equals(request1.getBody().getType())) { - request1.getBody().setType(Body.JSON); + request1.getBody().setType(Body.JSON_STR); if (CollectionUtils.isEmpty(request1.getHeaders())) { List headers = new LinkedList<>(); headers.add(new KeyValue("Content-Type", "application/json")); diff --git a/frontend/src/business/components/common/json-schema/convert/convert.js b/frontend/src/business/components/common/json-schema/convert/convert.js index 3379f11b9c..6b23ef687e 100644 --- a/frontend/src/business/components/common/json-schema/convert/convert.js +++ b/frontend/src/business/components/common/json-schema/convert/convert.js @@ -127,7 +127,7 @@ class Convert { if (isArray(elementItem)) { let innerItemArr = this._deepTraversal(elementItem, `${$id}/items`, key + 'items'); itemArr.push(innerItemArr); - }else { + } else { //item不是Array,进行统一处理 let item = this._value2object(elementItem, `${$id}/items`, key + 'items'); item = Object.assign(item, this._json2schema(elementItem, `${$id}/items`)); @@ -206,6 +206,7 @@ class Convert { let objectTemplate = { $id: $id, title: `The ${key} Schema`, + hidden: true, mock: { "mock": value }, diff --git a/frontend/src/business/components/common/json-schema/import/ImportJson.vue b/frontend/src/business/components/common/json-schema/import/ImportJson.vue index 4048c49570..f4c3e8c7c2 100644 --- a/frontend/src/business/components/common/json-schema/import/ImportJson.vue +++ b/frontend/src/business/components/common/json-schema/import/ImportJson.vue @@ -94,7 +94,6 @@ return; } let jsonData = MsConvert.format(json5.parse(this.json)); - //let jsonData = GenerateSchema(json5.parse(this.json)); this.$emit('jsonData', jsonData); } else { if (!this.checkIsJsonSchema(this.jsonSchema)) { 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 9b92ce6143..ce36842790 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 @@ -3,7 +3,7 @@
- @@ -171,7 +171,7 @@ export default { advanced() { return TYPE[this.pickValue.type] }, - types(){ + types() { return TYPES(this.pickKey); }, advancedAttr() { @@ -205,6 +205,11 @@ export default { customing: false } }, + created() { + if (this.pickValue) { + this.hidden = this.pickValue.hidden; + } + }, methods: { onInputName(e) { const val = e.target.value