Options
Configure @kubb/plugin-faker by passing these options to pluginFaker(), all of them optional.
| Option | Type | Default | Description |
|---|---|---|---|
output | Output | { path: 'mocks' } | Where the generated files are written and exported |
group | Group | — | Split output into per-tag or per-path folders |
dateParser | 'faker' | 'dayjs' | 'moment' | string | 'faker' | Library that formats string date and time fields |
regexGenerator | 'faker' | 'randexp' | 'faker' | Library that turns a regex pattern into a string |
locale | string | 'en' | Faker locale code for the generated values |
seed | number | number[] | — | Value passed to faker.seed(...) for deterministic output |
include | Array<Include> | — | Keep only operations that match |
exclude | Array<Exclude> | — | Skip operations that match |
override | Array<Override> | — | Apply different options per pattern |
resolver | ResolverPatch<ResolverFaker> | — | Customize generated names and file paths |
macros | Array<Macro> | — | Rewrite AST nodes before printing |
printer | { nodes?: PrinterFakerNodes } | — | Replace the handler for a schema type |
output
Where the generated .ts files are written and how they are exported.
output.path
Folder where the plugin writes its files, resolved against the global output.path on defineConfig, and defaulting to 'mocks'. To write everything to one file, set output.mode: 'file' and give path a file name with its extension, such as 'mocks.ts'.
output.mode
How the plugin consolidates generated code. 'file' (the default) writes everything into a single file, where output.path must include the extension such as 'mocks.ts'. 'directory' writes one file per operation or schema under output.path.
IMPORTANT
group requires mode: 'directory'. Pairing group with mode: 'file' (or leaving mode unset) is invalid and fails with a KUBB_INVALID_PLUGIN_OPTIONS error.
output.barrel
Toggle the export style and depth to see the generated barrels.
- src/gen/
- models/
- Pet.ts
- User.ts
- clients/
- pet/
- getPetById.ts
- store/
- getInventory.ts
Controls how the generated index.ts (barrel) re-exports the output. Accepts { type: 'named' } or { type: 'all' }, optionally with nested: true (for example { type: 'named', nested: true }) to write an index.ts in every subdirectory, or false to skip the barrel entirely. Each generator plugin defaults output.barrel to { type: 'named' }; the root output.barrel on defineConfig defaults to false.
output.banner
Text added to the top of every generated file, such as a license header or @ts-nocheck directive. Pass a string, or a function (meta: BannerMeta) => string that receives the document info (title, description, version, baseURL) and per-file context (filePath, baseName, isBarrel, isAggregation), so a directive can skip barrel files.
output.footer
Text added to the bottom of every generated file (string or (meta: BannerMeta) => string), like banner but for closing comments. Pair banner: '/* eslint-disable */' with footer: '/* eslint-enable */' to scope a lint disable to the generated file.
group
Switch the mode to see where these operations land on disk.
clients/pet/- getPetById
- addPet
clients/store/- getInventory
clients/order/- placeOrder
- getOrderById
clients/user/- loginUser
group: { type: "tag" } splits the output by the operation tag, so placeOrder follows its order tag.Splits generated files into subfolders by the operation's tag or URL path, each under {output.path}/{groupName}/. Without group, every file lands directly in output.path. It applies only to output.mode: 'directory'.
IMPORTANT
Combining group with output.mode: 'file' stops the build with a KUBB_INVALID_PLUGIN_OPTIONS error.
group.type
Property used to assign each operation to a group ('tag' | 'path'), required whenever group is set. An operation with no tag goes in the default group.
'tag'uses the operation's first tag.'path'uses the first URL segment, such aspetfor/pet/{petId}.
group.name
Function (context: { group: string }) => string that turns a group key into the subdirectory name and the suffix for aggregate files. It defaults to camelCase(group) for tag groups, and for type: 'path' groups uses the path segment as-is.
dateParser
Library used to format date and time fields represented as strings. Pick a value other than 'faker' when your project already uses a date library. Any library exporting a default function works, and Kubb adds the import for you.
A string date field renders differently per parser:
faker.date.anytime().toISOString().substring(0, 10)dayjs(faker.date.anytime()).format('YYYY-MM-DD')moment(faker.date.anytime()).format('YYYY-MM-DD')regexGenerator
Library used to generate strings that satisfy a regex pattern keyword in the spec. The default 'faker' emits faker.helpers.fromRegExp(pattern) and needs no extra dependency. 'randexp' emits new RandExp(pattern).gen(), which supports a wider regex grammar but adds the randexp runtime dependency.
locale
Faker locale code. It switches the named import to fakerXX from @faker-js/faker, so generated values reflect the target region. The default 'en' imports fakerEN, 'de' imports fakerDE, and 'de_AT' imports fakerDE_AT. See Faker.js localization for all locale codes.
seed
Value passed to faker.seed(...) and emitted at the top of each generated factory, giving deterministic output across runs for snapshot tests and reproducible local data. Pass a single number or an array of numbers.
include
Generates only the operations and schemas that match at least one entry, and skips the rest. Each entry filters by tag, operationId, path, method, contentType, or schemaName, with a pattern that can be a string or a RegExp, both matched as a regular expression against the value. A string pattern is compiled with new RegExp(pattern), so it is not an exact match: pattern: 'pet' also matches 'petType' or 'superpet'.
export type Include = {
type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType' | 'schemaName'
pattern: string | RegExp
}exclude
Skips any operation or schema that matches at least one entry, the opposite of include. Entries use the same type and pattern fields as include, and when both options match an item, exclude wins.
override
Applies different plugin options to operations that match a pattern. Each entry takes the same type and pattern as include, plus an options object that accepts any plugin option except override, so rules cannot nest. The first matching entry merges onto the plugin defaults, and later entries do not stack.
export type Override = {
type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType' | 'schemaName'
pattern: string | RegExp
options: Omit<Partial<Options>, 'override'>
}resolver
Changes how the plugin names generated files and symbols. Pass a partial patch: override only the members you want, and anything you omit keeps resolverFaker. See Override a resolver for the this context and how a patch layers over the default.
TIP
Inside a method this is the full resolver, so this.default.name(name) reuses the built-in casing.
type ResolverFakerPatch = {
name?(name: string): string
file?: {
baseName?(params: { name: string; extname: string }): string
path?(params: { baseName: string; output: Output }): string
}
param?: {
name?(node: OperationNode, param: ParameterNode): string // → 'showPetByIdPathPetId'
path?(node: OperationNode, param: ParameterNode): string // → 'createShowPetByIdPath'
query?(node: OperationNode, param: ParameterNode): string // → 'createListPetsQuery'
headers?(node: OperationNode, param: ParameterNode): string // → 'createDeletePetHeaders'
}
response?: {
status?(node: OperationNode, statusCode: StatusCode): string // → 'listPetsStatus200'
body?(node: OperationNode): string // → 'createPetsBody'
response?(node: OperationNode): string // → 'listPetsResponse'
responses?(node: OperationNode): string // → 'listPetsResponses'
}
}macros
Rewrites AST nodes before they are printed, without forking the generator. Each macro callback (such as schema or operation) receives the node and a context object, and returns a replacement or undefined to leave it as is. Omitted callbacks keep their defaults, and macros run in order, so a later one sees the output of an earlier one.
printer
Replaces the Faker node handler for a specific schema type, such as 'integer', 'date', or 'string'. Each handler returns the Faker expression as a string. Use this.transform to recurse into nested nodes and this.options to read printer options. The printer guide covers how overrides compose with macros.
import { pluginFaker } from '@kubb/plugin-faker'
pluginFaker({
printer: {
nodes: {
integer() {
return 'faker.number.float()'
},
},
},
})