@kubb/plugin-faker 5.0.0-beta.4 → 5.0.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +39 -22
  2. package/dist/{Faker-fcQEB9i5.js → Faker-DBPx_MVh.js} +39 -101
  3. package/dist/Faker-DBPx_MVh.js.map +1 -0
  4. package/dist/{Faker-BgleOzVN.cjs → Faker-DRL0W5Lt.cjs} +37 -123
  5. package/dist/Faker-DRL0W5Lt.cjs.map +1 -0
  6. package/dist/{Faker-CdyPfOPg.d.ts → Faker-SBhWTdC7.d.ts} +3 -3
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +1 -1
  9. package/dist/components.js +1 -1
  10. package/dist/{fakerGenerator-VJEVzLjc.cjs → fakerGenerator-CVOr0Pwm.cjs} +237 -60
  11. package/dist/fakerGenerator-CVOr0Pwm.cjs.map +1 -0
  12. package/dist/{fakerGenerator-D7daHCh6.js → fakerGenerator-DNJ61yLj.js} +237 -60
  13. package/dist/fakerGenerator-DNJ61yLj.js.map +1 -0
  14. package/dist/fakerGenerator-Duc28_FK.d.ts +14 -0
  15. package/dist/generators.cjs +1 -1
  16. package/dist/generators.d.ts +1 -1
  17. package/dist/generators.js +1 -1
  18. package/dist/index.cjs +211 -43
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +35 -15
  21. package/dist/index.js +213 -45
  22. package/dist/index.js.map +1 -1
  23. package/dist/{printerFaker-CJiwzoto.d.ts → printerFaker-DXS861Q0.d.ts} +64 -27
  24. package/extension.yaml +590 -135
  25. package/package.json +9 -12
  26. package/src/components/Faker.tsx +50 -64
  27. package/src/generators/fakerGenerator.tsx +107 -67
  28. package/src/plugin.ts +26 -22
  29. package/src/printers/printerFaker.ts +80 -16
  30. package/src/resolvers/resolverFaker.ts +29 -37
  31. package/src/types.ts +36 -23
  32. package/src/utils.ts +6 -105
  33. package/dist/Faker-BgleOzVN.cjs.map +0 -1
  34. package/dist/Faker-fcQEB9i5.js.map +0 -1
  35. package/dist/fakerGenerator-C3Ho3BaI.d.ts +0 -9
  36. package/dist/fakerGenerator-D7daHCh6.js.map +0 -1
  37. package/dist/fakerGenerator-VJEVzLjc.cjs.map +0 -1
  38. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/extension.yaml CHANGED
@@ -2,18 +2,18 @@ $schema: https://kubb.dev/schemas/extension.json
2
2
  kind: plugin
3
3
  id: plugin-faker
4
4
  name: Faker
5
- description: Generate realistic mock data using Faker.js from OpenAPI specifications.
5
+ description: Generate Faker.js mock-data factories from OpenAPI for tests, Storybook, and seeded local data.
6
6
  category: mocks
7
7
  type: official
8
- npmPackage: "@kubb/plugin-faker"
8
+ npmPackage: '@kubb/plugin-faker'
9
9
  docsPath: /plugins/plugin-faker
10
10
  repo: https://github.com/kubb-labs/plugins
11
11
  maintainers:
12
12
  - name: Stijn Van Hulle
13
13
  github: stijnvanhulle
14
14
  compatibility:
15
- kubb: ">=5.0.0"
16
- node: ">=22"
15
+ kubb: '>=5.0.0'
16
+ node: '>=22'
17
17
  tags:
18
18
  - faker
19
19
  - mock-data
@@ -36,329 +36,784 @@ icon:
36
36
  intro: |
37
37
  # @kubb/plugin-faker
38
38
 
