Skip to content

Commit 5d521b1

Browse files
committed
chore(ofetch): update snapshots
1 parent 2b94df0 commit 5d521b1

File tree

20 files changed

+550
-80
lines changed

20 files changed

+550
-80
lines changed

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/client.gen.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ export const createClient = (config: Config = {}): Client => {
7878
opts.headers.delete('Content-Type');
7979
}
8080

81+
// If user provides a raw body (no serializer), adjust Content-Type sensibly.
82+
// Avoid overriding explicit user-defined headers; only correct the default JSON header.
83+
if (
84+
opts.body !== undefined &&
85+
opts.bodySerializer === null &&
86+
(opts.headers.get('Content-Type') || '').toLowerCase() ===
87+
'application/json'
88+
) {
89+
const b: unknown = opts.body;
90+
if (typeof FormData !== 'undefined' && b instanceof FormData) {
91+
// Let the runtime set proper boundary
92+
opts.headers.delete('Content-Type');
93+
} else if (
94+
typeof URLSearchParams !== 'undefined' &&
95+
b instanceof URLSearchParams
96+
) {
97+
// Set standard urlencoded content type with charset
98+
opts.headers.set(
99+
'Content-Type',
100+
'application/x-www-form-urlencoded;charset=UTF-8',
101+
);
102+
} else if (typeof Blob !== 'undefined' && b instanceof Blob) {
103+
const t = b.type?.trim();
104+
if (t) {
105+
opts.headers.set('Content-Type', t);
106+
} else {
107+
// No known type for the blob: avoid sending misleading JSON header
108+
opts.headers.delete('Content-Type');
109+
}
110+
}
111+
}
112+
81113
// Precompute network body for retries and consistent handling
82114
const networkBody = getValidRequestBody(opts) as
83115
| RequestInit['body']
@@ -116,14 +148,18 @@ export const createClient = (config: Config = {}): Client => {
116148
body: BodyInit | null | undefined,
117149
responseType: OfetchResponseType | undefined,
118150
) => {
119-
const effectiveRetry = isRepeatableBody(body) ? (opts.retry as any) : (0 as any);
151+
const effectiveRetry = isRepeatableBody(body)
152+
? (opts.retry as any)
153+
: (0 as any);
120154
return buildOfetchOptions(opts, body, responseType, effectiveRetry);
121155
};
122156

