Skip to content
Officialv5.5.7MITkubb >=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
469.3K/ mo
Stars
8
Bundle size
287.9 kB
Updated
2h ago

Generate typed API calls for your own HTTP client.

Use it for signed requests, a shared client, or an existing HTTP layer. Write your client to define the required exports. The generated code has no Fetch, Axios, or Kubb runtime dependency.

Installation

bun add -d @kubb/plugin-client

Or run kubb add plugin-client to install the version the Kubb registry pins and add pluginClient() to kubb.config.ts.

Dependencies

  • Add pluginTs for operation types.
  • Add pluginZod when validator is set. Generation fails without it.

Set importPath to your client module. No HTTP client package is required.

Example

import { defineConfig } from 'kubb/config'
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