Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/openapi-fetch/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export function defaultPathSerializer(pathname, pathParams) {
* @type {import("./index.js").defaultBodySerializer}
*/
export function defaultBodySerializer(body, headers) {
if (body instanceof FormData || typeof body === "string" || body instanceof URLSearchParams || body instanceof Blob) {
if (body instanceof FormData) {
return body;
}
if (headers) {
Expand Down
10 changes: 4 additions & 6 deletions packages/openapi-fetch/test/common/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,30 @@ describe("request", () => {
});

test.each(BODY_ACCEPTING_METHODS)("`''` body (with body serializer) - %s", async (method) => {
const body = ''
const bodySerializer = vi.fn((body) => `Serialized: ${JSON.stringify(body)}`);
const { bodyUsed, bodyText } = await fireRequestAndGetBodyInformation({
bodySerializer,
method,
fetchOptions: {
body,
body: "",
},
});

expect(bodyUsed).toBe(true);
expect(bodyText).toBe(`Serialized: ${body}`);
expect(bodyText).toBe('Serialized: ""');
expect(bodySerializer).toBeCalled();
});

test.each(BODY_ACCEPTING_METHODS)("`''` body (without body serializer) - %s", async (method) => {
const body = ''
const { bodyUsed, bodyText } = await fireRequestAndGetBodyInformation({
method,
fetchOptions: {
body,
body: "",
},
});

expect(bodyUsed).toBe(true);
expect(bodyText).toBe(body);
expect(bodyText).toBe('""');
});

test.each(BODY_ACCEPTING_METHODS)("`0` body (with body serializer) - %s", async (method) => {
Expand Down