39
- Generate mock data factories from your OpenAPI schema using [Faker.js](https://fakerjs.dev/). Create realistic test data that matches your API's types.
39
+ Generate a mock-data factory function for every schema in your OpenAPI spec, powered by [Faker.js](https://fakerjs.dev/). Call `createPet()` to get a realistic `Pet` object useful for tests, Storybook, and local development without a running backend.
40
+
41
+ Pair with `@kubb/plugin-msw` to mock entire endpoints, or use the factories directly in your test suite.
40
42
  options:
41
43
  - name: output
42
44
  type: Output
43
45
  required: false
44
- default: "{ path: 'mocks', barrelType: 'named' }"
45
- description: Specify the export location for the files and define the behavior of the output.
46
+ default: "{ path: 'mocks', barrel: { type: 'named' } }"
47
+ description: Where the generated mock factories are written and how they are exported.
46
48
  properties:
47
49
  - name: path
48
50
  type: string
49
51
  required: true
50
- description: Output directory or file for the generated code, relative to the global `output.path`.
52
+ description: |
53
+ Folder (or single file) where the plugin writes its generated code. The path is resolved against the global `output.path` set on `defineConfig`.
54
+
55
+ Use a folder to keep each generator's output isolated (`'types'`, `'clients'`, `'hooks'`). Use a single file when you want everything in one place, for example `'api.ts'`.
51
56
  tip: |
52
- if `output.path` is a file, `group` cannot be used.
57
+ When `output.path` points to a single file, the `group` option cannot be used because every operation ends up in the same file.
58
+ examples:
59
+ - name: kubb.config.ts
60
+ files:
61
+ - lang: typescript
62
+ twoslash: false
63
+ code: |
64
+ import { defineConfig } from 'kubb'
65
+ import { pluginTs } from '@kubb/plugin-ts'
66
+
67
+ export default defineConfig({
68
+ input: { path: './petStore.yaml' },
69
+ output: { path: './src/gen' },
70
+ plugins: [
71
+ pluginTs({
72
+ output: { path: './types' },
73
+ }),
74
+ ],
75
+ })
76
+ - name: Resulting tree
77
+ files:
78
+ - lang: text
79
+ twoslash: false
80
+ code: |
81
+ src/
82
+ └── gen/
83
+ └── types/
84
+ ├── Pet.ts
85
+ └── Store.ts
53
86
  default: "'mocks'"
54
- - name: barrelType
55
- type: "'all' | 'named' | 'propagate' | false"
87
+ - name: barrel
88
+ type: "{ type: 'named' | 'all', nested?: boolean } | false"
56
89
  required: false
57
- default: "'named'"
58
- description: Specify what to export and optionally disable barrel-file generation.
90
+ default: "{ type: 'named' }"
91
+ description: |
92
+ Controls how the generated `index.ts` (barrel) file re-exports the plugin's output.
93
+
94
+ - `{ type: 'named' }` re-exports each symbol by name. Best for tree-shaking and explicit imports.
95
+ - `{ type: 'all' }` uses `export *`. Smaller barrel file, but exports everything.
96
+ - `{ nested: true }` creates a barrel in every subdirectory, so callers can import from any depth.
97
+ - `false` skips the barrel entirely. The plugin's files are also excluded from the root `index.ts`.
59
98
  tip: |
60
- Using `propagate` will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](https://kubb.dev/docs/5.x/configuration#output-barreltype) to export the specific function or type.
99
+ Pick `'named'` when consumers care about which symbols they import (better tree-shaking, friendlier auto-import). Pick `'all'` when the file count is small and you want a one-line barrel.
61
100
  examples:
62
- - name: all
101
+ - name: "'named' (default)"
63
102
  files:
64
- - lang: typescript
103
+ - name: kubb.config.ts
104
+ lang: typescript
105
+ twoslash: false
65
106
  code: |
66
- export * from './gen/petService.ts'
107
+ import { defineConfig } from 'kubb'
108
+ import { pluginTs } from '@kubb/plugin-ts'
109
+
110
+ export default defineConfig({
111
+ input: { path: './petStore.yaml' },
112
+ output: { path: './src/gen' },
113
+ plugins: [
114
+ pluginTs({
115
+ output: { barrel: { type: 'named' } },
116
+ }),
117
+ ],
118
+ })
119
+ - name: src/gen/types/index.ts
120
+ lang: typescript
67
121
  twoslash: false
68
- - name: named
122
+ code: |
123
+ export { Pet, PetStatus } from './Pet'
124
+ export { Store } from './Store'
125
+ - name: "'all'"
69
126
  files:
70
- - lang: typescript
127
+ - name: kubb.config.ts
128
+ lang: typescript
129
+ twoslash: false
71
130
  code: |
72
- export { PetService } from './gen/petService.ts'
131
+ import { defineConfig } from 'kubb'
132
+ import { pluginTs } from '@kubb/plugin-ts'
133
+
134
+ export default defineConfig({
135
+ input: { path: './petStore.yaml' },
136
+ output: { path: './src/gen' },
137
+ plugins: [
138
+ pluginTs({
139
+ output: { barrel: { type: 'all' } },
140
+ }),
141
+ ],
142
+ })
143
+ - name: src/gen/types/index.ts
144
+ lang: typescript
73
145
  twoslash: false
74
- - name: propagate
146
+ code: |
147
+ export * from './Pet'
148
+ export * from './Store'
149
+ - name: nested
75
150
  files:
76
- - lang: typescript
77
- code: ""
151
+ - name: kubb.config.ts
152
+ lang: typescript
78
153
  twoslash: false
79
- - name: "false"
154
+ code: |
155
+ import { defineConfig } from 'kubb'
156
+ import { pluginTs } from '@kubb/plugin-ts'
157
+
158
+ export default defineConfig({
159
+ input: { path: './petStore.yaml' },
160
+ output: { path: './src/gen' },
161
+ plugins: [
162
+ pluginTs({
163
+ output: { barrel: { type: 'named', nested: true } },
164
+ }),
165
+ ],
166
+ })
167
+ - name: Generated tree
168
+ lang: text
169
+ twoslash: false
170
+ code: |
171
+ src/gen/types/
172
+ ├── index.ts # re-exports ./petController and ./storeController
173
+ ├── petController/
174
+ │ ├── index.ts # re-exports Pet, Store, ...
175
+ │ └── Pet.ts
176
+ └── storeController/
177
+ ├── index.ts
178
+ └── Store.ts
179
+ - name: 'false'
80
180
  files:
81
- - lang: typescript
82
- code: ""
181
+ - name: kubb.config.ts
182
+ lang: typescript
83
183
  twoslash: false
184
+ code: |
185
+ import { defineConfig } from 'kubb'
186
+ import { pluginTs } from '@kubb/plugin-ts'
187
+
188
+ export default defineConfig({
189
+ input: { path: './petStore.yaml' },
190
+ output: { path: './src/gen' },
191
+ plugins: [
192
+ pluginTs({
193
+ output: { barrel: false },
194
+ }),
195
+ ],
196
+ })
197
+ - name: Result
198
+ lang: text
199
+ twoslash: false
200
+ code: |
201
+ # No index.ts is generated for this plugin.
202
+ # Its files are also excluded from the root index.ts.
84
203
  - name: banner
85
- type: "string | ((node: RootNode) => string)"
204
+ type: 'string | ((node: RootNode) => string)'
86
205
  required: false
87
- description: Add a banner comment at the top of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
206
+ description: |
207
+ Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives.
208
+
209
+ Pass a string for a static banner. Pass a function to compute the banner from each file's `RootNode` (the AST root containing path, schema, and operation context).
210
+ examples:
211
+ - name: Static banner
212
+ files:
213
+ - name: kubb.config.ts
214
+ lang: typescript
215
+ twoslash: false
216
+ code: |
217
+ import { defineConfig } from 'kubb'
218
+ import { pluginTs } from '@kubb/plugin-ts'
219
+
220
+ export default defineConfig({
221
+ input: { path: './petStore.yaml' },
222
+ output: { path: './src/gen' },
223
+ plugins: [
224
+ pluginTs({
225
+ output: {
226
+ banner: '/* eslint-disable */\n// @ts-nocheck',
227
+ },
228
+ }),
229
+ ],
230
+ })
231
+ - name: Generated file
232
+ lang: typescript
233
+ twoslash: false
234
+ code: |
235
+ /* eslint-disable */
236
+ // @ts-nocheck
237
+ export type Pet = {
238
+ id: number
239
+ name: string
240
+ }
241
+ - name: Dynamic banner
242
+ files:
243
+ - name: kubb.config.ts
244
+ lang: typescript
245
+ twoslash: false
246
+ code: |
247
+ import { defineConfig } from 'kubb'
248
+ import { pluginTs } from '@kubb/plugin-ts'
249
+
250
+ export default defineConfig({
251
+ input: { path: './petStore.yaml' },
252
+ output: { path: './src/gen' },
253
+ plugins: [
254
+ pluginTs({
255
+ output: {
256
+ banner: (node) => `// Source: ${node.path}\n// Generated at ${new Date().toISOString()}`,
257
+ },
258
+ }),
259
+ ],
260
+ })
88
261
  - name: footer
89
- type: "string | ((node: RootNode) => string)"
262
+ type: 'string | ((node: RootNode) => string)'
90
263
  required: false
91
- description: Add a footer comment at the end of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
264
+ description: |
265
+ Text appended at the end of every generated file. The mirror of `banner` — use it for closing comments, re-enabling lint rules, or marker lines.
266
+
267
+ Pass a string for a static footer, or a function that receives the file's `RootNode` and returns the footer text.
268
+ examples:
269
+ - name: Re-enable lint after a banner disable
270
+ files:
271
+ - name: kubb.config.ts
272
+ lang: typescript
273
+ twoslash: false
274
+ code: |
275
+ import { defineConfig } from 'kubb'
276
+ import { pluginTs } from '@kubb/plugin-ts'
277
+
278
+ export default defineConfig({
279
+ input: { path: './petStore.yaml' },
280
+ output: { path: './src/gen' },
281
+ plugins: [
282
+ pluginTs({
283
+ output: {
284
+ banner: '/* eslint-disable */',
285
+ footer: '/* eslint-enable */',
286
+ },
287
+ }),
288
+ ],
289
+ })
92
290
  - name: override
93
291
  type: boolean
94
292
  required: false
95
- default: "false"
96
- description: Whether Kubb overrides existing external files that can be generated if they already exist.
293
+ default: 'false'
294
+ description: |
295
+ Allows the plugin to overwrite hand-written files that share a name with a generated file.
296
+
297
+ - `false` (default): Kubb skips a file if it already exists and is not marked as generated. This protects manual edits.
298
+ - `true`: Kubb overwrites any file at the target path, including hand-written ones.
299
+ warning: |
300
+ Enable this only when you are sure the target folder contains nothing you need to keep. Local edits are lost on the next generation.
301
+ examples:
302
+ - name: kubb.config.ts
303
+ files:
304
+ - lang: typescript
305
+ twoslash: false
306
+ code: |
307
+ import { defineConfig } from 'kubb'
308
+ import { pluginTs } from '@kubb/plugin-ts'
309
+
310
+ export default defineConfig({
311
+ input: { path: './petStore.yaml' },
312
+ output: { path: './src/gen' },
313
+ plugins: [
314
+ pluginTs({
315
+ output: { override: true },
316
+ }),
317
+ ],
318
+ })
97
319
  - name: group
98
320
  type: Group
99
321
  required: false
100
322
  description: |
101
- Grouping combines files in a folder based on a specific `type`.
323
+ Splits generated files into subfolders based on the operation's tag, so each tag in your OpenAPI spec gets its own directory.
324
+
325
+ Without `group`, every file lands in the plugin's `output.path` folder. With `group`, files are bucketed under `{output.path}/{groupName}/`, where `groupName` is derived from the operation's first tag.
326
+ tip: |
327
+ Use `group` to mirror your API's domain structure (pet, store, user) in the generated code. Combine it with `output.barrel: { type: 'named', nested: true }` to get per-tag barrel files.
102
328
  examples:
103
329
  - name: kubb.config.ts
104
330
  files:
105
331
  - lang: typescript
106
- code: |
107
- group: {
108
- type: 'tag',
109
- name({ group }) {
110
- return `${group}Controller`
111
- }
112
- }
113
332
  twoslash: false
333
+ code: |
334
+ import { defineConfig } from 'kubb'
335
+ import { pluginTs } from '@kubb/plugin-ts'
336
+
337
+ export default defineConfig({
338
+ input: { path: './petStore.yaml' },
339
+ output: { path: './src/gen' },
340
+ plugins: [
341
+ pluginTs({
342
+ group: {
343
+ type: 'tag',
344
+ name: ({ group }) => `${group}Controller`,
345
+ },
346
+ }),
347
+ ],
348
+ })
114
349
  body: |
115
350
  With the configuration above, the generator emits:
116
351
 
117
352
  ```text
118
- .
119
- ├── src/
120
- └── petController/
121
- │ ├── addPet.ts
122
- │ │ └── getPet.ts
123
- │ └── storeController/
124
- │ ├── createStore.ts
125
- │ └── getStoreById.ts
126
- ├── petStore.yaml
127
- ├── kubb.config.ts
128
- └── package.json
353
+ src/gen/
354
+ ├── petController/
355
+ ├── AddPet.ts
356
+ └── GetPet.ts
357
+ └── storeController/
358
+ ├── CreateStore.ts
359
+ └── GetStoreById.ts
129
360
  ```
130
361
  properties:
131
362
  - name: type
132
363
  type: "'tag'"
133
364
  required: true
134
- description: Specify the property to group files by. Required when `group` is defined.
365
+ description: |
366
+ Property used to assign each operation to a group. Required whenever `group` is set.
367
+
368
+ Today only `'tag'` is supported: Kubb reads the first tag on the operation (`operation.getTags().at(0)?.name`) and uses it as the group key. Operations without a tag are placed in a default group.
135
369
  note: |
136
- `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
137
- body: |
138
- - `'tag'`: Uses the first tag from `operation.getTags().at(0)?.name`
370
+ `Required: true*` is conditional only required when the parent `group` option is used. `group` itself stays optional.
139
371
  - name: name
140
- type: "(context: GroupContext) => string"
372
+ type: '(context: GroupContext) => string'
141
373
  required: false
142
374
  default: (ctx) => `${ctx.group}Controller`
143
- description: Return the name of a group based on the group name. This is used for file and helper name generation.
375
+ description: Function that builds the folder/identifier name from a group key (the operation's first tag).
144
376
  - name: dateParser
145
377
  type: "'faker' | 'dayjs' | 'moment' | string"
146
378
  required: false
147
379
  default: "'faker'"
148
- description: Choose which formatter to use for `date`, `time`, or `datetime` fields represented as strings.
380
+ description: |
381
+ Library used to format `date`, `time`, and `datetime` fields that are represented as strings.
382
+
383
+ Use a value other than `'faker'` when you already have a date library in the project and want consistent formatting across mocks and runtime. The plugin auto-imports the default export of the library you choose.
149
384
  tip: |
150
- You can use another library that exposes a default export. Kubb adds the import automatically.
385
+ Any library exporting a default function works (`dayjs`, `moment`, `luxon`, ...). Kubb adds the import statement for you.
151
386
  examples:
152
- - name: "'faker'"
387
+ - name: "'faker' (default)"
153
388
  files:
154
- - lang: ts
389
+ - lang: typescript
390
+ twoslash: false
155
391
  code: |
156
392
  faker.date.anytime().toISOString().substring(0, 10)
157
393
  - name: "'dayjs'"
158
394
  files:
159
- - lang: ts
395
+ - lang: typescript
396
+ twoslash: false
160
397
  code: |
161
398
  dayjs(faker.date.anytime()).format('YYYY-MM-DD')
162
399
  - name: "'moment'"
163
400
  files:
164
- - lang: ts
401
+ - lang: typescript
402
+ twoslash: false
165
403
  code: |
166
404
  moment(faker.date.anytime()).format('YYYY-MM-DD')
167
405
  - name: mapper
168
406
  type: Record<string, string>
169
407
  required: false
170
- description: Override individual properties with custom Faker expressions.
408
+ description: |
409
+ Maps OpenAPI schema names to specific Faker expressions. Use this when the schema name does not give Faker enough context to pick a sensible value (`'email'`, `'phone'`, `'avatarUrl'`).
410
+
411
+ Keys are the schema name (case-sensitive); values are the JavaScript expression that produces the mock value.
412
+ codeBlock:
413
+ lang: typescript
414
+ title: kubb.config.ts
415
+ code: |
416
+ import { defineConfig } from 'kubb'
417
+ import { pluginFaker } from '@kubb/plugin-faker'
418
+
419
+ export default defineConfig({
420
+ input: { path: './petStore.yaml' },
421
+ output: { path: './src/gen' },
422
+ plugins: [
423
+ pluginFaker({
424
+ mapper: {
425
+ email: 'faker.internet.email()',
426
+ avatarUrl: 'faker.image.avatar()',
427
+ },
428
+ }),
429
+ ],
430
+ })
171
431
  - name: paramsCasing
172
432
  type: "'camelcase'"
173
433
  required: false
174
- description: Transform parameter property names in generated mocks for path, query, and headers.
434
+ description: |
435
+ Renames properties inside the generated path/query/header mocks. Body mocks are unaffected.
175
436
  important: |
176
- Use the same `paramsCasing` value in `@kubb/plugin-ts` so the generated mock objects stay compatible with the generated types.
437
+ Set the same `paramsCasing` here as on `@kubb/plugin-ts` so the generated mocks stay assignable to the generated types.
177
438
  - name: regexGenerator
178
439
  type: "'faker' | 'randexp'"
179
440
  required: false
180
441
  default: "'faker'"
181
- description: Generate strings from regex patterns using Faker or randexp.
442
+ description: |
443
+ Library used to generate strings that satisfy a regex `pattern` keyword in the OpenAPI spec.
444
+
445
+ - `'faker'` (default) — `faker.helpers.fromRegExp(...)`. No extra dependency.
446
+ - `'randexp'` — uses the `randexp` package, which supports a wider regex grammar (lookaheads, named groups) but adds a runtime dependency.
182
447
  examples:
183
- - name: "'faker'"
448
+ - name: "'faker' (default)"
184
449
  files:
185
- - lang: ts
450
+ - lang: typescript
451
+ twoslash: false
186
452
  code: |
187
453
  faker.helpers.fromRegExp('^[A-Z]+$')
188
454
  - name: "'randexp'"
189
455
  files:
190
- - lang: ts
456
+ - lang: typescript
457
+ twoslash: false
191
458
  code: |
192
459
  new RandExp(/^[A-Z]+$/).gen()
193
460
  - name: seed
194
461
  type: number | number[]
195
462
  required: false
196
- description: Seed faker for deterministic output.
463
+ description: |
464
+ Seed value passed to `faker.seed(...)`. Set this to get deterministic output across runs — handy for snapshot tests and reproducible local data.
465
+ examples:
466
+ - name: Deterministic seed
467
+ files:
468
+ - lang: typescript
469
+ twoslash: false
470
+ code: |
471
+ import { defineConfig } from 'kubb'
472
+ import { pluginFaker } from '@kubb/plugin-faker'
473
+
474
+ export default defineConfig({
475
+ input: { path: './petStore.yaml' },
476
+ output: { path: './src/gen' },
477
+ plugins: [
478
+ pluginFaker({ seed: 100 }),
479
+ ],
480
+ })
197
481
  - name: locale
198
482
  type: string
199
483
  required: false
200
484
  default: "'en'"
201
- description: Generate mock data using a locale-specific Faker instance.
485
+ description: |
486
+ Faker locale used for generated mock values. Switches the named import to `fakerXX` from `@faker-js/faker` so names, addresses, and phone numbers reflect the target region.
487
+
488
+ Defaults to `'en'`, which imports `fakerEN`.
202
489
  tip: |
203
- See the [Faker.js localization docs](https://fakerjs.dev/api/localization.html) for the full list of supported locales.
490
+ See [Faker.js localization](https://fakerjs.dev/api/localization.html) for the full list of locale codes.
204
491
  examples:
205
492
  - name: "'de'"
206
493
  files:
207
- - lang: ts
494
+ - lang: typescript
495
+ twoslash: false
208
496
  code: |
209
497
  import { fakerDE as faker } from '@faker-js/faker'
210
498
  - name: "'de_AT'"
211
499
  files:
212
- - lang: ts
500
+ - lang: typescript
501
+ twoslash: false
213
502
  code: |
214
503
  import { fakerDE_AT as faker } from '@faker-js/faker'
215
504
  - name: include
216
505
  type: Array<Include>
217
506
  required: false
218
- description: Array containing include parameters to include tags, operations, methods, paths, or content types.
507
+ description: |
508
+ Restricts generation to operations that match at least one entry in the list. Anything not matched is skipped.
509
+
510
+ Each entry filters by one of:
511
+
512
+ - `tag` — the operation's first tag in the OpenAPI spec.
513
+ - `operationId` — the operation's `operationId`.
514
+ - `path` — the URL pattern (`'/pet/{petId}'`).
515
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
516
+ - `contentType` — the media type of the request body.
517
+
518
+ `pattern` accepts either a string (exact match) or a `RegExp` for fuzzy matches.
219
519
  codeBlock:
220
520
  lang: typescript
221
- title: Include
521
+ title: Type definition
222
522
  code: |
223
523
  export type Include = {
224
524
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
225
525
  pattern: string | RegExp
226
526
  }
527
+ examples:
528
+ - name: Only the pet tag
529
+ files:
530
+ - name: kubb.config.ts
531
+ lang: typescript
532
+ twoslash: false
533
+ code: |
534
+ import { defineConfig } from 'kubb'
535
+ import { pluginTs } from '@kubb/plugin-ts'
536
+
537
+ export default defineConfig({
538
+ input: { path: './petStore.yaml' },
539
+ output: { path: './src/gen' },
540
+ plugins: [
541
+ pluginTs({
542
+ include: [
543
+ { type: 'tag', pattern: 'pet' },
544
+ ],
545
+ }),
546
+ ],
547
+ })
548
+ - name: Only GET operations under /pet
549
+ files:
550
+ - name: kubb.config.ts
551
+ lang: typescript
552
+ twoslash: false
553
+ code: |
554
+ import { defineConfig } from 'kubb'
555
+ import { pluginTs } from '@kubb/plugin-ts'
556
+
557
+ export default defineConfig({
558
+ input: { path: './petStore.yaml' },
559
+ output: { path: './src/gen' },
560
+ plugins: [
561
+ pluginTs({
562
+ include: [
563
+ { type: 'method', pattern: 'get' },
564
+ { type: 'path', pattern: /^\/pet/ },
565
+ ],
566
+ }),
567
+ ],
568
+ })
227
569
  - name: exclude
228
570
  type: Array<Exclude>
229
571
  required: false
230
- description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
572
+ description: |
573
+ Skips any operation that matches at least one entry in the list. The opposite of `include`.
574
+
575
+ Each entry filters by one of:
576
+
577
+ - `tag` — the operation's first tag.
578
+ - `operationId` — the operation's `operationId`.
579
+ - `path` — the URL pattern (`'/pet/{petId}'`).
580
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
581
+ - `contentType` — the media type of the request body.
582
+
583
+ `pattern` accepts a plain string or a `RegExp`. When both `include` and `exclude` are set, `exclude` wins.
231
584
  codeBlock:
232
585
  lang: typescript
233
- title: Exclude
586
+ title: Type definition
234
587
  code: |
235
588
  export type Exclude = {
236
589
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
237
590
  pattern: string | RegExp
238
591
  }
592
+ examples:
593
+ - name: Skip everything under the store tag
594
+ files:
595
+ - name: kubb.config.ts
596
+ lang: typescript
597
+ twoslash: false
598
+ code: |
599
+ import { defineConfig } from 'kubb'
600
+ import { pluginTs } from '@kubb/plugin-ts'
601
+
602
+ export default defineConfig({
603
+ input: { path: './petStore.yaml' },
604
+ output: { path: './src/gen' },
605
+ plugins: [
606
+ pluginTs({
607
+ exclude: [
608
+ { type: 'tag', pattern: 'store' },
609
+ ],
610
+ }),
611
+ ],
612
+ })
613
+ - name: Skip a specific operation and all delete methods
614
+ files:
615
+ - name: kubb.config.ts
616
+ lang: typescript
617
+ twoslash: false
618
+ code: |
619
+ import { defineConfig } from 'kubb'
620
+ import { pluginTs } from '@kubb/plugin-ts'
621
+
622
+ export default defineConfig({
623
+ input: { path: './petStore.yaml' },
624
+ output: { path: './src/gen' },
625
+ plugins: [
626
+ pluginTs({
627
+ exclude: [
628
+ { type: 'operationId', pattern: 'deletePet' },
629
+ { type: 'method', pattern: 'delete' },
630
+ ],
631
+ }),
632
+ ],
633
+ })
239
634
  - name: override
240
635
  type: Array<Override>
241
636
  required: false
242
- description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
637
+ description: |
638
+ Applies a different set of plugin options to operations that match a pattern. Use this when most of your API should follow the global config, but a handful of endpoints need different treatment.
639
+
640
+ Each entry has the same `type` and `pattern` shape as `include`/`exclude`, plus an `options` object that overrides the plugin's options for matched operations.
641
+
642
+ Entries are evaluated top to bottom. The first matching entry's `options` is merged onto the plugin defaults; later entries do not stack.
243
643
  codeBlock:
244
644
  lang: typescript
245
- title: Override
645
+ title: Type definition
246
646
  code: |
247
647
  export type Override = {
248
648
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
249
649
  pattern: string | RegExp
250
650
  options: PluginOptions
251
651
  }
652
+ examples:
653
+ - name: Use a different enum style for the user tag
654
+ files:
655
+ - name: kubb.config.ts
656
+ lang: typescript
657
+ twoslash: false
658
+ code: |
659
+ import { defineConfig } from 'kubb'
660
+ import { pluginTs } from '@kubb/plugin-ts'
661
+
662
+ export default defineConfig({
663
+ input: { path: './petStore.yaml' },
664
+ output: { path: './src/gen' },
665
+ plugins: [
666
+ pluginTs({
667
+ enumType: 'asConst',
668
+ override: [
669
+ {
670
+ type: 'tag',
671
+ pattern: 'user',
672
+ options: { enumType: 'literal' },
673
+ },
674
+ ],
675
+ }),
676
+ ],
677
+ })
252
678
  - name: generators
253
679
  type: Array<Generator<PluginFaker>>
254
680
  required: false
255
681
  experimental: true
256
682
  description: |
257
- Define additional generators next to the built-in generators.
683
+ Adds custom generators that run alongside the plugin's built-in generators. Each generator can emit additional files or post-process existing ones using the plugin's AST and options.
258
684
 
259
- See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
685
+ Use this when you need output the plugin does not produce out of the box (a custom client wrapper, an extra index, a metadata file). For end-to-end guidance, see [Creating plugins](https://kubb.dev/docs/5.x/guides/creating-plugins).
686
+ warning: |
687
+ Generators are an experimental, low-level API. The signature may change between minor releases.
260
688
  - name: resolver
261
689
  type: Partial<ResolverFaker>
262
690
  required: false
263
- description: Customize helper naming on top of the active compatibility preset.
691
+ description: |
692
+ Customizes the naming of the generated factory helpers. Common use case: append `Mock` or `Factory` so the helpers do not clash with the imported types.
264
693
  codeBlock:
265
694
  lang: typescript
695
+ title: Append "Mock" to every factory name
266
696
  code: |
267
- pluginFaker({
268
- resolver: {
269
- resolveName(name) {
270
- return `${this.default(name)}Mock`
271
- },
272
- },
697
+ import { defineConfig } from 'kubb'
698
+ import { pluginFaker } from '@kubb/plugin-faker'
699
+
700
+ export default defineConfig({
701
+ input: { path: './petStore.yaml' },
702
+ output: { path: './src/gen' },
703
+ plugins: [
704
+ pluginFaker({
705
+ resolver: {
706
+ resolveName(name) {
707
+ return `${this.default(name)}Mock`
708
+ },
709
+ },
710
+ }),
711
+ ],
273
712
  })
274
713
  - name: transformer
275
714
  type: ast.Visitor
276
715
  required: false
277
- description: Apply a single AST visitor before the faker helpers are rendered.
716
+ description: |
717
+ AST visitor applied to schema/operation nodes before code is printed. Use this to drop descriptions or rewrite metadata before the mock factory is built.
278
718
  codeBlock:
279
719
  lang: typescript
720
+ title: Strip schema descriptions
280
721
  code: |
281
- pluginFaker({
282
- transformer: {
283
- schema(node) {
284
- return { ...node, description: undefined }
285
- },
286
- },
722
+ import { defineConfig } from 'kubb'
723
+ import { pluginFaker } from '@kubb/plugin-faker'
724
+
725
+ export default defineConfig({
726
+ input: { path: './petStore.yaml' },
727
+ output: { path: './src/gen' },
728
+ plugins: [
729
+ pluginFaker({
730
+ transformer: {
731
+ schema(node) {
732
+ return { ...node, description: undefined }
733
+ },
734
+ },
735
+ }),
736
+ ],
287
737
  })
288
738
  - name: printer
289
- type: "{ nodes?: PrinterFakerNodes }"
739
+ type: '{ nodes?: PrinterFakerNodes }'
290
740
  required: false
291
741
  description: |
292
- Override individual printer node handlers to customize how specific schema types are rendered.
742
+ Replaces the Faker handler for a specific schema type (e.g. `'integer'`, `'date'`, `'ref'`). Each handler returns the Faker expression as a string.
293
743
 
294
- Each key is a `SchemaType` (for example `'integer'`, `'date'`, or `'ref'`). The function you provide replaces the built-in handler for that type. Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
744
+ Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
295
745
  examples:
296
- - name: Override integer to float()
746
+ - name: Use faker.number.float() for integers
297
747
  files:
298
748
  - lang: typescript
749
+ twoslash: false
299
750
  code: |
751
+ import { defineConfig } from 'kubb'
300
752
  import { pluginFaker } from '@kubb/plugin-faker'
301
753
 
302
- pluginFaker({
303
- printer: {
304
- nodes: {
305
- integer() {
306
- return 'faker.number.float()'
754
+ export default defineConfig({
755
+ input: { path: './petStore.yaml' },
756
+ output: { path: './src/gen' },
757
+ plugins: [
758
+ pluginFaker({
759
+ printer: {
760
+ nodes: {
761
+ integer() {
762
+ return 'faker.number.float()'
763
+ },
764
+ },
307
765
  },
308
- },
309
- },
766
+ }),
767
+ ],
310
768
  })
311
- twoslash: false
312
769
  - name: Override date strings
313
770
  files:
314
771
  - lang: typescript
772
+ twoslash: false
315
773
  code: |
774
+ import { defineConfig } from 'kubb'
316
775
  import { pluginFaker } from '@kubb/plugin-faker'
317
776
 
318
- pluginFaker({
319
- printer: {
320
- nodes: {
321
- date(node) {
322
- if (node.representation === 'string') {
323
- return 'new Date().toISOString().substring(0, 10)'
324
- }
325
-
326
- return 'new Date()'
777
+ export default defineConfig({
778
+ input: { path: './petStore.yaml' },
779
+ output: { path: './src/gen' },
780
+ plugins: [
781
+ pluginFaker({
782
+ printer: {
783
+ nodes: {
784
+ date(node) {
785
+ if (node.representation === 'string') {
786
+ return 'new Date().toISOString().substring(0, 10)'
787
+ }
788
+
789
+ return 'new Date()'
790
+ },
791
+ },
327
792
  },
328
- },
329
- },
793
+ }),
794
+ ],
330
795
  })
331
- twoslash: false
332
796
  examples:
333
797
  - name: kubb.config.ts
334
798
  files:
335
799
  - lang: typescript
800
+ twoslash: false
336
801
  code: |
337
802
  import { defineConfig } from 'kubb'
338
803
  import { pluginFaker } from '@kubb/plugin-faker'
339
804
  import { pluginTs } from '@kubb/plugin-ts'
340
805
 
341
806
  export default defineConfig({
342
- input: {
343
- path: './petStore.yaml',
344
- },
345
- output: {
346
- path: './src/gen',
347
- },
807
+ input: { path: './petStore.yaml' },
808
+ output: { path: './src/gen' },
348
809
  plugins: [
349
810
  pluginTs({
350
- output: {
351
- path: './types',
352
- },
811
+ output: { path: './types' },
353
812
  }),
354
813
  pluginFaker({
355
- output: {
356
- path: './mocks',
357
- barrelType: 'named',
358
- },
814
+ output: { path: './mocks' },
359
815
  seed: [100],
360
816
  paramsCasing: 'camelcase',
361
817
  }),
362
818
  ],
363
819
  })
364
- twoslash: false