From 98cb9b32340fee04b9ae9f5ea3eb50b68fab907f Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Wed, 6 May 2020 21:23:50 +0200 Subject: [PATCH 1/3] Add format body option --- lang/en-US.json | 2 ++ pages/index.vue | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lang/en-US.json b/lang/en-US.json index fa4719a67..70ab9151f 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -184,6 +184,8 @@ "waiting_receive_schema": "(waiting to receive schema)", "gql_prettify_invalid_query": "Couldn't prettify an invalid query, solve query syntax errors and try again", "prettify_query": "Prettify Query", + "json_prettify_invalid_body": "Couldn't prettify an invalid body, solve json syntax errors and try again", + "prettify_body": "Prettify body", "cancel": "Cancel", "save": "Save", "dismiss": "Dismiss", diff --git a/pages/index.vue b/pages/index.vue index e07093356..6bc86c36a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -262,6 +262,13 @@ + @@ -2332,6 +2339,16 @@ export default { }, }) }, + prettifyRequestBody() { + try { + const jsonObj = JSON.parse(this.rawParams) + this.rawParams = JSON.stringify(jsonObj, null, 2) + } catch (e) { + this.$toast.error(`${this.$t("json_prettify_invalid_body")}`, { + icon: "error", + }) + } + }, copyRequest() { if (navigator.share) { const time = new Date().toLocaleTimeString() From 5c5fa5c4bc9464c4450fcafd4e635705ef30a2d9 Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Wed, 6 May 2020 23:02:22 +0200 Subject: [PATCH 2/3] Only show prettify button when request body is JSON --- pages/index.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/index.vue b/pages/index.vue index 6bc86c36a..9689bff61 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -266,6 +266,7 @@ class="icon" @click="prettifyRequestBody()" v-tooltip="$t('prettify_body')" + v-if="this.contentType.endsWith('json')" > assistant From a25b0d03492a758913f03b89af7ae06d4be6788d Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Thu, 7 May 2020 09:14:10 +0200 Subject: [PATCH 3/3] Only show prettify button when raw input is enabled --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 9689bff61..3bbc271b2 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -266,7 +266,7 @@ class="icon" @click="prettifyRequestBody()" v-tooltip="$t('prettify_body')" - v-if="this.contentType.endsWith('json')" + v-if="rawInput && this.contentType.endsWith('json')" > assistant