Client
Officialv6.2.0@kubb/plugin-client
Options
Pass these options to pluginClient(). Shared options link to Shared plugin options.
Options overview
| Option | Purpose | Default |
|---|---|---|
importPath | Import specifier of your client module. | Required |
returnType | What a generated function resolves to. | 'plain' |
throwOnErrorDefault | throwOnError value each call passes to your client. | true |
validator | Zod or Valibot schemas to pass to your client. | false |
auth | How generated functions take auth. | None |
auth.mode | Optional auth, or required when a token is needed. | 'optional' |
output | Where files are written. | { path: 'clients', barrel: { type: 'named' } } |
group | Split output by tag or path. | None |
include | Keep only operations that match. | None |
exclude | Skip operations that match. | [] |
override | Apply different options per pattern, except returnType and throwOnErrorDefault. | [] |
resolver | Customize generated names and file paths. | resolverClient |
macros | Rewrite 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.
| Type | string |
| Required | true |
pluginClient({ importPath: '../../../client' }) // from src/gen/clients/<tag>/ to src/client.ts
pluginClient({ importPath: '@my-org/api-client' }) // a packageWithout 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' |
| Required | false |
| Default | 'plain' |
client returns.await the call or call .unwrap(). Your module must export withUnwrap, resolveThrowOnError, and the Unwrappable type.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.
| Type | boolean |
| Required | false |
| Default | true |
validator
Passes Zod schemas from @kubb/plugin-zod, or Valibot schemas from @kubb/plugin-valibot, to your client on config.validator. Your client runs them. See Validate requests and responses.
| Type | false | 'zod' | 'valibot' | { request?; params?; response? } |
| Required | false |
| Default | false |
@kubb/plugin-zod.@kubb/plugin-valibot.'zod' or 'valibot' as the value. Use one library for every 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.plugins when validator is set: pluginZod() for 'zod', pluginValibot() for 'valibot'. Without it, generation stops with an error.auth
Sets how generated functions take the auth option.
| Type | { mode?: 'optional' | 'required' } |
| Required | false |
auth as an optional option. Use it with the query-hook plugins, which pass a partial config to the function.auth as a required option, so a missing token fails at compile time. An operation without security, or one that allows {} (anonymous access), keeps auth optional.With mode: 'required', the required type is read from the auth key of your module's Options, so that type must have one.
// with pluginClient({ importPath: '../client', auth: { mode: 'required' } })
await addPet({ body, auth: () => getToken() })
await addPet({ body }) // Type error: `auth` is missing