Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/lazy-plugs-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kubb/plugin-fetch': patch
'@kubb/plugin-axios': patch
---

Fix the generated client failing to type-check in Node-only projects (`@types/node` without the `dom` lib). The generated `.kubb/client.ts` and `.kubb/serializers.ts` no longer reference the global `BodyInit` name, which such a project never declares. They now use a local `RequestBody` type derived from `RequestInit['body']`.
12 changes: 9 additions & 3 deletions examples/advanced/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
12 changes: 9 additions & 3 deletions examples/axios/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
10 changes: 8 additions & 2 deletions examples/fetch/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { type StandardSchemaValidator, validateStandardSchema } from './standard
*/
export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226'

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The success members of a per-status responses record.
*/
Expand Down Expand Up @@ -124,7 +130,7 @@ export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T
/**
* Serializes a request body for a single media type, registered per content type as a codec's `serialize` to encode formats the default serializer does not handle.
*/
export type ContentBodySerializer = (body: unknown, contentType?: string) => BodyInit | undefined
export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined

/**
* A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
Expand Down Expand Up @@ -238,7 +244,7 @@ export type ResolvedRequest = {
url: string
method: string
headers: Record<string, string>
body?: BodyInit
body?: RequestBody
signal?: AbortSignal
credentials?: RequestCredentials
options?: FetchOptions
Expand Down
12 changes: 9 additions & 3 deletions examples/fetch/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
12 changes: 9 additions & 3 deletions examples/mcp/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
10 changes: 8 additions & 2 deletions examples/react-query/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { type StandardSchemaValidator, validateStandardSchema } from './standard
*/
export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226'

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The success members of a per-status responses record.
*/
Expand Down Expand Up @@ -124,7 +130,7 @@ export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T
/**
* Serializes a request body for a single media type, registered per content type as a codec's `serialize` to encode formats the default serializer does not handle.
*/
export type ContentBodySerializer = (body: unknown, contentType?: string) => BodyInit | undefined
export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined

/**
* A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
Expand Down Expand Up @@ -238,7 +244,7 @@ export type ResolvedRequest = {
url: string
method: string
headers: Record<string, string>
body?: BodyInit
body?: RequestBody
signal?: AbortSignal
credentials?: RequestCredentials
options?: FetchOptions
Expand Down
12 changes: 9 additions & 3 deletions examples/react-query/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
10 changes: 8 additions & 2 deletions examples/sdk/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { type StandardSchemaValidator, validateStandardSchema } from './standard
*/
export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226'

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The success members of a per-status responses record.
*/
Expand Down Expand Up @@ -124,7 +130,7 @@ export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T
/**
* Serializes a request body for a single media type, registered per content type as a codec's `serialize` to encode formats the default serializer does not handle.
*/
export type ContentBodySerializer = (body: unknown, contentType?: string) => BodyInit | undefined
export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined

/**
* A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
Expand Down Expand Up @@ -238,7 +244,7 @@ export type ResolvedRequest = {
url: string
method: string
headers: Record<string, string>
body?: BodyInit
body?: RequestBody
signal?: AbortSignal
credentials?: RequestCredentials
options?: FetchOptions
Expand Down
12 changes: 9 additions & 3 deletions examples/sdk/src/gen/.kubb/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type HeaderValue = string | number | boolean | null | undefined | object
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
Expand Down Expand Up @@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
* the per-property OpenAPI `encoding` metadata for form bodies.
*/
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => BodyInit | undefined
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined

/**
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
Expand Down Expand Up @@ -111,7 +117,7 @@ export type Styles = {
body?: Record<string, BodyEncoding>
}

function isFormBody(body: unknown): body is BodyInit {
function isFormBody(body: unknown): body is RequestBody {
return (
body instanceof FormData ||
body instanceof URLSearchParams ||
Expand Down Expand Up @@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
*/
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
if (body === undefined || body === null) return undefined
if (isFormBody(body)) return body as BodyInit
if (isFormBody(body)) return body as RequestBody
if (contentType?.includes('multipart/form-data')) {
const formData = new FormData()
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
Expand Down
10 changes: 8 additions & 2 deletions examples/simple-single/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { type StandardSchemaValidator, validateStandardSchema } from './standard
*/
export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226'

/**
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
*/
export type RequestBody = NonNullable<RequestInit['body']>

/**
* The success members of a per-status responses record.
*/
Expand Down Expand Up @@ -124,7 +130,7 @@ export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T
/**
* Serializes a request body for a single media type, registered per content type as a codec's `serialize` to encode formats the default serializer does not handle.
*/
export type ContentBodySerializer = (body: unknown, contentType?: string) => BodyInit | undefined
export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined

/**
* A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
Expand Down Expand Up @@ -238,7 +244,7 @@ export type ResolvedRequest = {
url: string
method: string
headers: Record<string, string>
body?: BodyInit
body?: RequestBody
signal?: AbortSignal
credentials?: RequestCredentials
options?: FetchOptions
Expand Down
Loading
Loading