这是indexloc提供的服务,不要输入任何密码
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
5 changes: 5 additions & 0 deletions .changeset/large-rats-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**client-ofetch**: fix FormData boundary mismatch
17 changes: 15 additions & 2 deletions examples/openapi-ts-ofetch/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const createClient = (config: Config = {}): Client => {
const applyRequestInterceptors = async (
request: Request,
opts: ResolvedRequestOptions,
body: BodyInit | null | undefined,
) => {
for (const fn of interceptors.request.fns) {
if (fn) {
Expand All @@ -138,6 +139,18 @@ export const createClient = (config: Config = {}): Client => {
// body comes only from getValidRequestBody(options)
// reflect signal if present
opts.signal = (request as any).signal as AbortSignal | undefined;

// When body is FormData, remove Content-Type header to avoid boundary mismatch.
// Note: We already delete Content-Type in resolveOptions for FormData, but the
// Request constructor (line 175) re-adds it with an auto-generated boundary.
// Since we pass the original FormData (not the Request's body) to ofetch, and
// ofetch will generate its own boundary, we must remove the Request's Content-Type
// to let ofetch set the correct one. Otherwise the boundary in the header won't
// match the boundary in the actual multipart body sent by ofetch.
if (typeof FormData !== 'undefined' && body instanceof FormData) {
opts.headers.delete('Content-Type');
}

return request;
};

Expand Down Expand Up @@ -176,7 +189,7 @@ export const createClient = (config: Config = {}): Client => {
};
let request = new Request(url, requestInit);

request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
const finalUrl = request.url;

// build ofetch options and perform the request (.raw keeps the Response)
Expand Down Expand Up @@ -235,7 +248,7 @@ export const createClient = (config: Config = {}): Client => {
method,
onRequest: async (url, init) => {
let request = new Request(url, init);
request = await applyRequestInterceptors(request, opts);
request = await applyRequestInterceptors(request, opts, networkBody);
return request;
},
serializedBody: networkBody as BodyInit | null | undefined,
Expand Down
Loading
Loading