[Plugin] Cannot get inhereted parameters when rendering a request

I am building a plugin to copy the request as a nushell http command instead of curl.

I have the following request:

The header X-API-KEY is configured for the whole workspace.

But the plugin cannot access the inherited header: X-API-KEY.
Here is a code sample:

export const plugin: PluginDefinition = {
  httpRequestActions: [
    {
      label: "Copy as Nushell http",
      icon: "copy",
      async onSelect(ctx, args) {
        const rendered_request = await ctx.httpRequest.render({
          httpRequest: args.httpRequest,
          purpose: "preview",
        });
        const xs = [""];
        addHeaders(xs, (rendered_request.headers ?? []).filter(onlyEnabled));
        await ctx.clipboard.copyText(xs.join(" "));
      },
    },
  ],
};

function addHeaders(xs: string[], headers: HttpRequestHeader[]) {
  if (headers.length == 0)
    return;
  xs.push("--headers");
  xs.push("{");
  for (const h of headers) {
    xs.push(`${h.name}: "${h.value}"`);
  }
}

This would copy on the clipboard:

--headers { Content-Type: "application/json" Accept: "application/stacked" }

instead of:

--headers { Content-Type: "application/json" Accept: "application/stacked" X-API-KEY: "SECRET" }

As far as I can tell, the export as curl plugin has the same problem

Please authenticate to join the conversation.

Upvoters
Status

Released

Board

Feedback

Tags

Bug

Date

12 months ago

Author

Lucas Dell'Isola

Subscribe to post

Get notified by email when there are changes.