Compare commits

...

1 Commits

Author SHA1 Message Date
Gregory Schier
99afb0d178 Fix grpcurl copy for rendered template tags 2026-02-27 21:00:49 -08:00
2 changed files with 22 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ export const plugin: PluginDefinition = {
async onSelect(ctx, args) {
const rendered_request = await ctx.grpcRequest.render({
grpcRequest: args.grpcRequest,
purpose: 'preview',
purpose: 'send',
});
const data = await convert(rendered_request, args.protoFiles);
await ctx.clipboard.copyText(data);
@@ -103,7 +103,7 @@ export async function convert(request: Partial<GrpcRequest>, allProtoFiles: stri
// Add form params
if (request.message) {
xs.push('-d', `${quote(JSON.stringify(JSON.parse(request.message)))}`);
xs.push('-d', quote(request.message));
xs.push(NEWLINE);
}

View File

@@ -151,7 +151,26 @@ describe('exporter-curl', () => {
[
`grpcurl -import-path '/'`,
`-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',
].join(' \\\n '),
);