### Install dependencies Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/community/contributing.md Install all necessary project dependencies using pnpm. ```shell pnpm install ``` -------------------------------- ### Install @kubb/plugin-react-query Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-react-query/index.md Install the plugin using your preferred package manager. ```bun bun add -d @kubb/plugin-react-query ``` ```pnpm pnpm add -D @kubb/plugin-react-query ``` ```npm npm install --save-dev @kubb/plugin-react-query ``` ```yarn yarn add -D @kubb/plugin-react-query ``` -------------------------------- ### Install @kubb/plugin-axios Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-axios/index.md Installation commands for various package managers. ```shell bun add -d @kubb/plugin-axios ``` ```shell pnpm add -D @kubb/plugin-axios ``` ```shell npm install --save-dev @kubb/plugin-axios ``` ```shell yarn add -D @kubb/plugin-axios ``` -------------------------------- ### Run kubb init Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Execute the interactive setup wizard in the project directory. ```shell npx kubb init ``` -------------------------------- ### Install @kubb/plugin-swr Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-swr/index.md Install the plugin using your preferred package manager. ```bun bun add -d @kubb/plugin-swr ``` ```pnpm pnpm add -D @kubb/plugin-swr ``` ```npm npm install --save-dev @kubb/plugin-swr ``` ```yarn yarn add -D @kubb/plugin-swr ``` -------------------------------- ### Run Context7 interactive setup Source: https://context7.com/kubb-labs/docs/llms.txt Execute the interactive setup command in your terminal to connect Context7 to your AI assistant. ```shell npx ctx7 setup ``` -------------------------------- ### Install v5 plugins Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/migration.md Install the required v5 plugin packages using your preferred package manager. ```shell bun add -d @kubb/plugin-ts@5.0.0 @kubb/plugin-zod@5.0.0 @kubb/plugin-axios@5.0.0 @kubb/plugin-fetch@5.0.0 \ @kubb/plugin-react-query@5.0.0 @kubb/plugin-vue-query@5.0.0 @kubb/plugin-swr@5.0.0 \ @kubb/plugin-faker@5.0.0 @kubb/plugin-msw@5.0.0 \ @kubb/plugin-mcp@5.0.0 @kubb/plugin-cypress@5.0.0 @kubb/plugin-redoc@5.0.0 ``` ```shell pnpm add -D @kubb/plugin-ts@5.0.0 @kubb/plugin-zod@5.0.0 @kubb/plugin-axios@5.0.0 @kubb/plugin-fetch@5.0.0 \ @kubb/plugin-react-query@5.0.0 @kubb/plugin-vue-query@5.0.0 @kubb/plugin-swr@5.0.0 \ @kubb/plugin-faker@5.0.0 @kubb/plugin-msw@5.0.0 \ @kubb/plugin-mcp@5.0.0 @kubb/plugin-cypress@5.0.0 @kubb/plugin-redoc@5.0.0 ``` ```shell npm install -D @kubb/plugin-ts@5.0.0 @kubb/plugin-zod@5.0.0 @kubb/plugin-axios@5.0.0 @kubb/plugin-fetch@5.0.0 \ @kubb/plugin-react-query@5.0.0 @kubb/plugin-vue-query@5.0.0 @kubb/plugin-swr@5.0.0 \ @kubb/plugin-faker@5.0.0 @kubb/plugin-msw@5.0.0 \ @kubb/plugin-mcp@5.0.0 @kubb/plugin-cypress@5.0.0 @kubb/plugin-redoc@5.0.0 ``` ```shell yarn add -D @kubb/plugin-ts@5.0.0 @kubb/plugin-zod@5.0.0 @kubb/plugin-axios@5.0.0 @kubb/plugin-fetch@5.0.0 \ @kubb/plugin-react-query@5.0.0 @kubb/plugin-vue-query@5.0.0 @kubb/plugin-swr@5.0.0 \ @kubb/plugin-faker@5.0.0 @kubb/plugin-msw@5.0.0 \ @kubb/plugin-mcp@5.0.0 @kubb/plugin-cypress@5.0.0 @kubb/plugin-redoc@5.0.0 ``` -------------------------------- ### Install @kubb/plugin-zod Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-zod/index.md Install the plugin using your preferred package manager. ```bun bun add -d @kubb/plugin-zod ``` ```pnpm pnpm add -D @kubb/plugin-zod ``` ```npm npm install --save-dev @kubb/plugin-zod ``` ```yarn yarn add -D @kubb/plugin-zod ``` -------------------------------- ### Install @kubb/plugin-fetch Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-fetch/index.md Install the plugin as a development dependency using your preferred package manager. ```bun bun add -d @kubb/plugin-fetch ``` ```pnpm pnpm add -D @kubb/plugin-fetch ``` ```npm npm install --save-dev @kubb/plugin-fetch ``` ```yarn yarn add -D @kubb/plugin-fetch ``` -------------------------------- ### Install @kubb/plugin-vue-query Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-vue-query/index.md Commands to install the plugin using various package managers. ```shell bun add -d @kubb/plugin-vue-query ``` ```shell pnpm add -D @kubb/plugin-vue-query ``` ```shell npm install --save-dev @kubb/plugin-vue-query ``` ```shell yarn add -D @kubb/plugin-vue-query ``` -------------------------------- ### Install Kubb CLI Source: https://github.com/kubb-labs/docs/blob/main/blog/claude-code-plugin.md Prerequisite installation of the Kubb CLI either locally in the project or globally. ```shell npm install -D kubb # in the project npm install -g kubb # or globally ``` -------------------------------- ### Legacy configuration example Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-legacy-input.md Example of a v4 configuration that triggers the KUBB_LEGACY_INPUT diagnostic. ```typescript import { defineConfig } from 'kubb/config' export default defineConfig({ // the v4 wrapper, no longer accepted input: { path: './petStore.yaml' }, output: { path: './src/gen' }, plugins: [/* ... */], }) ``` -------------------------------- ### Install @kubb/plugin-mcp Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-mcp/index.md Install the plugin using your preferred package manager. ```bun bun add -d @kubb/plugin-mcp ``` ```pnpm pnpm add -D @kubb/plugin-mcp ``` ```npm npm install --save-dev @kubb/plugin-mcp ``` ```yarn yarn add -D @kubb/plugin-mcp ``` -------------------------------- ### Kubb init command output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Example output showing the interactive wizard flow. ```terminal command: npx kubb init output: - ◆ Kubb Init - ◇ Detected package manager: pnpm - ◇ Where is your OpenAPI specification located? - │ ./openapi.yaml - ◇ Where should the generated files be output? - │ ./src/gen - ◇ Select plugins to use: - │ plugin-ts, plugin-axios, plugin-zod - ◇ Installed 4 packages - ◇ Created kubb.config.ts - ◇ All set! Run `npx kubb generate` to start generating. ``` -------------------------------- ### Install @kubb/plugin-msw Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-msw/index.md Install the plugin as a development dependency using your preferred package manager. ```bun bun add -d @kubb/plugin-msw ``` ```pnpm pnpm add -D @kubb/plugin-msw ``` ```npm npm install --save-dev @kubb/plugin-msw ``` ```yarn yarn add -D @kubb/plugin-msw ``` -------------------------------- ### Install the Kubb Claude Code plugin Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/claude.md Add the Kubb repository to the marketplace and install the plugin within the Claude Code environment. ```shell /plugin marketplace add kubb-labs/kubb /plugin install kubb@kubb ``` -------------------------------- ### Install Kubb dependency Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/claude.md Install the Kubb CLI as a development dependency in your project. ```shell npm install -D kubb ``` -------------------------------- ### Instantiate and use a PetClient Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-axios/reference/options.md Example of creating a class-based SDK client and calling an operation method. ```typescript import { PetClient } from './src/gen/clients/petClient' const pet = new PetClient({ baseURL: 'https://petstore.swagger.io/v2' }) const { data } = await pet.getPetById({ path: { petId: 1 } }) ``` -------------------------------- ### Define output folder structure Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/migration.md Example of output folder naming convention changes. ```text v4: src/gen/clients/petController/ → v5: src/gen/clients/pet/ ``` -------------------------------- ### Example verbose output summary Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-performance.md A representation of the terminal output showing plugin generation timings. ```shell Plugins 3 passed (3) Files 12 generated Duration 81ms Output ./src/gen Timings • plugin-react-query █ 42ms • plugin-zod █ 21ms • plugin-ts █ 18ms ``` -------------------------------- ### Install Kubb Dependencies Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/getting-started/introduction.md Install the core Kubb package and required plugins via npm. ```shell npm install -D kubb @kubb/plugin-ts @kubb/plugin-zod ``` -------------------------------- ### Invalid configuration example Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-input-required.md An example of a Kubb configuration missing the required input property. ```typescript import { defineConfig } from 'kubb/config' export default defineConfig({ // input is missing output: { path: './src/gen' }, plugins: [/* ... */], }) ``` -------------------------------- ### Run plugin from local directory Source: https://github.com/kubb-labs/docs/blob/main/blog/claude-code-plugin.md Command to test the plugin locally from a specific directory before marketplace installation. ```shell claude --plugin-dir ./tools/claude ``` -------------------------------- ### Install @kubb/adapter-oas Source: https://github.com/kubb-labs/docs/blob/main/adapters/adapter-oas/index.md Add the adapter as a development dependency using your preferred package manager. ```bun bun add -d @kubb/adapter-oas ``` ```pnpm pnpm add -D @kubb/adapter-oas ``` ```npm npm install --save-dev @kubb/adapter-oas ``` ```yarn yarn add -D @kubb/adapter-oas ``` -------------------------------- ### Install @kubb/plugin-cypress Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-cypress/index.md Add the plugin as a development dependency using your preferred package manager. ```bun bun add -d @kubb/plugin-cypress ``` ```pnpm pnpm add -D @kubb/plugin-cypress ``` ```npm npm install --save-dev @kubb/plugin-cypress ``` ```yarn yarn add -D @kubb/plugin-cypress ``` -------------------------------- ### Install @kubb/plugin-ts Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-ts/index.md Add the plugin to your project using your preferred package manager. ```bun bun add -d @kubb/plugin-ts ``` ```pnpm pnpm add -D @kubb/plugin-ts ``` ```npm npm install --save-dev @kubb/plugin-ts ``` ```yarn yarn add -D @kubb/plugin-ts ``` -------------------------------- ### Install @kubb/plugin-redoc Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-redoc/index.md Add the plugin as a development dependency using your preferred package manager. ```bun bun add -d @kubb/plugin-redoc ``` ```pnpm pnpm add -D @kubb/plugin-redoc ``` ```npm npm install --save-dev @kubb/plugin-redoc ``` ```yarn yarn add -D @kubb/plugin-redoc ``` -------------------------------- ### Install Kubb plugins Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/getting-started/installation.md Install specific Kubb plugins as development dependencies using your preferred package manager. ```shell bun add -d @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-react-query ``` ```shell pnpm add -D @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-react-query ``` ```shell npm install --save-dev @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-react-query ``` ```shell yarn add -D @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-react-query ``` -------------------------------- ### Start the MCP server Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/mcp.md Run the Kubb MCP server using the stdio transport. ```shell kubb mcp ``` -------------------------------- ### Configure kubb.config.ts Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-axios/index.md Example configuration for the Kubb CLI to include the axios plugin. ```typescript import { defineConfig } from 'kubb' import { pluginTs } from '@kubb/plugin-ts' import { pluginAxios } from '@kubb/plugin-axios' export default defineConfig({ input: './petStore.yaml', output: { path: './src/gen' }, plugins: [ pluginTs(), pluginAxios({ output: { path: 'clients', mode: 'directory', barrel: { type: 'named' } }, baseURL: 'https://petstore.swagger.io/v2', group: { type: 'tag', name: ({ group }) => `${group}Service`, }, }), ], }) ``` -------------------------------- ### kubb studio command output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/studio.md Example output showing the status of permissions when running the studio command. ```terminal command: kubb studio output: - ✘ write generated files - ✘ edit kubb.config.ts - ✘ use a Studio spec - ✘ run formatter, linter, postGenerate ``` -------------------------------- ### Install @kubb/plugin-faker Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-faker/index.md Add the plugin as a development dependency using your preferred package manager. ```bun bun add -d @kubb/plugin-faker ``` ```pnpm pnpm add -D @kubb/plugin-faker ``` ```npm npm install --save-dev @kubb/plugin-faker ``` ```yarn yarn add -D @kubb/plugin-faker ``` -------------------------------- ### Start the generated MCP server Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-mcp/recipes/a-working-mcp-server-from-a-spec.md Invoke the startServer function exported by the generated server module. ```typescript import { startServer } from './src/gen/mcp/server' await startServer() ``` -------------------------------- ### Configure Kubb with plugin-axios Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-axios/recipes/build-a-url-without-sending.md Setup the Kubb configuration file to include the axios plugin. ```typescript import { defineConfig } from 'kubb/config' import { pluginTs } from '@kubb/plugin-ts' import { pluginAxios } from '@kubb/plugin-axios' export default defineConfig({ input: './petStore.yaml', output: { path: './src/gen', clean: true }, plugins: [ pluginTs(), pluginAxios(), ], }) ``` -------------------------------- ### Exporting generated handlers Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-msw/reference/options.md Example of a generated handlers.ts file that re-exports all handlers for use in MSW setup. ```typescript import { getPetHandler } from './getPetHandler' import { addPetHandler } from './addPetHandler' export const handlers = [getPetHandler(), addPetHandler()] as const ``` -------------------------------- ### Initialize Kubb project Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/getting-started/installation.md Run the interactive wizard to automatically detect settings and generate a configuration file. ```shell npx kubb init ``` -------------------------------- ### Initialize and start the MCP server Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/going-further/claude-mcp-plugin.md Sets up the McpServer instance, registers tools, and connects to the stdio transport. ```typescript import { McpServer } from '@modelcontextprotocol/sdk/server/mcp' import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio' import { addPetHandler } from './addPet' import { addPetBodySchema, addPetStatus200Schema } from '../zod/addPetSchema' export function getServer() { const server = new McpServer({ name: 'Swagger PetStore - OpenAPI 3.0', version: '1.0.11', }) server.registerTool( 'addPet', { title: 'Add a new pet to the store', description: 'Add a new pet to the store', outputSchema: { data: addPetStatus200Schema }, inputSchema: { body: addPetBodySchema }, }, async ({ body }, request) => { return addPetHandler({ body }, request) }, ) return server } export const server = getServer() export async function startServer() { try { const transport = new StdioServerTransport() await server.connect(transport) } catch (error) { console.error('Failed to start server:', error) process.exit(1) } } startServer() ``` -------------------------------- ### Run kubb init in dry run mode Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Preview the wizard actions without installing packages or writing configuration files. ```shell npx kubb init --yes --dryRun ``` -------------------------------- ### Run kubb init with partial flags Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Provide specific plugins while still being prompted for other configuration values. ```shell npx kubb init --plugins plugin-ts,plugin-axios,plugin-react-query ``` -------------------------------- ### Start Kubb Studio Source: https://github.com/kubb-labs/docs/blob/main/blog/kubb-studio.md Run this command in your terminal to initiate the connection between your local project and the Kubb Studio browser interface. ```shell kubb studio ``` -------------------------------- ### Run kubb init with specific configuration Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Bypass prompts for input, output, and plugins by providing flags directly. ```shell npx kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod ``` -------------------------------- ### Install @kubb/plugin-barrel Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-barrel/index.md Commands to install the plugin as a development dependency using various package managers. ```bun bun add -d @kubb/plugin-barrel ``` ```pnpm pnpm add -D @kubb/plugin-barrel ``` ```npm npm install --save-dev @kubb/plugin-barrel ``` ```yarn yarn add -D @kubb/plugin-barrel ``` -------------------------------- ### Prompting AI with full documentation Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/llmstxt.md Use the full documentation file to provide comprehensive context for AI queries. ```text Read https://kubb.dev/llms-full.txt and answer questions about Kubb. ``` -------------------------------- ### KubbPluginSetupContext Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/kit/plugins.md Methods available within the 'kubb:plugin:setup' lifecycle hook to register plugin functionality. ```APIDOC ## KubbPluginSetupContext Methods ### Description Methods provided to the `kubb:plugin:setup` hook to configure generators, resolvers, macros, and file injection. ### Methods - **addGenerator(...generators: Array)** - Register generators for the plugin. - **setResolver(resolver: ResolverPatch | Resolver)** - Define or override file naming logic. - **addMacro(macro: Macro)** - Register a macro for AST node rewriting. - **setMacros(macros: Array)** - Replace existing macros with a new set. - **setOptions(options: ResolvedOptions)** - Define resolved options for generators. - **injectFile(file: UserFileNode)** - Manually inject a file into the build output. ### Properties - **config** (Config) - The resolved build configuration. - **options** (TOptions) - The plugin-specific options provided by the user. ``` -------------------------------- ### OpenAPI Schema Deprecation Example Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-deprecated.md An example of an OpenAPI component schema marked with deprecated: true. ```yaml components: schemas: Pet: type: object deprecated: true properties: id: type: string ``` -------------------------------- ### Install Kubb as a dev dependency Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/integrations/index.md Install the kubb package as a development dependency using your preferred package manager. ```shell bun add -d kubb ``` ```shell pnpm add -D kubb ``` ```shell npm install --save-dev kubb ``` ```shell yarn add -D kubb ``` -------------------------------- ### Run Kubb Studio with specific permissions Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/integrations/studio.md Grant specific permissions like --allowWrite and --allowExec when starting the Studio session to enable file writing and process execution. ```shell kubb studio --allowWrite --allowExec ``` -------------------------------- ### Install Kubb MCP dependencies Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/going-further/claude-mcp-plugin.md Install the required Kubb core and plugins using your preferred package manager. ```bun bun add -d kubb @kubb/plugin-ts @kubb/plugin-zod @kubb/plugin-axios @kubb/plugin-mcp ``` ```pnpm pnpm add -D kubb @kubb/plugin-ts @kubb/plugin-zod @kubb/plugin-axios @kubb/plugin-mcp ``` ```npm npm install --save-dev kubb @kubb/plugin-ts @kubb/plugin-zod @kubb/plugin-axios @kubb/plugin-mcp ``` ```yarn yarn add -D kubb @kubb/plugin-ts @kubb/plugin-zod @kubb/plugin-axios @kubb/plugin-mcp ``` -------------------------------- ### Generated type output example Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-ts/recipes/prefix-every-generated-type-name.md Example of a generated type file where all referenced types include the 'Api' prefix. ```typescript import type { ApiCat } from './Cat' import type { ApiCategory } from './Category' import type { ApiDog } from './Dog' import type { ApiTag } from './Tag' export type ApiPet = (((ApiDog & { readonly type: "dog"; }) | (ApiCat & { readonly type: "cat"; })) & { id?: bigint; name: string; category?: ApiCategory; }); ``` -------------------------------- ### Prompting AI with documentation index Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/llmstxt.md Use the index file for models with limited context windows to fetch specific documentation pages as needed. ```text Use https://kubb.dev/llms.txt to find relevant pages, then read them. ``` -------------------------------- ### Install @kubb/parser-ts Source: https://github.com/kubb-labs/docs/blob/main/parsers/parser-ts/index.md Add the parser package as a development dependency to your project. ```bun bun add -d @kubb/parser-ts ``` ```pnpm pnpm add -D @kubb/parser-ts ``` ```npm npm install --save-dev @kubb/parser-ts ``` ```yarn yarn add -D @kubb/parser-ts ``` -------------------------------- ### Common kubb studio usage examples Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/studio.md Various ways to invoke the studio command, including permission flags, authentication, and self-hosted URLs. ```shell kubb studio # connect read-only kubb studio --allowWrite --allowExec # write files, run the formatter and linter kubb studio login # connect without opening a session kubb studio logout # disconnect this machine kubb studio --url http://localhost:3000 # self-hosted Studio ``` -------------------------------- ### Run kubb init with defaults Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/init.md Skip all interactive prompts by using default values. ```shell npx kubb init --yes ``` -------------------------------- ### Registering generators and injecting files in a Kubb plugin Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/going-further/creating-plugins.md Demonstrates using the setup context to register a generator and inject both raw and static files into the build output. ```typescript import { fileURLToPath } from 'node:url' import { ast, definePlugin, defineGenerator } from 'kubb/kit' export const pluginExample = definePlugin(() => ({ name: 'plugin-example', hooks: { 'kubb:plugin:setup'(ctx) { // ctx.config gives access to the full Kubb configuration. const outputPath = ctx.config.output.path // Register a generator that emits one file per operation. ctx.addGenerator( defineGenerator({ name: 'example-generator', operation(node, genCtx) { return [ ast.factory.createFile({ baseName: `${node.operationId}.ts`, path: `${genCtx.root}/${node.operationId}.ts`, sources: [ast.factory.createSource({ nodes: [ast.factory.createText(`// output: ${outputPath}\n`)] })], }), ] }, }), ) // Inject a static file directly, bypassing generators entirely. ctx.injectFile({ baseName: 'README.md', path: `${outputPath}/README.md`, sources: [{ kind: 'Source', nodes: [{ kind: 'Text', value: '# Generated\n' }] }], }) // Copy a real file shipped in your package into the output, verbatim. ctx.injectFile({ baseName: 'runtime.ts', path: `${outputPath}/runtime.ts`, copy: fileURLToPath(new URL('../templates/runtime.ts', import.meta.url)), }) }, }, })) ``` -------------------------------- ### Example diagnostic output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-invalid-document.md The terminal output displayed when the KUBB_INVALID_DOCUMENT error is triggered. ```text [KUBB_INVALID_DOCUMENT]: The resolved `input` is not an OpenAPI or Swagger document: it declares no `openapi` or `swagger` version. fix: Point `input` at a document that declares `openapi` or `swagger`. If you pass an object, pass the spec itself rather than a wrapper such as `{ path }` or `{ data }`. see: https://kubb.dev/docs/5.x/reference/diagnostics/kubb-invalid-document ``` -------------------------------- ### Diagnostic output example Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-input-required.md The error message displayed in the terminal when the input is missing. ```text [KUBB_INPUT_REQUIRED]: An adapter is configured without an input. fix: Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config. see: https://kubb.dev/docs/5.x/reference/diagnostics/kubb-input-required ``` -------------------------------- ### Configure infinite query options Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-vue-query/reference/options.md Examples showing the default behavior versus enabling infinite query hooks. ```typescript export function getPetsQueryOptions(/* ... */) { return queryOptions({ queryKey, queryFn }) } ``` ```typescript export function getPetsInfiniteQueryOptions(/* ... */) { return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam }) } export function useGetPetsInfiniteQuery(/* ... */) { return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */)) } ``` -------------------------------- ### Configure Kubb with plugin-fetch Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-fetch/recipes/build-a-url-without-sending.md Setup the Kubb configuration to include the fetch plugin for generating client code. ```typescript import { defineConfig } from 'kubb/config' import { pluginTs } from '@kubb/plugin-ts' import { pluginFetch } from '@kubb/plugin-fetch' export default defineConfig({ input: './petStore.yaml', output: { path: './src/gen', clean: true }, plugins: [ pluginTs(), pluginFetch(), ], }) ``` -------------------------------- ### Update global Kubb CLI Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-update-available.md Command to update the global Kubb CLI installation. ```shell npm install -g @kubb/cli ``` -------------------------------- ### Configure Zod coercion Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-zod/reference/options.md Examples of using z.coerce for string, number, and date types. ```typescript z.coerce.string() z.coerce.number() z.coerce.date() ``` -------------------------------- ### Kubb CLI Usage Syntax Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/commands/index.md Displays the general usage pattern and available commands for the Kubb CLI. ```text USAGE kubb [COMMAND] [OPTIONS] COMMANDS init Initialize a new Kubb project with interactive setup generate [input] Generate files based on a 'kubb.config.ts' file (default) validate Validate a Swagger/OpenAPI file mcp Start the MCP server so an MCP client can interact with the LLM studio [action] Connect this project to Kubb Studio and generate from the browser Use kubb --help for more information about a command. ``` -------------------------------- ### Partial override for ResolverClientPatch Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-axios/reference/options.md Example of the type definition for overriding resolver naming conventions. ```typescript type ResolverClientPatch = { name?(name: string): string file?: { baseName?(params: { name: string; extname: string }): string path?(params: { baseName: string; output: Output }): string } className?(name: string): string groupName?(name: string): string // → 'PetClient' propertyName?(name: string): string } ``` -------------------------------- ### Run Kubb commands in Claude Code Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/ai/claude.md Example workflow for validating a spec, initializing the configuration, and generating code. ```text /kubb:validate ./petStore.yaml /kubb:init ./petStore.yaml ./src/gen plugin-ts,plugin-zod,plugin-react-query /kubb:generate ``` -------------------------------- ### View KUBB_PLUGIN_WARNING output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-plugin-warning.md Example of how a plugin warning appears in the terminal during a Kubb run. ```text [KUBB_PLUGIN_WARNING] plugin-zod: Falling back to z.any() for an untyped schema. see: https://kubb.dev/docs/5.x/reference/diagnostics/kubb-plugin-warning ``` -------------------------------- ### KUBB_FORMAT_FAILED Terminal Output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-format-failed.md Example of the error message displayed in the terminal when the formatter fails. ```text [KUBB_FORMAT_FAILED]: formatter failed: Cannot find module 'oxfmt' fix: Check that the tool is installed and that the command and its config are correct. see: https://kubb.dev/docs/5.x/reference/diagnostics/kubb-format-failed ``` -------------------------------- ### KUBB_ADAPTER_REQUIRED diagnostic output Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-adapter-required.md Example of the error message displayed in the terminal when the diagnostic is triggered. ```text [KUBB_ADAPTER_REQUIRED]: An adapter is required, but none is configured. fix: Set `adapter` in kubb.config.ts (for example `adapterOas()`). see: https://kubb.dev/docs/5.x/reference/diagnostics/kubb-adapter-required ``` -------------------------------- ### Iterate on packages Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/community/contributing.md Run specific packages in watch mode or execute the test suite. ```shell pnpm -F @kubb/core start ``` ```shell pnpm run test ``` -------------------------------- ### Example YAML schema with unsupported format Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/diagnostics/kubb-unsupported-format.md Demonstrates a schema definition using a custom format that triggers the KUBB_UNSUPPORTED_FORMAT warning. ```yaml components: schemas: Pet: type: object properties: id: type: string format: snowflake # falls back to string ``` -------------------------------- ### TypeScript Only Configuration Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/guide/recipes.md Minimal setup to generate TypeScript types and interfaces from an OpenAPI specification. ```typescript import { defineConfig } from 'kubb/config' import { pluginTs } from '@kubb/plugin-ts' export default defineConfig({ input: './petStore.yaml', output: { path: './src/gen', clean: true }, plugins: [pluginTs()], }) ``` -------------------------------- ### Update input configuration Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/migration.md Simplify the input configuration by passing the path or spec directly instead of using an object wrapper. ```diff export default defineConfig({ - input: { path: './petstore.yaml' }, + input: './petstore.yaml', output: { path: './src/gen' }, }) ``` -------------------------------- ### Generated TypeScript output Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-ts/recipes/map-spec-types-to-native-ts.md Example of the generated TypeScript interface where integer types have been mapped to bigint. ```typescript export type Order = { id?: bigint; petId?: bigint; quantity?: bigint; // ... }; ``` -------------------------------- ### Configure input adapter Source: https://github.com/kubb-labs/docs/blob/main/docs/5.x/reference/configuration.md Customize the input adapter to convert source files into the universal AST. ```typescript import { defineConfig } from 'kubb/config' import { adapterOas } from '@kubb/adapter-oas' export default defineConfig({ input: './petStore.yaml', output: { path: './src/gen' }, adapter: adapterOas({ validate: true }), }) ``` -------------------------------- ### Faker parser implementation Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-msw/reference/options.md Example of a handler using the faker parser to generate response bodies. ```typescript export function getPetHandler(data?: GetPetQueryResponse | ((info: Parameters[1]>[0]) => Response | Promise)) { return http.get('/pet/:petId', function handler(info) { if (typeof data === 'function') return data(info) return new Response(JSON.stringify(data || createGetPetQueryResponse(data)), { status: 200, headers: { 'Content-Type': 'application/json' }, }) }) } ``` -------------------------------- ### Create an isolated client for multi-tenant environments Source: https://github.com/kubb-labs/docs/blob/main/snippets/how-to/authentication.md Use createClient to build a client instance with a specific base URL and authentication token resolver. ```typescript import { createClient } from './gen/.kubb/client' const tenant = createClient({ baseURL: 'https://tenant.example.com', auth: () => tenantToken, }) const { data } = await getPetById({ path: { petId: 1 }, client: tenant }) ``` -------------------------------- ### Generated MSW handler example Source: https://github.com/kubb-labs/docs/blob/main/plugins/plugin-msw/recipes/auto-generated-mock-data.md The generated handler function that utilizes the mock data creator. ```typescript import type { GetPetByIdResponse } from '../types/GetPetById' import { createGetPetByIdResponse } from '../mocks/createGetPetById' import { http } from 'msw' export function getPetByIdHandler(data?: GetPetByIdResponse | ((info: Parameters[1]>[0]) => Response | Promise)) { return http.get('/pet/:petId\:search', function handler(info) { if (typeof data === 'function') return data(info) return new Response(JSON.stringify(data || createGetPetByIdResponse(data)), { status: 200, headers: { 'Content-Type': 'application/json' }, }) }) } ```