- Downloads
- 441k/ mo
- Stars
- 8
- Bundle size
- 280.9 kB
- Updated
- today
@kubb/plugin-client turns each OpenAPI operation into a typed async function that calls a client module you write. Kubb generates the operations and their types. It does not choose a transport and does not copy a runtime into your project, so the generated code has no Fetch, Axios, or Kubb dependency.
Use it when @kubb/plugin-fetch or @kubb/plugin-axios do more than you want, for example when you sign requests, share one client across many generated packages, or keep an existing HTTP layer.
From your spec, the plugin gives you:
- Typed functions per operation with grouped
path,query,headers, andbody. - A
securitylist on each call that tells your client which auth the operation needs. - A per-call
clientoverride, so one function can use a different client. - Optional validation schemas from
@kubb/plugin-zod, passed to your client.
Each function takes one grouped options object ({ path, query, headers, body }) and returns whatever your client returns, typed as your RequestResult. See write your client for the exports the module needs.
Installation
bun add -d @kubb/plugin-clientpnpm add -D @kubb/plugin-clientnpm install --save-dev @kubb/plugin-clientyarn add -D @kubb/plugin-clientDependencies
The plugin needs @kubb/plugin-ts for the operation types. It needs @kubb/plugin-zod only when validator is set, and generation stops with an error if @kubb/plugin-zod is missing.
Important
There is no HTTP client to install. The generated functions call the module you point importPath at.
Example
import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginClient } from '@kubb/plugin-client'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [
pluginTs(),
pluginClient({
output: { path: 'clients', mode: 'directory', barrel: { type: 'named' } },
group: { type: 'tag' },
// resolved from each generated file: src/gen/clients/<tag>/ to src/client.ts
importPath: '../../../client',
}),
],
})