Skip to content

Generating the SDK

The SDK is auto-generated from the API's OpenAPI specification using Kubb.

When to Regenerate

Regenerate the SDK after:

  • Adding new API endpoints
  • Modifying request/response types
  • Changing authentication requirements
  • Updating API routes

Prerequisites

  1. Updated OpenAPI spec from the API:

    bash
    cd api
    pnpm generate:openapi
  2. The spec file at api/swagger.json

Generation Steps

1. Update API Spec

First, ensure the API's OpenAPI spec is current:

bash
cd api
pnpm generate:openapi

This updates api/swagger.json.

2. Generate SDK

bash
cd sdk
pnpm generate

This reads api/swagger.json and generates:

  • Client methods in src/client/
  • Types in src/types/
  • Axios configuration in src/axios/

3. Build

bash
pnpm build

4. Verify

Check that exports work:

bash
pnpm lint:fix

Kubb Configuration

The generator is configured in kubb.config.ts:

typescript
import { defineConfig } from "@kubb/core"
import createSwagger from "@kubb/swagger"
import createSwaggerTs from "@kubb/swagger-ts"
import createSwaggerClient from "@kubb/swagger-client"

export default defineConfig({
	input: {
		path: "../api/swagger.json",
	},
	output: {
		path: "./src",
	},
	plugins: [
		createSwagger(),
		createSwaggerTs(),
		createSwaggerClient({
			client: "axios",
		}),
	],
})

Troubleshooting

Type Errors After Generation

Run lint fix:

bash
pnpm lint:fix

Missing Endpoints

Ensure the API controller has the @Tags decorator and re-run:

bash
cd api && pnpm generate:openapi
cd ../sdk && pnpm generate

Build Failures

Clear generated files and regenerate:

bash
rm -rf src/client src/types src/axios
pnpm generate
pnpm build

CI/CD

The SDK is automatically published to Buildkite when:

  1. Changes are pushed to the SDK directory
  2. The api/swagger.json is updated

Version bumping is handled by the CI pipeline based on commit messages.

Built with VitePress