Plugin
plugins: [pluginFaker()]Officialv5.1.5kubb >=5.8.3node >=22
Faker
@kubb/plugin-faker
Generates a Faker.js mock-data factory for every schema in your OpenAPI spec.
kubb add plugin-faker
fakermock-datamocksfixturestestingcodegenopenapi
- Downloads309.2K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size386.4kBv5.1.5 on npm
- Latest release10h agov5.1.5 · Oct 13, 2026
The Faker plugin generates one factory function per schema. Each factory returns mock data from Faker.js and accepts partial data that overrides the generated values.
Use the factories in tests, Storybook, and local development without a running backend. @kubb/plugin-msw can use them to fill mock responses.
Installation
bun add -d @kubb/plugin-fakerpnpm add -D @kubb/plugin-fakernpm install --save-dev @kubb/plugin-fakeryarn add -D @kubb/plugin-fakerOr run kubb add plugin-faker to install the version the Kubb registry pins and add pluginFaker() to kubb.config.ts.
Setup
- Add
@kubb/plugin-tsfor the factory return types. Generation fails without it. - Install
@faker-js/fakerv10 in the app that uses the generated code. - Install
dayjs,moment, orrandexpwhen you pick it indateParserorregexGenerator.
Options worth knowing
seedpasses a fixed seed tofaker.seed(...), so every run returns the same data.localesets the Faker locale. The default isen.dateParserformatsdateandtimestrings withfaker(default),dayjs, ormoment.date-timevalues always use Faker.dayjsandmomentdo not work when the adapter types a date or time asDate, for example withdateType: 'date'.regexGeneratorturns apatterninto a string withfaker(default) orrandexp.typeModesets the factory types:inferred(default) derives them from the generated values, andschemauses the declared model type.
See Options for every option and its default.
Example
The config below generates the factories with a fixed seed.
kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginFaker } from '@kubb/plugin-faker'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [
pluginTs(),
pluginFaker({ seed: [100] }),
],
})Dependencies
Extensions that must be in the same config as Faker.