Skip to content

Commit

Permalink
fix(fetch): fetch client can now override headers with options (#…
Browse files Browse the repository at this point in the history
…1627)

* fix(fetch): `header` can now be overwritten with `options`

* chore: update sample apps
  • Loading branch information
soartec-lab authored Sep 15, 2024
1 parent bdc584b commit d9fcfd5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ${
const ignoreContentTypes = ['multipart/form-data'];
const fetchHeadersOption =
body.contentType && !ignoreContentTypes.includes(body.contentType)
? `headers: { 'Content-Type': '${body.contentType}' }`
? `headers: { 'Content-Type': '${body.contentType}', ...options?.headers }`
: '';
const requestBodyParams = generateBodyOptions(
body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const createPets = async (
const res = await fetch(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
const data = await res.json();
Expand All @@ -92,7 +92,7 @@ export const updatePets = async (
const res = await fetch(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
const data = await res.json();
Expand Down
4 changes: 2 additions & 2 deletions samples/next-app-with-fetch/app/gen/pets/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const createPets = async (
return customFetch<Promise<createPetsResponse>>(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
};
Expand All @@ -115,7 +115,7 @@ export const updatePets = async (
return customFetch<Promise<updatePetsResponse>>(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const createPets = async (
const res = await fetch(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBody),
});
const data = await res.json();
Expand Down
4 changes: 2 additions & 2 deletions samples/react-query/custom-fetch/src/gen/pets/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const createPets = async (
return customFetch<Promise<createPetsResponse>>(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
};
Expand Down Expand Up @@ -304,7 +304,7 @@ export const updatePets = async (
return customFetch<Promise<updatePetsResponse>>(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
};
Expand Down
4 changes: 2 additions & 2 deletions samples/svelte-query/custom-fetch/src/gen/pets/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const createPets = async (
return customFetch<Promise<createPetsResponse>>(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
};
Expand Down Expand Up @@ -254,7 +254,7 @@ export const updatePets = async (
return customFetch<Promise<updatePetsResponse>>(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
};
Expand Down
4 changes: 2 additions & 2 deletions samples/swr-with-zod/src/gen/endpoints/pets/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const createPets = async (
const res = await fetch(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
const data = await res.json();
Expand Down Expand Up @@ -205,7 +205,7 @@ export const updatePets = async (
const res = await fetch(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
const data = await res.json();
Expand Down
4 changes: 2 additions & 2 deletions samples/vue-query/custom-fetch/src/gen/pets/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const createPets = async (
return customFetch<Promise<createPetsResponse>>(getCreatePetsUrl(), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(createPetsBodyItem),
});
};
Expand Down Expand Up @@ -256,7 +256,7 @@ export const updatePets = async (
return customFetch<Promise<updatePetsResponse>>(getUpdatePetsUrl(), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(pet),
});
};
Expand Down

0 comments on commit d9fcfd5

Please sign in to comment.