mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 20:01:28 +00:00
fix: grpc messages vanishes after save if the body contains variables (#6216)
This commit is contained in:
@@ -41,8 +41,8 @@ const SingleGrpcMessage = ({ message, item, collection, index, methodType, isCol
|
||||
|
||||
dispatch(updateRequestBody({
|
||||
content: currentMessages,
|
||||
itemUid: item.uid,
|
||||
collectionUid: collection.uid
|
||||
itemUid: item.uid,
|
||||
collectionUid: collection.uid
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -1043,22 +1043,6 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
||||
const messageName = namePair ? namePair.value : '';
|
||||
const messageContent = contentPair ? contentPair.value : '';
|
||||
|
||||
try {
|
||||
// Validate JSON by parsing (but don't modify the original string)
|
||||
JSON.parse(messageContent);
|
||||
} catch (error) {
|
||||
console.error("Error validating gRPC message JSON:", error);
|
||||
return {
|
||||
body: {
|
||||
mode: 'grpc',
|
||||
grpc: [{
|
||||
name: messageName,
|
||||
content: '{}'
|
||||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
mode: 'grpc',
|
||||
|
||||
@@ -39,6 +39,60 @@ settings {
|
||||
});
|
||||
});
|
||||
|
||||
describe('body:grpc', () => {
|
||||
it('parses message content with name and content', () => {
|
||||
const input = `
|
||||
body:grpc {
|
||||
name: message 1
|
||||
content: '''
|
||||
{"foo":"bar"}
|
||||
'''
|
||||
}
|
||||
`;
|
||||
|
||||
const expected = {
|
||||
body: {
|
||||
mode: 'grpc',
|
||||
grpc: [
|
||||
{
|
||||
content: '{"foo":"bar"}',
|
||||
name: 'message 1'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const output = parser(input);
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
|
||||
it('parses message with variables in content', () => {
|
||||
const input = `
|
||||
body:grpc {
|
||||
name: message 1
|
||||
content: '''
|
||||
{"id":{{userId}},"name":"{{userName}}"}
|
||||
'''
|
||||
}
|
||||
`;
|
||||
|
||||
const expected = {
|
||||
body: {
|
||||
mode: 'grpc',
|
||||
grpc: [
|
||||
{
|
||||
content: '{"id":{{userId}},"name":"{{userName}}"}',
|
||||
name: 'message 1'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const output = parser(input);
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multi-line values', () => {
|
||||
it('parses multi-line values in URL, headers, params, and vars', () => {
|
||||
const input = `
|
||||
|
||||
Reference in New Issue
Block a user