From aef1c260d0af3b681686c601f5992b1a01649eb9 Mon Sep 17 00:00:00 2001 From: RubyLiu Date: Thu, 27 Jul 2023 11:03:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DMock-json=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E6=8A=A5JSON=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/mock/Components/MockApiBody.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api-test/frontend/src/business/definition/components/mock/Components/MockApiBody.vue b/api-test/frontend/src/business/definition/components/mock/Components/MockApiBody.vue index 87ce8acaf5..a859f193ef 100644 --- a/api-test/frontend/src/business/definition/components/mock/Components/MockApiBody.vue +++ b/api-test/frontend/src/business/definition/components/mock/Components/MockApiBody.vue @@ -196,8 +196,14 @@ export default { const MsConvert = new Convert(); if (this.body.format === 'JSON-SCHEMA') { - if (this.body.raw && !this.body.jsonSchema) { - this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw)); + if (this.body.raw) { + try { + const jsonObj = JSON.parse(this.body.raw) + this.body.jsonSchema = MsConvert.format(jsonObj); + } catch (e) { + this.body.format = 'JSON'; + this.$message.error(this.$t('api_definition.body.json_format_error')); + } } } else { if (this.body.jsonSchema) {