Skip to content
Officialv5.5.4MITkubb >=5.0.0node >=22

@kubb/plugin-client

Generates typed operation functions from your OpenAPI spec that call a client module you own, so you decide the transport, auth, and error handling.

api-clienthttp-clientcodegenopenapi
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
446.4K/ mo
Stars
8
Bundle size
280.9 kB
Updated
1d ago

@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, and body.
  • A security list on each call that tells your client which auth the operation needs.
  • A per-call client override, 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-client

Dependencies

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.

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',
    }),
  ],
})

See also