Fix grpcurl copy for rendered template tags

This commit is contained in:
Gregory Schier
2026-02-27 21:00:49 -08:00
parent d875eaa5bf
commit b6ad51c838
2 changed files with 22 additions and 3 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ export const plugin: PluginDefinition = {
async onSelect(ctx, args) { async onSelect(ctx, args) {
const rendered_request = await ctx.grpcRequest.render({ const rendered_request = await ctx.grpcRequest.render({
grpcRequest: args.grpcRequest, grpcRequest: args.grpcRequest,
purpose: 'preview', purpose: 'send',
}); });
const data = await convert(rendered_request, args.protoFiles); const data = await convert(rendered_request, args.protoFiles);
await ctx.clipboard.copyText(data); await ctx.clipboard.copyText(data);
@@ -103,7 +103,7 @@ export async function convert(request: Partial<GrpcRequest>, allProtoFiles: stri
// Add form params // Add form params
if (request.message) { if (request.message) {
xs.push('-d', `${quote(JSON.stringify(JSON.parse(request.message)))}`); xs.push('-d', quote(request.message));
xs.push(NEWLINE); xs.push(NEWLINE);
} }
@@ -151,7 +151,26 @@ describe('exporter-curl', () => {
[ [
`grpcurl -import-path '/'`, `grpcurl -import-path '/'`,
`-proto '/foo.proto'`, `-proto '/foo.proto'`,
`-d '{"foo":"bar","baz":1}'`, `-d '{\n "foo": "bar",\n "baz": 1\n}'`,
'yaak.app',
].join(' \\\n '),
);
});
test('Sends data with unresolved template tags', async () => {
expect(
await convert(
{
url: 'https://yaak.app',
message: '{"timestamp": ${[ faker "timestamp" ]}, "foo": "bar"}',
},
['/foo.proto'],
),
).toEqual(
[
`grpcurl -import-path '/'`,
`-proto '/foo.proto'`,
`-d '{"timestamp": \${[ faker "timestamp" ]}, "foo": "bar"}'`,
'yaak.app', 'yaak.app',
].join(' \\\n '), ].join(' \\\n '),
); );