Skip to content
Kit

Kit API

The kubb/kit reference for extension authors: extensions, generators, resolvers, AST, renderer, storage, engine, hooks, and the casing helpers.

kubb/kit gives you the APIs to write plugins, adapters, parsers, and storage backends. It ships with kubb.

Parts of the kit

An adapter reads the spec into the AST. Generators turn the AST into files, and a resolver names them. Parsers print the files, and storage writes them.

names and pathsSpecAdapterASTGeneratorsResolverRendererFileNodeParserStorage
PartEntry pointsPage
PluginsdefineExtension({ kind: 'plugin' }), addGenerator, setResolverPlugins
AdaptersdefineExtension({ kind: 'adapter' })Adapters
ParsersdefineExtension({ kind: 'parser' })Parsers
GeneratorsdefineGeneratorGenerators
ResolverscreateResolver, ResolverResolvers
ASTast, createPrinter, defineMacroAST and node builders
JSX rendererjsxRenderer, createRendererJSX renderer
StoragecreateStorage, fsStorage, memoryStorageStorage
EnginecreateKubb, DiagnosticsEngine
Lifecycle hooksKubbHooks, HookableLifecycle hooks
Extension manifestkubb-extension.json, isExtensionManifestExtension manifest
Extension docsdocs/ folderExtension docs

Import createKubb from kubb, jsxRenderer from kubb/jsx, and everything else from kubb/kit.

Casing

casing turns spec names into identifiers and file names. Every helper except capitalize takes { prefix, suffix } as a second argument and adds them before casing.

HelperInputOutput
casing.camel'get pet-by id''getPetById'
casing.pascal'get pet-by id''GetPetById'
casing.snake'helloWorld''hello_world'
casing.screamingSnake'helloWorld''HELLO_WORLD'
casing.capitalize'getPetById''GetPetById'
casing.ts
import { casing } from 'kubb/kit'

casing.camel('tag', { prefix: 'create' }) // 'createTag'
camelCase and pascalCase from kubb/kit are deprecated. Use casing.camel and casing.pascal.

Text

text escapes and formats strings for any output language, so a quote or line break in a spec name cannot break the output.

HelperReturns
text.quote(value)A single-quoted, escaped string literal. '' for null or undefined.
text.indent({ text, unit })text with each non-empty line indented by unit, two spaces by default.
text.dedent(text)text without its common leading whitespace and surrounding blank lines.
text.unquote(text)text without one matching pair of ", ', or ` around it.
text.ts
import { text } from 'kubb/kit'

const line = `method: ${text.quote("o'clock")}` // method: 'o\'clock'