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
1 change: 1 addition & 0 deletions examples/generated-rq/1password-connect/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/adyen-checkout/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/adyen-legal-entity/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/canada_holidays/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/devto/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedApiKey ? { 'api-key': resolvedApiKey } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/exchangerate/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/open-meteo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/openai/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/petstore-3.0/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/redocly-museum/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/resend/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/spotify/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated-rq/twitter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/1password-connect/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/adyen-checkout/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated/adyen-legal-entity/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated/canada_holidays/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated/devto/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedApiKey ? { 'api-key': resolvedApiKey } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/exchangerate/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated/open-meteo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
1 change: 1 addition & 0 deletions examples/generated/openai/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/petstore-3.0/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/redocly-museum/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedBasic
Expand Down
1 change: 1 addition & 0 deletions examples/generated/resend/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/spotify/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
1 change: 1 addition & 0 deletions examples/generated/twitter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
Accept: 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
...(resolvedToken ? { Authorization: `Bearer ${resolvedToken}` } : {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function _request(
let _init: RequestInit = {
method,
headers: {
'Accept': 'application/json',
...(opts.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
...headers,
},
Expand Down
7 changes: 7 additions & 0 deletions packages/openapi-zod-ts/src/plugins/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,11 @@ function emitContentTypeHeader(lines: string[], hasFormUrlencoded: boolean): voi
}
}

/** Emits the Accept: application/json header as the first entry in the headers block. */
function emitAcceptHeader(lines: string[]): void {
lines.push(` 'Accept': 'application/json',`)
}

/** Emits the body field in the fetch options for JSON or form-urlencoded body. */
function emitBodyField(lines: string[], hasFormUrlencoded: boolean): void {
if (hasFormUrlencoded) {
Expand Down Expand Up @@ -1101,6 +1106,7 @@ function emitRequestFunction(
lines.push(` method,`)
if (features.hasCookieAuth) lines.push(` credentials,`)
lines.push(` headers: {`)
emitAcceptHeader(lines)
emitContentTypeHeader(lines, features.hasFormUrlencoded)
lines.push(` ...headers,`)
emitAuthHeaderSpreads(lines, hasToken, hasBasic, auth.apiKeyHeaderNames)
Expand Down Expand Up @@ -1142,6 +1148,7 @@ function emitRequestFormFunction(
lines.push(` method,`)
if (features.hasCookieAuth) lines.push(` credentials,`)
lines.push(` headers: {`)
emitAcceptHeader(lines)
lines.push(` ...headers,`)
emitAuthHeaderSpreads(lines, hasToken, hasBasic, auth.apiKeyHeaderNames)
if (features.hasHeaderParams) lines.push(` ...opts.extraHeaders,`)
Expand Down
Loading