### Initialize Kubb with default configurations
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/init.md
Run this command for a default Kubb setup. It will create a `kubb.config.ts` file and install the default `plugin-ts` if no other plugins are specified.
```shell
npx kubb init --yes
```
--------------------------------
### Initialize Kubb with specific configurations
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/init.md
Use this command to scaffold a `kubb.config.ts` file and install plugins. Specify your OpenAPI input, output directory, and a comma-separated list of plugins. The `--yes` flag ensures non-interactive setup and creates a `package.json` if one doesn't exist.
```shell
npx kubb init --yes --input --output --plugins
```
--------------------------------
### Run `kubb init` interactively
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Run the `kubb init` command without any flags to start an interactive setup wizard for scaffolding a new Kubb project.
```bash
npx kubb init
```
--------------------------------
### Install @kubb/core
Source: https://github.com/kubb-labs/kubb/blob/main/packages/core/README.md
Install the @kubb/core package using your preferred package manager.
```bash
bun add @kubb/core
# or
pnpm add @kubb/core
# or
npm install @kubb/core
```
--------------------------------
### Install Kubb
Source: https://github.com/kubb-labs/kubb/blob/main/README.md
Install Kubb using your preferred package manager.
```bash
bun add kubb
# or
pnpm add kubb
# or
npm install kubb
```
--------------------------------
### Fork, Clone, Install, and Build Kubb
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Commands to set up the Kubb development environment. Ensure you have Node.js 22+ and pnpm 11+ installed. This process includes forking the repository, cloning your fork, installing dependencies, and building the project.
```bash
gh repo fork kubb-labs/kubb --clone # or: git clone https://github.com/kubb-labs/kubb.git
cd kubb
pnpm install
pnpm build
```
--------------------------------
### Example kubb.config.ts
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Example configuration file for Kubb, defining input, output, and plugins.
```typescript
import { defineConfig } from 'kubb'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginAxios } from '@kubb/plugin-axios'
export default defineConfig({
input: {
path: './petstore.yaml',
},
output: {
path: './src/generated',
},
plugins: [pluginOas(), pluginTs(), pluginAxios()],
})
```
--------------------------------
### Install @kubb/plugin-barrel
Source: https://github.com/kubb-labs/kubb/blob/main/packages/plugin-barrel/README.md
Install the plugin using your preferred package manager.
```bash
bun add @kubb/plugin-barrel
# or
pnpm add @kubb/plugin-barrel
# or
npm install @kubb/plugin-barrel
```
--------------------------------
### Install @kubb/parser-ts
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-ts/README.md
Install the package using your preferred package manager.
```bash
bun add @kubb/parser-ts
# or
pnpm add @kubb/parser-ts
# or
npm install @kubb/parser-ts
```
--------------------------------
### Initialize Kubb Project
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/README.md
Use the /kubb:init command to scaffold a kubb.config.ts file and install necessary packages. Specify input and output paths, and desired plugins.
```text
/kubb:init ./petstore.yaml
```
--------------------------------
### Install @kubb/mcp
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Install @kubb/mcp as a dev dependency using bun, pnpm, or npm.
```bash
bun add -D @kubb/mcp
# or
pnpm add -D @kubb/mcp
# or
npm install -D @kubb/mcp
```
--------------------------------
### Start the MCP Server using Kubb CLI
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Start the MCP server using the Kubb CLI command.
```bash
npx kubb mcp
```
--------------------------------
### Run `kubb init` with specific plugins
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Selectively install specific Kubb plugins during project initialization by providing a comma-separated list to the `--plugins` flag.
```bash
npx kubb init --plugins plugin-ts,plugin-axios,plugin-react-query
```
--------------------------------
### Install @kubb/renderer-jsx
Source: https://github.com/kubb-labs/kubb/blob/main/packages/renderer-jsx/README.md
Install the @kubb/renderer-jsx package using your preferred package manager.
```bash
bun add @kubb/renderer-jsx
# or
pnpm add @kubb/renderer-jsx
# or
npm install @kubb/renderer-jsx
```
--------------------------------
### Install @kubb/adapter-oas
Source: https://github.com/kubb-labs/kubb/blob/main/packages/adapter-oas/README.md
Install the @kubb/adapter-oas package using your preferred package manager.
```bash
bun add @kubb/adapter-oas
# or
pnpm add @kubb/adapter-oas
# or
npm install @kubb/adapter-oas
```
--------------------------------
### Start the MCP Server as a Standalone Package
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Run the MCP server directly as a standalone package.
```bash
npx @kubb/mcp
```
--------------------------------
### Install unplugin-kubb
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Install unplugin-kubb and @kubb/core using your preferred package manager.
```bash
bun add -D unplugin-kubb @kubb/core
# or
pnpm add -D unplugin-kubb @kubb/core
# or
npm install -D unplugin-kubb @kubb/core
```
--------------------------------
### Install @kubb/parser-md
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/README.md
Install the @kubb/parser-md package using your preferred package manager.
```bash
bun add @kubb/parser-md
# or
pnpm add @kubb/parser-md
# or
npm install @kubb/parser-md
```
--------------------------------
### Start MCP Server (HTTP mode)
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Start the MCP server in HTTP mode by specifying a port using the `--port` flag. This allows AI assistants to connect via an HTTP server.
```bash
npx kubb mcp --port 3001
```
--------------------------------
### Scaffold Kubb Configuration with CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/agents/kubb-expert.md
Initialize Kubb in a project by creating a `kubb.config.ts` file and installing necessary packages. Specify the input spec, output directory, and desired plugins.
```bash
kubb init --input --output --plugins
```
--------------------------------
### Install Kubb CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/README.md
Install Kubb CLI locally in your project or globally. The plugin requires Kubb v5 or higher.
```bash
npm install -D kubb # in the project
npm install -g kubb # or globally
```
--------------------------------
### Install @kubb/cli
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Install the @kubb/cli package as a development dependency using your preferred package manager.
```bash
bun add -D @kubb/cli
# or
pnpm add -D @kubb/cli
# or
npm install -D @kubb/cli
```
--------------------------------
### Install Kubb Claude Plugin
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/README.md
Add the Kubb Claude plugin to your Claude marketplace and install it. For local testing, run Claude with the plugin directory.
```bash
# add this repo as a marketplace, then install the plugin
/plugin marketplace add kubb-labs/kubb
/plugin install kubb@kubb
```
```bash
claude --plugin-dir ./tools/claude
```
--------------------------------
### Create a JSX renderer instance
Source: https://github.com/kubb-labs/kubb/blob/main/packages/renderer-jsx/README.md
Instantiate the JSX renderer to access its render, files, and stream methods. This is the starting point for using the renderer.
```typescript
const renderer = jsxRenderer()
await renderer.render( )
const files = renderer.files // FileNode[]
```
--------------------------------
### Run Kubb Generate CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/generate.md
Execute the `kubb generate` command to start the code generation process. An optional input spec can be provided as the first argument to override the default input specified in the configuration.
```shell
npx kubb generate
```
--------------------------------
### Render files with JSX components
Source: https://github.com/kubb-labs/kubb/blob/main/packages/renderer-jsx/README.md
Use the built-in components within a Kubb plugin to emit generated files. This example demonstrates creating a file with type and function definitions.
```tsx
import { jsxRenderer } from '@kubb/renderer-jsx'
import { File, Function, Type } from '@kubb/renderer-jsx'
const renderer = jsxRenderer()
await renderer.render(
{'{ id: number; name: string }'}
{"return fetch('/pets')"}
,
)
const files = renderer.files
```
--------------------------------
### Run Kubb Validate CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/validate.md
Execute the `kubb validate` command in your terminal, providing the path or URL to your OpenAPI/Swagger specification file. Ensure `@kubb/adapter-oas` is installed if prompted.
```shell
npx kubb validate --input
```
--------------------------------
### Configure pluginBarrel in kubb.config.ts
Source: https://github.com/kubb-labs/kubb/blob/main/packages/plugin-barrel/README.md
Add pluginBarrel to the plugins array in your kubb.config.ts file. This example shows how to configure it with the 'named' export type.
```typescript
import { defineConfig } from 'kubb'
import { pluginBarrel } from '@kubb/plugin-barrel'
export default defineConfig({
input: {
path: './openapi.yaml',
},
output: {
path: './src/gen',
},
plugins: [
pluginBarrel({
type: 'named',
}),
],
})
```
--------------------------------
### Local Development Build and Check
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Commands to build, type-check, and test your local changes during development.
```bash
pnpm build && pnpm typecheck && pnpm test
```
--------------------------------
### Run `kubb init` non-interactively
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Configure `kubb init` non-interactively by specifying the input OpenAPI spec path, output directory, and desired plugins using flags.
```bash
npx kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod
```
--------------------------------
### Configure MCP Client with project-specific working directory
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Configure an MCP client for a specific project by setting the working directory.
```json
{
"mcpServers": {
"kubb-petstore": {
"command": "npx",
"args": ["@kubb/mcp"],
"cwd": "/path/to/your/project"
}
}
}
```
--------------------------------
### Common Project Commands
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
A list of common pnpm commands for managing the project, including building, cleaning, testing, type checking, linting, formatting, and creating changesets.
```bash
pnpm build # Build all packages with tsdown
pnpm clean # Remove build artifacts
pnpm test # Run tests once
pnpm test:watch # Run tests in watch mode
pnpm test:bench # Run performance benchmarks
pnpm typecheck # Type-check all packages
pnpm lint # Lint with oxlint
pnpm lint:fix # Lint and auto-fix
pnpm format # Format with oxfmt
pnpm changeset # Create a changeset
pnpm upgrade # Bump dependencies with taze
```
--------------------------------
### Configure MCP Client with standalone @kubb/mcp package
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Configure an MCP client to use the standalone '@kubb/mcp' package.
```json
{
"mcpServers": {
"kubb": {
"command": "npx",
"args": ["@kubb/mcp"]
}
}
}
```
--------------------------------
### Local Development Style Fixes
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Commands to format code and fix linting issues locally.
```bash
pnpm format && pnpm lint:fix
```
--------------------------------
### Creating AST Nodes with Factory
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Demonstrates how to construct AST nodes using the `ast.factory` functions, similar to TypeScript's `ts.factory`. This is useful for programmatically generating AST structures.
```typescript
import { ast } from '@kubb/ast'
const { createInput, createSchema, createProperty } = ast.factory
const root = createInput({
schemas: [
createSchema({
name: 'Pet',
type: 'object',
properties: [
createProperty({
name: 'id',
schema: createSchema({ type: 'integer' }),
required: true,
}),
createProperty({
name: 'name',
schema: createSchema({ type: 'string' }),
required: true,
}),
],
}),
],
})
```
--------------------------------
### Token Optimized CLI (rtk) Meta Commands
Source: https://github.com/kubb-labs/kubb/blob/main/AGENTS.md
Run meta commands directly with 'rtk' for specific functionalities like viewing savings dashboards or discovering missed 'rtk' opportunities. Use 'rtk proxy ' to run raw commands while still tracking usage.
```bash
rtk gain # Token savings dashboard
rtk gain --history # Per-command savings history
rtk discover # Find missed rtk opportunities
rtk proxy # Run raw without filtering but still track usage
```
--------------------------------
### Run Kubb Generate CLI with Custom Config and Verbose Mode
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/generate.md
Execute the `kubb generate` command using a custom configuration file path with `--config ` and enabling verbose output with `--verbose` for detailed logging.
```shell
npx kubb generate --config --verbose
```
--------------------------------
### Run Shell Commands with Token Optimization (rtk)
Source: https://github.com/kubb-labs/kubb/blob/main/CLAUDE.md
Prefix shell commands with 'rtk' to filter and compress their output, reducing token usage. Use meta commands for specific tasks like viewing savings or discovering optimization opportunities.
```bash
rtk git status
rtk git log -10
rtk pnpm test
```
```bash
rtk gain # Token savings dashboard
rtk gain --history # Per-command savings history
rtk discover # Find missed rtk opportunities
rtk proxy # Run raw without filtering but still track usage
```
--------------------------------
### Generate code with default config file
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Use the 'generate' tool with a default kubb.config.ts file.
```json
{
"config": "./kubb.config.ts"
}
```
--------------------------------
### Generate Code with Default Config
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Use the `generate` command to create code based on your `kubb.config.ts` file. This is the default way to generate code.
```bash
npx kubb generate
```
--------------------------------
### Generate Code with Kubb CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/agents/kubb-expert.md
Run the Kubb code generation process based on the existing configuration. Use the `--verbose` flag for detailed output during debugging.
```bash
kubb generate
```
```bash
kubb generate --verbose
```
--------------------------------
### Generate code with verbose logging
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Use the 'generate' tool with verbose logging enabled.
```json
{
"config": "./kubb.config.ts",
"logLevel": "verbose"
}
```
--------------------------------
### Create a Changeset
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Command to generate a changeset file for versioning and changelog updates when a change affects a published package.
```bash
pnpm changeset
```
--------------------------------
### Generate Code with Custom Config
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Specify a custom configuration file for the `generate` command using the `--config` flag.
```bash
npx kubb generate --config ./configs/kubb.config.ts
```
--------------------------------
### Generate Code with Custom Reporters
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Configure specific reporters, such as `cli` and `json`, using the `--reporter` flag to customize output.
```bash
npx kubb generate --reporter cli,json
```
--------------------------------
### Run Single Package Tests
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Commands to run tests for a specific package using Vitest, pointing to its configuration and package directory.
```bash
pnpm vitest run --config ./configs/vitest.config.ts packages/core
```
```bash
pnpm vitest run --config ./configs/vitest.config.ts -u packages/core # update snapshots
```
--------------------------------
### Full Local Check Before PR
Source: https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md
Run all checks, including formatting, linting, type checking, and tests, to ensure code quality before opening a pull request.
```bash
pnpm format && pnpm lint:fix
pnpm typecheck
pnpm test
```
--------------------------------
### Configure MCP Client with kubb mcp command
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Configure an MCP client to use the 'kubb mcp' command.
```json
{
"mcpServers": {
"kubb": {
"command": "npx",
"args": ["kubb", "mcp"]
}
}
}
```
--------------------------------
### Kubb AST Node Structure Overview
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Provides a high-level overview of the Kubb AST node hierarchy, illustrating the relationships between different node types such as RootNode, SchemaNode, and OperationNode.
```plaintext
RootNode
├── schemas: SchemaNode[]
└── operations: OperationNode[]
├── parameters: ParameterNode[] → SchemaNode
├── requestBody?: SchemaNode
└── responses: ResponseNode[] → SchemaNode?
SchemaNode (discriminated union)
object → properties: PropertyNode[] → SchemaNode
array | tuple → items: SchemaNode[]
union | intersection → members: SchemaNode[]
enum | ref | string | number | integer | bigint
boolean | null | any | unknown | void
date | datetime | time | uuid | email | url | blob
```
--------------------------------
### Kubb Options Configuration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Define the options for Kubb, including the user configuration.
```typescript
type Options = {
config: UserConfig
}
```
--------------------------------
### Generate Code with Custom Input
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Override the input OpenAPI file path specified in your config by passing it as an argument to the `generate` command.
```bash
npx kubb generate ./openapi.yaml
```
--------------------------------
### adapterOas(options?)
Source: https://github.com/kubb-labs/kubb/blob/main/packages/adapter-oas/README.md
Creates an instance of the OAS adapter for Kubb. This function is intended to be used within the `adapters` array of the `defineConfig` function in your `kubb.config.ts` file.
```APIDOC
## adapterOas(options?)
### Description
Creates the OAS adapter instance. Pass it in the `adapters` array of `defineConfig`.
### Method
`adapterOas`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
export default defineConfig({
input: {
path: './openapi.yaml',
},
output: {
path: './src/gen',
},
adapters: [adapterOas()],
})
```
### Response
#### Success Response
An OAS adapter instance.
#### Response Example
(Not applicable for function creation)
```
--------------------------------
### Run Kubb Generate CLI with Input Spec Override
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/generate.md
Run the `kubb generate` command, specifying an input spec file (e.g., `./openapi.yaml`) as the first argument to override the input defined in the `kubb.config.ts` file.
```shell
npx kubb generate ./openapi.yaml
```
--------------------------------
### esbuild Integration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Integrate unplugin-kubb into your esbuild build process by importing and adding it to the plugins array.
```typescript
import { build } from 'esbuild'
import kubb from 'unplugin-kubb/esbuild'
build({
plugins: [kubb()],
})
```
--------------------------------
### Generate Code with Verbose Logging
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Use the `--verbose` flag to enable verbose logging during the code generation process.
```bash
npx kubb generate --verbose
```
--------------------------------
### Generate Code with Watch Mode
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Enable watch mode with the `--watch` flag to automatically regenerate code whenever the input file changes.
```bash
npx kubb generate --watch
```
--------------------------------
### Type Narrowing with Schema Guards
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Explains how to use `narrowSchema` and `schemaDef.is` to check the type of a node and narrow it down to a specific schema type, ensuring type safety when working with the AST.
```typescript
import { narrowSchema, schemaDef } from '@kubb/ast'
import type { Node } from '@kubb/ast/types'
function process(node: Node) {
if (schemaDef.is(node)) {
const obj = narrowSchema(node, 'object')
obj?.properties?.forEach((p) => console.log(p.name))
}
}
```
--------------------------------
### Extracting Data from AST with Collect Visitor
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Demonstrates how to use the `collect` function to extract specific data from the AST. The visitor function returns the desired data for each node, which is then aggregated into a list.
```typescript
import { walk, transform, collect } from '@kubb/ast'
// Extraction
const types = collect(root, {
schema(node) {
return node.type
},
})
```
--------------------------------
### Run Kubb Generate CLI in Watch Mode
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/commands/generate.md
Use the `--watch` flag with the `kubb generate` command to automatically regenerate code whenever the input spec file changes.
```shell
npx kubb generate --watch
```
--------------------------------
### Transforming AST Immutably with Transform Visitor
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Illustrates how to use the `transform` function to create a new AST with modifications. The visitor function returns a new node or the original node if no changes are needed.
```typescript
import { walk, transform, collect } from '@kubb/ast'
// Immutable transformation
const updated = transform(root, {
schema(node) {
return { ...node, description: 'generated' }
},
})
```
--------------------------------
### Configure Kubb with OAS Adapter
Source: https://github.com/kubb-labs/kubb/blob/main/packages/adapter-oas/README.md
Configure your `kubb.config.ts` to use the `adapterOas` for processing OpenAPI specifications.
```typescript
import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
export default defineConfig({
input: {
path: './openapi.yaml',
},
output: {
path: './src/gen',
},
adapters: [adapterOas()],
})
```
--------------------------------
### Traversing AST with Walk Visitor
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Shows how to use the `walk` function to perform side effects by visiting each node in the AST. The visitor function is called for each node of a specific type.
```typescript
import { walk, transform, collect } from '@kubb/ast'
// Side effects
await walk(root, {
schema(node) {
console.log(node.type)
},
})
```
--------------------------------
### Generate code overriding input and output
Source: https://github.com/kubb-labs/kubb/blob/main/packages/mcp/README.md
Use the 'generate' tool to override input and output paths specified in the config file.
```json
{
"config": "./kubb.config.ts",
"input": "./specs/petstore.yaml",
"output": "./src/generated"
}
```
--------------------------------
### Vite Integration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Integrate unplugin-kubb into your Vite build process by importing and adding it to your plugins.
```typescript
import kubb from 'unplugin-kubb/vite'
export default defineConfig({
plugins: [
kubb({
/* options */
}),
],
})
```
--------------------------------
### parserTs API
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-ts/README.md
The `parserTs` instance is used for `.ts` and `.js` files. It can be passed to `defineConfig` to emit TypeScript source files. It provides methods to parse file nodes and print TypeScript compiler nodes.
```APIDOC
## parserTs API
Parser instance for `.ts` and `.js` files. Pass to `defineConfig({ parsers: [...] })` to emit TypeScript source files.
- `parserTs.parse(file, options?)` — serialize a `FileNode` to TypeScript source.
- `parserTs.print(...nodes)` — convert TypeScript compiler `Node` instances to a formatted source string.
```
--------------------------------
### Validate Local OpenAPI File
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Validate a local OpenAPI file by providing its path to the `--input` flag of the `validate` command.
```bash
npx kubb validate --input ./openapi.yaml
```
--------------------------------
### Validate OpenAPI Specification
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Use the `validate` command to check an OpenAPI/Swagger file for structural correctness. The `--input` flag is required.
```bash
npx kubb validate --input
```
--------------------------------
### Configure Kubb with @kubb/parser-md
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/README.md
Configure Kubb to use the @kubb/parser-md parser alongside other parsers like @kubb/parser-ts by including it in the `parsers` array within `defineConfig`.
```typescript
import { defineConfig } from 'kubb'
import { parserMd } from '@kubb/parser-md'
import { parserTs } from '@kubb/parser-ts'
export default defineConfig({
input: { path: './petstore.yaml' },
output: { path: './src/gen' },
parsers: [parserTs, parserMd],
})
```
--------------------------------
### parserTsx API
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-ts/README.md
The `parserTsx` instance is used for `.tsx` and `.jsx` files. It has the same API as `parserTs` but includes support for JSX.
```APIDOC
## parserTsx API
Parser instance for `.tsx` and `.jsx` files. Same API as `parserTs` with JSX support.
```
--------------------------------
### Nuxt Integration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Integrate unplugin-kubb into your Nuxt configuration by adding it to the modules array.
```typescript
export default defineNuxtConfig({
modules: [
[
'unplugin-kubb/nuxt',
{
/* options */
},
],
],
})
```
--------------------------------
### Webpack Integration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Integrate unplugin-kubb into your Webpack configuration by requiring the plugin.
```javascript
module.exports = {
/* ... */
plugins: [
require('unplugin-kubb/webpack')({
/* options */
}),
],
}
```
--------------------------------
### Configure Kubb with Parsers
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-ts/README.md
Integrate the TypeScript parsers into your Kubb configuration to enable processing of .ts and .tsx files.
```typescript
import { defineConfig } from 'kubb'
import { parserTs, parserTsx } from '@kubb/parser-ts'
export default defineConfig({
input: { path: './petstore.yaml' },
output: { path: './src/gen' },
parsers: [parserTs, parserTsx],
})
```
--------------------------------
### parserMd.print
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/README.md
Joins markdown fragments separated by blank lines. Plain objects are serialized as YAML frontmatter; strings pass through unchanged. This is useful for programmatically generating markdown files with YAML frontmatter.
```APIDOC
## parserMd.print
### Description
Joins markdown fragments separated by blank lines. Plain objects are serialized as YAML frontmatter; strings pass through unchanged.
### Method
`parserMd.print(...parts)`
### Parameters
- `...parts` (string | object) - Markdown fragments to join. Objects will be serialized as YAML frontmatter.
### Request Example
```typescript
import { parserMd } from '@kubb/parser-md'
const source = parserMd.print({ title: 'Pets', layout: 'doc' })
// → ---
// title: Pets
// layout: doc
// ---
```
```
--------------------------------
### Print YAML Frontmatter with @kubb/parser-md
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/README.md
Use the `parserMd.print` method to convert a metadata object into a YAML frontmatter string. This is useful for generating Markdown files with frontmatter from within a Kubb plugin.
```typescript
import { parserMd } from '@kubb/parser-md'
const source = parserMd.print({ title: 'Pets', layout: 'doc' })
// → ---
// title: Pets
// layout: doc
// ---
```
--------------------------------
### Configure tsconfig.json for JSX runtime
Source: https://github.com/kubb-labs/kubb/blob/main/packages/renderer-jsx/README.md
Configure your tsconfig.json to use the JSX runtime provided by @kubb/renderer-jsx by setting 'jsx' to 'react-jsx' and 'jsxImportSource' to '@kubb/renderer-jsx'.
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@kubb/renderer-jsx"
}
}
```
--------------------------------
### Print AST Nodes to Source
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-ts/README.md
Use the `print` method from the parser instance to convert TypeScript compiler AST nodes into formatted source code strings. This is useful for generating code within plugins.
```typescript
import { parserTs } from '@kubb/parser-ts'
import ts from 'typescript'
const source = parserTs.print(
ts.factory.createVariableStatement(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration('hello', undefined, undefined, ts.factory.createStringLiteral('world'))],
ts.NodeFlags.Const,
),
),
)
// → export const hello = 'world'
```
--------------------------------
### Rollup Integration
Source: https://github.com/kubb-labs/kubb/blob/main/packages/unplugin-kubb/README.md
Integrate unplugin-kubb into your Rollup build process by importing and adding it to your plugins.
```typescript
import kubb from 'unplugin-kubb/rollup'
export default {
plugins: [
kubb({
/* options */
}),
],
}
```
--------------------------------
### Token Optimized CLI (rtk) Usage
Source: https://github.com/kubb-labs/kubb/blob/main/AGENTS.md
Prefix shell commands with 'rtk' to filter and compress command output, reducing token usage. This is useful for commands like git status or pnpm test.
```bash
rtk git status
rtk git log -10
rtk pnpm test
```
--------------------------------
### Extracting Reference Name from URI
Source: https://github.com/kubb-labs/kubb/blob/main/packages/ast/README.md
Shows how to use the `extractRefName` utility function to parse a reference URI (e.g., '#/components/schemas/Pet') and extract the actual name of the referenced schema.
```typescript
import { extractRefName } from '@kubb/ast/utils'
extractRefName('#/components/schemas/Pet') // 'Pet'
```
--------------------------------
### parserMd.parse
Source: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/README.md
Serializes a FileNode to Markdown source. When file.meta.frontmatter is set, the parser prepends the corresponding YAML envelope. This method is used internally by Kubb to process markdown files.
```APIDOC
## parserMd.parse
### Description
Serializes a `FileNode` to Markdown source. When `file.meta.frontmatter` is set, the parser prepends the corresponding YAML envelope.
### Method
`parserMd.parse(file)`
### Parameters
- `file` (FileNode) - The file node to serialize.
### Note
This method is primarily for internal use within Kubb plugins.
```
--------------------------------
### Validate OpenAPI/Swagger Spec with Kubb CLI
Source: https://github.com/kubb-labs/kubb/blob/main/tools/claude/agents/kubb-expert.md
Validate a spec file before performing any destructive operations. Use this to ensure the input spec is well-formed.
```bash
kubb validate --input
```
--------------------------------
### Validate Remote OpenAPI Specification
Source: https://github.com/kubb-labs/kubb/blob/main/packages/cli/README.md
Validate a remote OpenAPI specification by providing its URL to the `--input` flag of the `validate` command.
```bash
npx kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json
```
--------------------------------
### mergeDocuments(documents)
Source: https://github.com/kubb-labs/kubb/blob/main/packages/adapter-oas/README.md
Merges multiple OpenAPI documents into a single document. This utility function can be used before parsing to consolidate specifications.
```APIDOC
## mergeDocuments(documents)
### Description
Merges multiple OpenAPI documents into a single document before parsing.
### Method
`mergeDocuments`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **documents** (Array) - Required - An array of OpenAPI documents to merge.
### Request Example
```typescript
import { mergeDocuments } from '@kubb/adapter-oas'
const mergedDoc = mergeDocuments([doc1, doc2])
```
### Response
#### Success Response
A single merged OpenAPI document.
#### Response Example
```json
{
"openapi": "3.0.0",
"info": {
"title": "Merged API",
"version": "1.0.0"
},
"paths": { ... }
}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.