Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content

Migration: @kubb/plugin-faker

Part of the v4 → v5 migration guide. See the full option reference in @kubb/plugin-faker.

dateType, integerType, unknownType, emptySchemaType, and contentType moved to adapterOas. See Migration: @kubb/adapter-oas. resolver.resolveName replaces transformers.name, and macros replace transformers.schema. The generators option is gone.

Removed: paramsCasing

v4 kubb.config.ts
typescript
pluginFaker({ paramsCasing: 'camelcase' })

Properties inside the generated path, query, and header mocks are now always camelCase, so drop the option. This keeps the mocks assignable to the types from @kubb/plugin-ts, which also camelCases parameters.

Generated output

Generic return type and intermediate variable

The create prefix stays, so createPet is still createPet. The signature and internal structure change. The factory now takes a generic TData and lifts the fake values into a defaultFakeData variable before the spread.

Diff
diff
 export function createPet(data?: Partial<Pet>): Pet {
   return {
     ...{
       id: faker.number.int(),
       ...
     },
     ...(data || {}),
   }
 }
 export function createPet<TData extends Partial<Pet> = object>(data?: TData) {
   const defaultFakeData = {
     id: faker.number.int(),
     ...
   }
   return {
     ...defaultFakeData,
     ...(data || {}),
   } as Omit<typeof defaultFakeData, keyof TData> & TData
 }

The inferred return type keeps the fields you pass in data exactly as typed and fills the rest from defaultFakeData, so an override like createPet({ id: 1 }) reads back id as the literal you set rather than the wider schema type.