diff --git a/packages/bruno-app/src/components/RequestPane/WsBody/index.js b/packages/bruno-app/src/components/RequestPane/WsBody/index.js
index 8010df8e6..7af277387 100644
--- a/packages/bruno-app/src/components/RequestPane/WsBody/index.js
+++ b/packages/bruno-app/src/components/RequestPane/WsBody/index.js
@@ -20,7 +20,7 @@ const TYPE_BY_DECODER = {
xml: 'xml'
};
-const DECODER_BY_TYPE = invert(TYPE_BY_DECODER)
+const DECODER_BY_TYPE = invert(TYPE_BY_DECODER);
const SingleWSMessage = ({
message,
@@ -41,14 +41,14 @@ const SingleWSMessage = ({
const { name, content, decoder } = message;
const [messageFormat, setMessageFormat] = useState(autoDetectLang(content));
- const onUpdateMessageType = mode => {
- setMessageFormat(mode)
-
+ const onUpdateMessageType = type => {
+ setMessageFormat(type);
+
const currentMessages = [...(body.ws || [])];
currentMessages[index] = {
...currentMessages[index],
- type: DECODER_BY_TYPE[messageFormat],
+ type: DECODER_BY_TYPE[type],
};
dispatch(
@@ -58,7 +58,7 @@ const SingleWSMessage = ({
collectionUid: collection.uid
})
);
- }
+ };
const onEdit = (value) => {
const currentMessages = [...(body.ws || [])];
@@ -96,9 +96,9 @@ const SingleWSMessage = ({
const getContainerHeight =
canClientSendMultipleMessages && body.ws.length > 1 ? `${isCollapsed ? '' : 'h-80'}` : 'h-full';
-
+
let codeType = messageFormat;
- if (TYPE_BY_DECODER[decoder]){
+ if (TYPE_BY_DECODER[decoder]) {
codeType = TYPE_BY_DECODER[decoder];
}
@@ -108,53 +108,47 @@ const SingleWSMessage = ({
json: 'application/ld+json'
};
-
const onPrettify = () => {
- if(codeType === "json"){
- try {
- const edits = format(content, undefined, { tabSize: 2, insertSpaces: true });
- const prettyBodyJson = applyEdits(content, edits);
+ if (codeType === 'json') {
+ try {
+ const edits = format(content, undefined, { tabSize: 2, insertSpaces: true });
+ const prettyBodyJson = applyEdits(content, edits);
- const currentMessages = [...(body.ws || [])];
- currentMessages[index] = {
- name: name ? name : `message ${index + 1}`,
- content: prettyBodyJson
- };
- dispatch(
- updateRequestBody({
- content: currentMessages,
- itemUid: item.uid,
- collectionUid: collection.uid
- })
- );
- } catch (e) {
- toastError(new Error('Unable to prettify. Invalid JSON format.'));
- }
+ const currentMessages = [...(body.ws || [])];
+ currentMessages[index] = {
+ name: name ? name : `message ${index + 1}`,
+ content: prettyBodyJson,
+ };
+ dispatch(updateRequestBody({
+ content: currentMessages,
+ itemUid: item.uid,
+ collectionUid: collection.uid,
+ }));
+ } catch (e) {
+ toastError(new Error('Unable to prettify. Invalid JSON format.'));
}
-
- if (codeType === "xml") {
- try {
- const prettyBodyXML = xmlFormat(content, { collapseContent: true });
+ }
- const currentMessages = [...(body.ws || [])];
- currentMessages[index] = {
- name: name ? name : `message ${index + 1}`,
- content: prettyBodyXML
- };
+ if (codeType === 'xml') {
+ try {
+ const prettyBodyXML = xmlFormat(content, { collapseContent: true });
- dispatch(
- updateRequestBody({
- content: currentMessages,
- itemUid: item.uid,
- collectionUid: collection.uid
- })
- );
- } catch (e) {
- toastError(new Error('Unable to prettify. Invalid XML format.'));
- }
- }
+ const currentMessages = [...(body.ws || [])];
+ currentMessages[index] = {
+ name: name ? name : `message ${index + 1}`,
+ content: prettyBodyXML,
+ };
+
+ dispatch(updateRequestBody({
+ content: currentMessages,
+ itemUid: item.uid,
+ collectionUid: collection.uid,
+ }));
+ } catch (e) {
+ toastError(new Error('Unable to prettify. Invalid XML format.'));
+ }
+ }
};
-
return (
{
try {
@@ -110,15 +107,11 @@ const bruToJson = (bru) => {
});
} else if (requestType === 'ws-request') {
transformedJson.request.auth.mode = _.get(json, 'ws.auth', 'none');
- transformedJson.request.body = _.get(json, 'body', {
+ const bodyFromBru = _.get(json, 'body') || {};
+ transformedJson.request.body = {
mode: 'ws',
- ws: [
- {
- name: 'message 1',
- content: '{}'
- }
- ]
- });
+ ws: [bodyFromBru],
+ };
} else {
transformedJson.request.method = _.upperCase(_.get(json, 'http.method'));
transformedJson.request.auth.mode = _.get(json, 'http.auth', 'none');
diff --git a/packages/bruno-filestore/src/formats/bru/index.ts b/packages/bruno-filestore/src/formats/bru/index.ts
index 4776ca48a..c596561cd 100644
--- a/packages/bruno-filestore/src/formats/bru/index.ts
+++ b/packages/bruno-filestore/src/formats/bru/index.ts
@@ -79,15 +79,13 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
});
} else if (requestType === 'ws-request') {
transformedJson.request.auth.mode = _.get(json, 'ws.auth', 'none');
- transformedJson.request.body = _.get(json, 'body', {
+ const bodyFromBru = _.get(json, 'body') || {};
+ transformedJson.request.body = {
mode: 'ws',
- ws: _.get(json, 'body.ws', [
- {
- name: 'message 1',
- content: '{}'
- }
- ])
- });
+ ws: [
+ bodyFromBru,
+ ],
+ };
} else {
// For HTTP and GraphQL
(transformedJson.request as any).params = _.get(json, 'params', []);
@@ -184,7 +182,6 @@ export const jsonRequestToBru = (json: any): string => {
bruJson.ws = {
url: _.get(json, 'request.url'),
auth: _.get(json, 'request.auth.mode', 'none'),
- body: _.get(json, 'request.body.mode', 'ws')
};
const method = _.get(json, 'request.method');
const methodType = _.get(json, 'request.methodType');
diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js
index 2a9b10d72..201db8819 100644
--- a/packages/bruno-lang/v2/src/bruToJson.js
+++ b/packages/bruno-lang/v2/src/bruToJson.js
@@ -131,7 +131,7 @@ const grammar = ohm.grammar(`Bru {
oauth2RefreshTokenReqQueryParams = "auth:oauth2:additional_params:refresh_token_req:queryparams" dictionary
oauth2RefreshTokenReqBody = "auth:oauth2:additional_params:refresh_token_req:body" dictionary
- body = "body" st* "{" nl* textblock tagend
+ body = "body" st* "{" nl* (pairlist|textblock) tagend
bodyjson = "body:json" st* "{" nl* textblock tagend
bodytext = "body:text" st* "{" nl* textblock tagend
bodyxml = "body:xml" st* "{" nl* textblock tagend
@@ -846,13 +846,18 @@ const sem = grammar.createSemantics().addAttribute('ast', {
}
};
},
- body(_1, _2, _3, _4, textblock, _5) {
+ body(_1, _2, _3, _4, content, _5) {
+ if (Array.isArray(content.ast)) {
+ return {
+ body: mapPairListToKeyValPair([content.ast]),
+ };
+ }
return {
http: {
body: 'json'
},
body: {
- json: outdentString(textblock.sourceString)
+ json: outdentString(content.sourceString),
}
};
},
@@ -1005,31 +1010,6 @@ const sem = grammar.createSemantics().addAttribute('ast', {
}
};
},
- // TODO: reaper remove `:ws`
- // TODO: reaper add `type`
- bodyws(_1, dictionary) {
- const pairs = mapPairListToKeyValPairs(dictionary.ast, false);
- const namePair = _.find(pairs, { name: 'name' });
- const contentPair = _.find(pairs, { name: 'content' });
- const typePair = _.find(pairs, { name: 'type' });
-
- const messageName = namePair ? namePair.value : '';
- const messageContent = contentPair ? contentPair.value : '';
- const messageTypeContent = typePair ? typePair.value : '';
-
- return {
- body: {
- mode: 'ws',
- ws: [
- {
- name: messageName,
- type: messageTypeContent,
- content: messageContent
- }
- ]
- }
- };
- }
});
const parser = (input) => {
diff --git a/packages/bruno-lang/v2/src/jsonToBru.js b/packages/bruno-lang/v2/src/jsonToBru.js
index affbf9f13..42de2e1b6 100644
--- a/packages/bruno-lang/v2/src/jsonToBru.js
+++ b/packages/bruno-lang/v2/src/jsonToBru.js
@@ -634,13 +634,13 @@ ${indentString(body.sparql)}
if (body && body.ws) {
// Convert each ws message to a separate body:ws block
if (Array.isArray(body.ws)) {
- body.ws.forEach((m) => {
- const { name, content, type = "" } = m;
+ body.ws.forEach(message => {
+ const { name, content, type = '' } = message;
- bru += `body:ws {\n`;
+ bru += `body {\n`;
bru += `${indentString(`name: ${getValueString(name)}`)}\n`;
- if(type.length){
+ if (type.length) {
bru += `${indentString(`type: ${getValueString(type)}`)}\n`;
}