From 820e3033ea31d1e9ce81f91a290a69431e1f8225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Tue, 31 Oct 2023 11:55:45 +0100 Subject: [PATCH 1/4] Remove unused conditions in QueryResult The mode is returned by getCodeMirrorModeBasedOnContentType(), which always prefixes the returned values with 'application/'. However returning data on those application/html or application/text break Bruno. --- .../bruno-app/src/components/ResponsePane/QueryResult/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index b5508ba1b..40807bb05 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -28,7 +28,7 @@ const formatResponse = (data, mode) => { return safeStringifyJSON(parsed, true); } - if (['text', 'html'].includes(mode) || typeof data === 'string') { + if (typeof data === 'string') { return data; } From 76a26b634df314fc9c89ff921e82dfa6ad32fbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Tue, 31 Oct 2023 11:58:09 +0100 Subject: [PATCH 2/4] JSON in QueryResult should always be indented Some APIs return the wrong Content-Type 'application/html', but valid JSON as payload. In this cases the data is still typeof object and a indented JSON makes it easier to work with. However JSON folding and highlighting will still be off in this case. --- .../bruno-app/src/components/ResponsePane/QueryResult/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index 40807bb05..392780d5c 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -32,7 +32,7 @@ const formatResponse = (data, mode) => { return data; } - return safeStringifyJSON(data); + return safeStringifyJSON(data, true); }; const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => { From dc32d7246c4fc7d7b7959781fd24df1616eced64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Wed, 1 Nov 2023 16:24:38 +0100 Subject: [PATCH 3/4] Use the body to check for a json content type --- .../src/components/ResponsePane/QueryResult/index.js | 2 +- packages/bruno-app/src/utils/common/codemirror.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index 392780d5c..c2930ad43 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -37,7 +37,7 @@ const formatResponse = (data, mode) => { const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => { const contentType = getContentType(headers); - const mode = getCodeMirrorModeBasedOnContentType(contentType); + const mode = getCodeMirrorModeBasedOnContentType(contentType, data); const formattedData = formatResponse(data, mode); const { storedTheme } = useTheme(); diff --git a/packages/bruno-app/src/utils/common/codemirror.js b/packages/bruno-app/src/utils/common/codemirror.js index 78016de6f..3061719cc 100644 --- a/packages/bruno-app/src/utils/common/codemirror.js +++ b/packages/bruno-app/src/utils/common/codemirror.js @@ -43,7 +43,10 @@ export const defineCodeMirrorBrunoVariablesMode = (variables, mode) => { }); }; -export const getCodeMirrorModeBasedOnContentType = (contentType) => { +export const getCodeMirrorModeBasedOnContentType = (contentType, body) => { + if (typeof body === 'object') { + return 'application/ld+json'; + } if (!contentType || typeof contentType !== 'string') { return 'application/text'; } From 631e436079906c281da618cf076b3bc4787dac18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Wed, 1 Nov 2023 17:32:57 +0100 Subject: [PATCH 4/4] Revert "JSON in QueryResult should always be indented" This reverts commit 76a26b634df314fc9c89ff921e82dfa6ad32fbec. --- .../bruno-app/src/components/ResponsePane/QueryResult/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index c2930ad43..ff5618a5d 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -32,7 +32,7 @@ const formatResponse = (data, mode) => { return data; } - return safeStringifyJSON(data, true); + return safeStringifyJSON(data); }; const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => {