Skip to content
Client logo

Client

Officialv6.0.4

@kubb/plugin-client

kubb add plugin-client

Options

Pass these options to pluginClient(). Shared options link to Shared plugin options.

Options overview

OptionPurposeDefault
importPathImport specifier of your client module.Required
returnTypeWhat a generated function resolves to.'plain'
throwOnErrorDefaultthrowOnError value each call passes to your client.true
validatorZod schemas to pass to your client.false
outputWhere files are written.{ path: 'clients', barrel: { type: 'named' } }
groupSplit output by tag or path.None
includeKeep only operations that match.None
excludeSkip operations that match.[]
overrideApply different options per pattern, except returnType and throwOnErrorDefault.[]
resolverCustomize generated names and file paths.resolverClient
macrosRewrite AST nodes before printing.[], run after the built-in client macros

Option details

importPath

Import specifier of your client module, written into every generated import as given. It must resolve from the generated file: use a relative path, a package name, or an alias.

Typestring
Requiredtrue
pluginClient({ importPath: '../../../client' }) // from src/gen/clients/<tag>/ to src/client.ts
pluginClient({ importPath: '@my-org/api-client' }) // a package

Without group, files sit one folder higher, so use ../../client. Write your client lists the exports the module needs.

returnType

What a generated function resolves to.

Type'plain' | 'full' | 'data'
Requiredfalse
Default'plain'
'plain'
Default. Returns what your client returns.
'full'
The caller can await the call or call .unwrap(). Your module must export withUnwrap, resolveThrowOnError, and the Unwrappable type.
'data'
Resolves to the body when throwOnError is true, and to the full result when it is false. Your module must export unwrapResult, resolveThrowOnError, and the UnwrappedResult type.

You can re-export these helpers from @kubb/plugin-client/templates/core.ts.

pluginClient({ importPath: '../../client', returnType: 'full' })
// with integerType: 'number' on the adapter
// const pet = await getPetById({ path: { petId: 1 } }).unwrap()

throwOnErrorDefault

The throwOnError value every generated function passes to your client, unless the call sets its own. Your client decides what the flag does.

Typeboolean
Requiredfalse
Defaulttrue

validator

Passes Zod schemas from @kubb/plugin-zod to your client on config.validator. Your client runs them. See Validate requests and responses.

Typefalse | 'zod' | { request?: 'zod'; params?: 'zod'; response?: 'zod' }
Requiredfalse
Defaultfalse
false
Default. Passes nothing.
'zod'
Passes the response and error schemas.
{ request?: 'zod', params?: 'zod', response?: 'zod' }
Opts in per slot: request for the body, params for the path, query, header, and cookie schemas, and response for the response and error schemas. params also imports toHeadersStandardSchema from your module.
Add pluginZod() to plugins when validator is set, or generation stops with an error.