Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FETCH: Custom headers provided in options are overwritten for POST #1622

Closed
sharenz opened this issue Sep 11, 2024 · 7 comments · Fixed by #1627
Closed

FETCH: Custom headers provided in options are overwritten for POST #1622

sharenz opened this issue Sep 11, 2024 · 7 comments · Fixed by #1627
Assignees
Labels
fetch Fetch client related issue
Milestone

Comments

@sharenz
Copy link

sharenz commented Sep 11, 2024

What are the steps to reproduce this issue?

  1. Use the FETCH Client
  2. Set a custom header using options
  3. Make a POST call

What happens?

The custom header gets overwritten

What were you expecting to happen?

The custom headers are merged with the other headers.

Proposed fix by shodai on discord:

Indeed, this may needs to be merge options.headers and { 'Content-Type': 'application/json' } like a follow:

return customFetch<Promise<createPetsResponse>>(getCreatePetsUrl(), {
  ...options,
  method: 'POST',
  headers: { 'Content-Type': 'application/json', ...options.headers },
  body: JSON.stringify(createPetsBodyItem),
});
@melloware melloware added the fetch Fetch client related issue label Sep 11, 2024
@soartec-lab
Copy link
Member

Thanks for made it 👍

@Poylar
Copy link

Poylar commented Sep 14, 2024

Thanks for made it 👍

Is there any temporary solution? This problem is exhausting me.
And is it possible to get information about when this can be fixed?
week. month, day?
The thing is that I have an urgent project and I need to understand whether to continue working with orval or take something else for generation.

@soartec-lab
Copy link
Member

@Poylar

It will probably take a week or a month to fix it.
And you can avoid this problem by using custom fetch as a workaround.

https://orval.dev/guides/fetch-client#custom-fetch-client
https://github.com/orval-labs/orval/blob/master/samples/next-app-with-fetch/custom-fetch.ts#L32-L45

@soartec-lab
Copy link
Member

I fixed it by #1627 👍

@Poylar
Copy link

Poylar commented Sep 15, 2024

@Poylar

It will probably take a week or a month to fix it. And you can avoid this problem by using custom fetch as a workaround.

https://orval.dev/guides/fetch-client#custom-fetch-client https://github.com/orval-labs/orval/blob/master/samples/next-app-with-fetch/custom-fetch.ts#L32-L45

yeah, im already using custom fetch, but i cant override header outside function. for example

export const updateCart = async (
  updateCartBody: UpdateCartBody,
  options?: RequestInit
): Promise<updateCartResponse> => {
  const res = await fetch(getUpdateCartUrl(), {
    ...options,
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(updateCartBody)
  });
  const data = await res.json();

  return { status: res.status, data };
};

i cant override with


await updateCart(body,{
headers: {
...
}
})

@melloware melloware added this to the 7.1.1 milestone Sep 15, 2024
@soartec-lab
Copy link
Member

@Poylar
yes. Currently it can't be overridden with optional when calling arguments.
So I ask when the next release is planned.

@soartec-lab
Copy link
Member

@Poylar @sharenz @scottdickerson

A new version V 7.1.1 with the fix has been released, please check it here 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetch Fetch client related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants