Migration: @kubb/plugin-ts
Part of the v4 → v5 migration guide. See the full option reference in @kubb/plugin-ts.
Removed: mapper
pluginTs({ mapper: { status: 'string' } })Use printer.nodes to override specific schema-type renderers, or macros to rewrite AST nodes before printing.
Renamed: transformers.name
resolver.resolveTypeName replaces transformers.name.
Moved to adapterOas
dateType, integerType, unknownType, emptySchemaType, enumSuffix, and contentType moved to adapterOas. See Migration: @kubb/adapter-oas.
Changed: enum options grouped under one object
The loose enumType, enumTypeSuffix, and enumKeyCasing options now live inside one enum object, and a new enum.constCasing sets the casing of the generated const. The old enumType: 'asPascalConst' is gone, so reach for constCasing: 'pascalCase' instead.
| v4 (old) | v5 (new) |
|---|---|
enumType: 'asConst' | enum: { type: 'asConst' } |
enumType: 'asPascalConst' | enum: { type: 'asConst', constCasing: 'pascalCase' } |
enumTypeSuffix: 'Value' | enum: { typeSuffix: 'Value' } |
enumKeyCasing: 'screamingSnakeCase' | enum: { keyCasing: 'screamingSnakeCase' } |
import { defineConfig } from '@kubb/core'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: { path: './petstore.yaml' },
output: { path: './src/gen' },
plugins: [
pluginTs({
enumType: 'asConst',
enumTypeSuffix: 'Key',
enumKeyCasing: 'none',
}),
],
})import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: { path: './petstore.yaml' },
output: { path: './src/gen' },
plugins: [
pluginTs({
enum: { type: 'asConst', constCasing: 'camelCase', typeSuffix: 'Key', keyCasing: 'none' },
}),
],
})TIP
Set constCasing: 'pascalCase' together with typeSuffix: '' to emit a const and a type that share the schema's exact name. This is the convention most hand-written codebases use, so migrating an existing project keeps every annotation and value reference working.
pluginTs({ enum: { type: 'asConst', constCasing: 'pascalCase', typeSuffix: '' } })export const VehicleType = {
Sedan: 'Sedan',
SUV: 'SUV',
} as const
export type VehicleType = (typeof VehicleType)[keyof typeof VehicleType]Generated output
Enums: object literal instead of enum
v5 emits a const-asserted object plus a *Key type union. This drops the runtime cost of a TypeScript enum and stays tree-shakable.
export enum ParamsStatusEnum {
placed = 'placed',
approved = 'approved',
delivered = 'delivered',
}
status: ParamsStatusEnumexport enum orderParamsStatusEnum {
placed = 'placed',
approved = 'approved',
delivered = 'delivered',
}
status: OrderParamsStatusEnumKey- Enum names are now operation-scoped (
orderParamsStatusEnum,customerParamsStatusEnum, …) instead of suffix-deduplicated (ParamsStatusEnum,ParamsStatusEnum2, …), so the numeric collisions are gone. - Configure
enumonpluginTswhen you wantenum,constEnum,literal, or a different const and type casing.
int64 maps to bigint by default
adapterOas now defaults integerType to 'bigint', so OpenAPI fields with format: int64 generate bigint instead of number.
- petId?: number
+ petId?: bigintSet integerType: 'number' on adapterOas to restore the previous output.
Open string unions use (string & {})
To keep IntelliSense suggestions, v5 writes the known TypeScript trick.
- status?: 'accepted' | string
+ status?: 'accepted' | (string & {})JSDoc
@type integer | undefined, int64→@type integer | undefined. The format suffix is removed, since the schema documents the format rather than the type comment.@exampleis emitted from the OpenAPIexamplefield.- Object schemas now carry an
@type objectJSDoc tag.
Discriminated unions are factored
Fields shared by every variant of a oneOf/anyOf move into a common object:
- export type Pet =
- | { id?: number; name: string; status?: StatusEnum; ... }
- | { id?: number; name: string; status?: StatusEnum; ... }
+ export type Pet = ({ ... } | { ... }) & {
+ id?: number
+ name: string
+ status?: PetStatusEnumKey
+ ...
+ }