123157
const request: Client['request'] = async (options) => {
124-
const { networkBody: initialNetworkBody, opts, url } = await resolveOptions(
125-
options as any,
126-
);
158+
const {
159+
networkBody: initialNetworkBody,
160+
opts,
161+
url,
162+
} = await resolveOptions(options as any);
127163
// Compute response type mapping once
128164
const ofetchResponseType: OfetchResponseType | undefined =
129165
mapParseAsToResponseType(opts.parseAs, opts.responseType);

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/utils.gen.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ export const buildOfetchOptions = (
318318
body: BodyInit | null | undefined,
319319
responseType: OfetchResponseType | undefined,
320320
retryOverride?: OfetchOptions['retry'],
321-
): OfetchOptions => ({
321+
): OfetchOptions =>
322+
({
322323
agent: opts.agent as OfetchOptions['agent'],
323324
body,
324325
dispatcher: opts.dispatcher as OfetchOptions['dispatcher'],
@@ -332,13 +333,13 @@ export const buildOfetchOptions = (
332333
// URL already includes query
333334
query: undefined,
334335
responseType,
335-
retry: (retryOverride ?? (opts.retry as OfetchOptions['retry'])),
336+
retry: retryOverride ?? (opts.retry as OfetchOptions['retry']),
336337
retryDelay: opts.retryDelay as OfetchOptions['retryDelay'],
337338
retryStatusCodes:
338339
opts.retryStatusCodes as OfetchOptions['retryStatusCodes'],
339340
signal: opts.signal,
340341
timeout: opts.timeout as number | undefined,
341-
} as OfetchOptions);
342+
}) as OfetchOptions;
342343

343344
/**
344345
* Parse a successful response, handling empty bodies and stream cases.
@@ -384,10 +385,20 @@ export const parseSuccess = async (
384385
case 'arrayBuffer':
385386
case 'blob':
386387
case 'formData':
387-
case 'json':
388388
case 'text':
389389
data = await (response as any)[inferredParseAs]();
390390
break;
391+
case 'json': {
392+
// Some servers return 200 with no Content-Length and empty body.
393+
// response.json() would throw; detect empty via clone().text() first.
394+
const txt = await response.clone().text();
395+
if (!txt) {
396+
data = {};
397+
} else {
398+
data = await (response as any).json();
399+
}
400+
break;
401+
}
391402
case 'stream':
392403
return response.body;
393404
}

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/client.gen.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ export const createClient = (config: Config = {}): Client => {
7878
opts.headers.delete('Content-Type');
7979
}
8080

81+
// If user provides a raw body (no serializer), adjust Content-Type sensibly.
82+
// Avoid overriding explicit user-defined headers; only correct the default JSON header.
83+
if (
84+
opts.body !== undefined &&
85+
opts.bodySerializer === null &&
86+
(opts.headers.get('Content-Type') || '').toLowerCase() ===
87+
'application/json'
88+
) {
89+
const b: unknown = opts.body;
90+
if (typeof FormData !== 'undefined' && b instanceof FormData) {
91+
// Let the runtime set proper boundary
92+
opts.headers.delete('Content-Type');
93+
} else if (
94+
typeof URLSearchParams !== 'undefined' &&
95+
b instanceof URLSearchParams
96+
) {
97+
// Set standard urlencoded content type with charset
98+
opts.headers.set(
99+
'Content-Type',
100+
'application/x-www-form-urlencoded;charset=UTF-8',
101+
);
102+
} else if (typeof Blob !== 'undefined' && b instanceof Blob) {
103+
const t = b.type?.trim();
104+
if (t) {
105+
opts.headers.set('Content-Type', t);
106+
} else {
107+
// No known type for the blob: avoid sending misleading JSON header
108+
opts.headers.delete('Content-Type');
109+
}
110+
}
111+
}
112+
81113
// Precompute network body for retries and consistent handling
82114
const networkBody = getValidRequestBody(opts) as
83115
| RequestInit['body']
@@ -116,14 +148,18 @@ export const createClient = (config: Config = {}): Client => {
116148
body: BodyInit | null | undefined,
117149
responseType: OfetchResponseType | undefined,
118150
) => {
119-
const effectiveRetry = isRepeatableBody(body) ? (opts.retry as any) : (0 as any);
151+
const effectiveRetry = isRepeatableBody(body)
152+
? (opts.retry as any)
153+
: (0 as any);
120154
return buildOfetchOptions(opts, body, responseType, effectiveRetry);
121155
};
122156

123157
const request: Client['request'] = async (options) => {
124-
const { networkBody: initialNetworkBody, opts, url } = await resolveOptions(
125-
options as any,
126-
);
158+
const {
159+
networkBody: initialNetworkBody,
160+
opts,
161+
url,
162+
} = await resolveOptions(options as any);
127163
// Compute response type mapping once
128164
const ofetchResponseType: OfetchResponseType | undefined =
129165
mapParseAsToResponseType(opts.parseAs, opts.responseType);

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/utils.gen.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ export const buildOfetchOptions = (
318318
body: BodyInit | null | undefined,
319319
responseType: OfetchResponseType | undefined,
320320
retryOverride?: OfetchOptions['retry'],
321-
): OfetchOptions => ({
321+
): OfetchOptions =>
322+
({
322323
agent: opts.agent as OfetchOptions['agent'],
323324
body,
324325
dispatcher: opts.dispatcher as OfetchOptions['dispatcher'],
@@ -332,13 +333,13 @@ export const buildOfetchOptions = (
332333
// URL already includes query
333334
query: undefined,
334335
responseType,
335-
retry: (retryOverride ?? (opts.retry as OfetchOptions['retry'])),
336+
retry: retryOverride ?? (opts.retry as OfetchOptions['retry']),
336337
retryDelay: opts.retryDelay as OfetchOptions['retryDelay'],
337338
retryStatusCodes:
338339
opts.retryStatusCodes as OfetchOptions['retryStatusCodes'],
339340
signal: opts.signal,
340341
timeout: opts.timeout as number | undefined,
341-
} as OfetchOptions);
342+
}) as OfetchOptions;
342343

343344
/**
344345
* Parse a successful response, handling empty bodies and stream cases.
@@ -384,10 +385,20 @@ export const parseSuccess = async (
384385
case 'arrayBuffer':
385386
case 'blob':
386387
case 'formData':
387-
case 'json':
388388
case 'text':
389389
data = await (response as any)[inferredParseAs]();
390390
break;
391+
case 'json': {
392+
// Some servers return 200 with no Content-Length and empty body.
393+
// response.json() would throw; detect empty via clone().text() first.
394+
const txt = await response.clone().text();
395+
if (!txt) {
396+
data = {};
397+
} else {
398+
data = await (response as any).json();
399+
}
400+
break;
401+
}
391402
case 'stream':
392403
return response.body;
393404
}

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/client.gen.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ export const createClient = (config: Config = {}): Client => {
7878
opts.headers.delete('Content-Type');
7979
}
8080

81+
// If user provides a raw body (no serializer), adjust Content-Type sensibly.
82+
// Avoid overriding explicit user-defined headers; only correct the default JSON header.
83+
if (
84+
opts.body !== undefined &&
85+
opts.bodySerializer === null &&
86+
(opts.headers.get('Content-Type') || '').toLowerCase() ===
87+
'application/json'
88+
) {
89+
const b: unknown = opts.body;
90+
if (typeof FormData !== 'undefined' && b instanceof FormData) {
91+
// Let the runtime set proper boundary
92+
opts.headers.delete('Content-Type');
93+
} else if (
94+
typeof URLSearchParams !== 'undefined' &&
95+
b instanceof URLSearchParams
96+
) {
97+
// Set standard urlencoded content type with charset
98+
opts.headers.set(
99+
'Content-Type',
100+
'application/x-www-form-urlencoded;charset=UTF-8',
101+
);
102+
} else if (typeof Blob !== 'undefined' && b instanceof Blob) {
103+
const t = b.type?.trim();
104+
if (t) {
105+
opts.headers.set('Content-Type', t);
106+
} else {
107+
// No known type for the blob: avoid sending misleading JSON header
108+
opts.headers.delete('Content-Type');
109+
}
110+
}
111+
}
112+
81113
// Precompute network body for retries and consistent handling
82114
const networkBody = getValidRequestBody(opts) as
83115
| RequestInit['body']
@@ -116,14 +148,18 @@ export const createClient = (config: Config = {}): Client => {
116148
body: BodyInit | null | undefined,
117149
responseType: OfetchResponseType | undefined,
118150
) => {
119-
const effectiveRetry = isRepeatableBody(body) ? (opts.retry as any) : (0 as any);
151+
const effectiveRetry = isRepeatableBody(body)
152+
? (opts.retry as any)
153+
: (0 as any);
120154
return buildOfetchOptions(opts, body, responseType, effectiveRetry);
121155
};
122156

123157
const request: Client['request'] = async (options) => {
124-
const { networkBody: initialNetworkBody, opts, url } = await resolveOptions(
125-
options as any,
126-
);
158+
const {
159+
networkBody: initialNetworkBody,
160+
opts,
161+
url,
162+
} = await resolveOptions(options as any);
127163
// Compute response type mapping once
128164
const ofetchResponseType: OfetchResponseType | undefined =
129165
mapParseAsToResponseType(opts.parseAs, opts.responseType);

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/utils.gen.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ export const buildOfetchOptions = (
318318
body: BodyInit | null | undefined,
319319
responseType: OfetchResponseType | undefined,
320320
retryOverride?: OfetchOptions['retry'],
321-
): OfetchOptions => ({
321+
): OfetchOptions =>
322+
({
322323
agent: opts.agent as OfetchOptions['agent'],
323324
body,
324325
dispatcher: opts.dispatcher as OfetchOptions['dispatcher'],
@@ -332,13 +333,13 @@ export const buildOfetchOptions = (
332333
// URL already includes query
333334
query: undefined,
334335
responseType,
335-
retry: (retryOverride ?? (opts.retry as OfetchOptions['retry'])),
336+
retry: retryOverride ?? (opts.retry as OfetchOptions['retry']),
336337
retryDelay: opts.retryDelay as OfetchOptions['retryDelay'],
337338
retryStatusCodes:
338339
opts.retryStatusCodes as OfetchOptions['retryStatusCodes'],
339340
signal: opts.signal,
340341
timeout: opts.timeout as number | undefined,
341-
} as OfetchOptions);
342+
}) as OfetchOptions;
342343

343344
/**
344345
* Parse a successful response, handling empty bodies and stream cases.
@@ -384,10 +385,20 @@ export const parseSuccess = async (
384385
case 'arrayBuffer':
385386
case 'blob':
386387
case 'formData':
387-
case 'json':
388388
case 'text':
389389
data = await (response as any)[inferredParseAs]();
390390
break;
391+
case 'json': {
392+
// Some servers return 200 with no Content-Length and empty body.
393+
// response.json() would throw; detect empty via clone().text() first.
394+
const txt = await response.clone().text();
395+
if (!txt) {
396+
data = {};
397+
} else {
398+
data = await (response as any).json();
399+
}
400+
break;
401+
}
391402
case 'stream':
392403
return response.body;
393404
}

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/client.gen.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ export const createClient = (config: Config = {}): Client => {
7878
opts.headers.delete('Content-Type');
7979
}
8080

81+
// If user provides a raw body (no serializer), adjust Content-Type sensibly.
82+
// Avoid overriding explicit user-defined headers; only correct the default JSON header.
83+
if (
84+
opts.body !== undefined &&
85+
opts.bodySerializer === null &&
86+
(opts.headers.get('Content-Type') || '').toLowerCase() ===
87+
'application/json'
88+
) {
89+
const b: unknown = opts.body;
90+
if (typeof FormData !== 'undefined' && b instanceof FormData) {
91+
// Let the runtime set proper boundary
92+
opts.headers.delete('Content-Type');
93+
} else if (
94+
typeof URLSearchParams !== 'undefined' &&
95+
b instanceof URLSearchParams
96+
) {
97+
// Set standard urlencoded content type with charset
98+
opts.headers.set(
99+
'Content-Type',
100+
'application/x-www-form-urlencoded;charset=UTF-8',
101+
);
102+
} else if (typeof Blob !== 'undefined' && b instanceof Blob) {
103+
const t = b.type?.trim();
104+
if (t) {
105+
opts.headers.set('Content-Type', t);
106+
} else {
107+
// No known type for the blob: avoid sending misleading JSON header
108+
opts.headers.delete('Content-Type');
109+
}
110+
}
111+
}
112+
81113
// Precompute network body for retries and consistent handling
82114
const networkBody = getValidRequestBody(opts) as
83115
| RequestInit['body']
@@ -116,14 +148,18 @@ export const createClient = (config: Config = {}): Client => {
116148
body: BodyInit | null | undefined,
117149
responseType: OfetchResponseType | undefined,
118150
) => {
119-
const effectiveRetry = isRepeatableBody(body) ? (opts.retry as any) : (0 as any);
151+
const effectiveRetry = isRepeatableBody(body)
152+
? (opts.retry as any)
153+
: (0 as any);
120154
return buildOfetchOptions(opts, body, responseType, effectiveRetry);
121155
};
122156

123157
const request: Client['request'] = async (options) => {
124-
const { networkBody: initialNetworkBody, opts, url } = await resolveOptions(
125-
options as any,
126-
);
158+
const {
159+
networkBody: initialNetworkBody,
160+
opts,
161+
url,
162+
} = await resolveOptions(options as any);
127163
// Compute response type mapping once
128164
const ofetchResponseType: OfetchResponseType | undefined =
129165
mapParseAsToResponseType(opts.parseAs, opts.responseType);

0 commit comments

Comments
 (0)