orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

Orval default headers for POST override the ones I passed in options.headers #1629

Closed scottdickerson closed 2 months ago

scottdickerson commented 2 months ago

What are the steps to reproduce this issue?

When I pass additional headers as the options: RequestInit parameter, they're overridden since the ...options spread is under the headers: {'Content-Type': 'application/json'}. Notice that my Accept-Language is actually a parameter determined during runtime, so I don't think that change can be made at code generation time.

   response = await subscribeToNewsletter(
      { email },
      {
        headers: {
          'Content-Type': 'application/json',
          'Accept-Language': locale,
        },
      }
    );

export const subscribeToNewsletter = async (
  newsletterSubscriptionRequest: NewsletterSubscriptionRequest,
  options?: RequestInit
): Promise<subscribeToNewsletterResponse> => {
  return fetchWrapper<Promise<subscribeToNewsletterResponse>>(
    getSubscribeToNewsletterUrl(),
    {
      ...options,
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(newsletterSubscriptionRequest),
    }
  );
};

What happens?

My options.headers are ignored.

What were you expecting to happen?

My headers should override the default orval headers.

Any logs, error output, etc?

N/A

Any other comments?

What versions are you using?

  System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.63 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    orval: ^7.1.0 => 7.1.0 
melloware commented 2 months ago

Isn't that this ticket just fixed? https://github.com/orval-labs/orval/issues/1622

soartec-lab commented 2 months ago

Yes, this problem already fixed by #1627 so i close this issue.

@scottdickerson

This issue will be fixed in the next release version 👍