Skip to content
Client

Client

Officialv5.5.8

@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
outputWhere files are written: path, mode, barrel, banner, footer.{ path: 'clients', barrel: { type: 'named' } }
groupSplit output by tag or path: type, name.None
throwOnErrorDefaultDefault throwOnError value passed to your client.true
validatorPass Zod schemas to your client.false
includeKeep only operations that match.None
excludeSkip operations that match.[]
overrideApply different options per pattern.[]
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. The plugin writes it into every generated import exactly as given, so it must resolve from the generated file. Use a relative path, a package name, or an alias.

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

With group: { type: 'tag' } and output.path: 'clients', a generated file sits in src/gen/clients/<tag>/, so ../../../client points at src/client.ts. Without group it is ../../client.

The module must export client, plus the Options and RequestResult types. See write your client.

throwOnErrorDefault

Default for the throwOnError field that every generated function passes to your client. A call that sets throwOnError itself wins. Your client decides what the flag does: the example client throws on a non-2xx status when it is true and returns the error as a value when it is false.

Typeboolean
Requiredfalse
Defaulttrue

The setting applies to the whole plugin, so you cannot set it in override.

validator

Passes Zod schemas from @kubb/plugin-zod to your client on config.validator. The plugin does not run the schemas. Your client reads config.validator and runs them. See validate requests and responses.

Typefalse | 'zod' | { request?: 'zod'; response?: 'zod' }
Requiredfalse
Defaultfalse
false
Default value. Passes nothing.
'zod'
Passes the response and error schemas.
{ request?: 'zod', response?: 'zod' }
Opts in per direction.
Add pluginZod() to the plugins list when validator is set. Generation stops with an error if it is missing.