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

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/dist/{Faker-SBhWTdC7.d.ts → Faker-BA4l8DTe.d.ts} +2 -2
  2. package/dist/{Faker-DBPx_MVh.js → Faker-DUx7jvCo.js} +10 -55
  3. package/dist/Faker-DUx7jvCo.js.map +1 -0
  4. package/dist/{Faker-DRL0W5Lt.cjs → Faker-Ds2xP2-k.cjs} +11 -62
  5. package/dist/Faker-Ds2xP2-k.cjs.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +1 -1
  8. package/dist/components.js +1 -1
  9. package/dist/{fakerGenerator-Duc28_FK.d.ts → fakerGenerator-BNysC6rh.d.ts} +2 -2
  10. package/dist/{fakerGenerator-CVOr0Pwm.cjs → fakerGenerator-BeKRKYuy.cjs} +26 -60
  11. package/dist/fakerGenerator-BeKRKYuy.cjs.map +1 -0
  12. package/dist/{fakerGenerator-DNJ61yLj.js → fakerGenerator-D5Bcy5WY.js} +25 -59
  13. package/dist/fakerGenerator-D5Bcy5WY.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +47 -44
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +47 -44
  21. package/dist/index.js.map +1 -1
  22. package/dist/{printerFaker-DXS861Q0.d.ts → printerFaker-BzEB43Jz.d.ts} +11 -15
  23. package/package.json +8 -16
  24. package/dist/Faker-DBPx_MVh.js.map +0 -1
  25. package/dist/Faker-DRL0W5Lt.cjs.map +0 -1
  26. package/dist/fakerGenerator-CVOr0Pwm.cjs.map +0 -1
  27. package/dist/fakerGenerator-DNJ61yLj.js.map +0 -1
  28. package/extension.yaml +0 -819
  29. package/src/components/Faker.tsx +0 -139
  30. package/src/components/index.ts +0 -1
  31. package/src/generators/fakerGenerator.tsx +0 -311
  32. package/src/generators/index.ts +0 -1
  33. package/src/index.ts +0 -7
  34. package/src/plugin.ts +0 -92
  35. package/src/printers/printerFaker.ts +0 -405
  36. package/src/resolvers/resolverFaker.ts +0 -84
  37. package/src/types.ts +0 -185
  38. package/src/utils.ts +0 -257
package/extension.yaml DELETED
@@ -1,819 +0,0 @@
1
- $schema: https://kubb.dev/schemas/extension.json
2
- kind: plugin
3
- id: plugin-faker
4
- name: Faker
5
- description: Generate Faker.js mock-data factories from OpenAPI for tests, Storybook, and seeded local data.
6
- category: mocks
7
- type: official
8
- npmPackage: '@kubb/plugin-faker'
9
- docsPath: /plugins/plugin-faker
10
- repo: https://github.com/kubb-labs/plugins
11
- maintainers:
12
- - name: Stijn Van Hulle
13
- github: stijnvanhulle
14
- compatibility:
15
- kubb: '>=5.0.0'
16
- node: '>=22'
17
- tags:
18
- - faker
19
- - mock-data
20
- - mocks
21
- - fixtures
22
- - testing
23
- - codegen
24
- - openapi
25
- dependencies:
26
- - plugin-ts
27
- resources:
28
- documentation: https://kubb.dev/plugins/plugin-faker
29
- repository: https://github.com/kubb-labs/plugins
30
- issues: https://github.com/kubb-labs/plugins/issues
31
- changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-faker/CHANGELOG.md
32
- codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/faker
33
- featured: false
34
- icon:
35
- light: https://kubb.dev/feature/faker.svg
36
- intro: |
37
- # @kubb/plugin-faker
38
-
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.
42
- options:
43
- - name: output
44
- type: Output
45
- required: false
46
- default: "{ path: 'mocks', barrel: { type: 'named' } }"
47
- description: Where the generated mock factories are written and how they are exported.
48
- properties:
49
- - name: path
50
- type: string
51
- required: true
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'`.
56
- tip: |
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
86
- default: "'mocks'"
87
- - name: barrel
88
- type: "{ type: 'named' | 'all', nested?: boolean } | false"
89
- required: false
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`.
98
- tip: |
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.
100
- examples:
101
- - name: "'named' (default)"
102
- files:
103
- - name: kubb.config.ts
104
- lang: typescript
105
- twoslash: false
106
- code: |
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
121
- twoslash: false
122
- code: |
123
- export { Pet, PetStatus } from './Pet'
124
- export { Store } from './Store'
125
- - name: "'all'"
126
- files:
127
- - name: kubb.config.ts
128
- lang: typescript
129
- twoslash: false
130
- code: |
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
145
- twoslash: false
146
- code: |
147
- export * from './Pet'
148
- export * from './Store'
149
- - name: nested
150
- files:
151
- - name: kubb.config.ts
152
- lang: typescript
153
- twoslash: 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'
180
- files:
181
- - name: kubb.config.ts
182
- lang: typescript
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.
203
- - name: banner
204
- type: 'string | ((node: RootNode) => string)'
205
- required: false
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
- })
261
- - name: footer
262
- type: 'string | ((node: RootNode) => string)'
263
- required: false
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
- })
290
- - name: override
291
- type: boolean
292
- required: false
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
- })
319
- - name: group
320
- type: Group
321
- required: false
322
- description: |
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.
328
- examples:
329
- - name: kubb.config.ts
330
- files:
331
- - lang: typescript
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
- })
349
- body: |
350
- With the configuration above, the generator emits:
351
-
352
- ```text
353
- src/gen/
354
- ├── petController/
355
- │ ├── AddPet.ts
356
- │ └── GetPet.ts
357
- └── storeController/
358
- ├── CreateStore.ts
359
- └── GetStoreById.ts
360
- ```
361
- properties:
362
- - name: type
363
- type: "'tag'"
364
- required: true
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.
369
- note: |
370
- `Required: true*` is conditional — only required when the parent `group` option is used. `group` itself stays optional.
371
- - name: name
372
- type: '(context: GroupContext) => string'
373
- required: false
374
- default: (ctx) => `${ctx.group}Controller`
375
- description: Function that builds the folder/identifier name from a group key (the operation's first tag).
376
- - name: dateParser
377
- type: "'faker' | 'dayjs' | 'moment' | string"
378
- required: false
379
- default: "'faker'"
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.
384
- tip: |
385
- Any library exporting a default function works (`dayjs`, `moment`, `luxon`, ...). Kubb adds the import statement for you.
386
- examples:
387
- - name: "'faker' (default)"
388
- files:
389
- - lang: typescript
390
- twoslash: false
391
- code: |
392
- faker.date.anytime().toISOString().substring(0, 10)
393
- - name: "'dayjs'"
394
- files:
395
- - lang: typescript
396
- twoslash: false
397
- code: |
398
- dayjs(faker.date.anytime()).format('YYYY-MM-DD')
399
- - name: "'moment'"
400
- files:
401
- - lang: typescript
402
- twoslash: false
403
- code: |
404
- moment(faker.date.anytime()).format('YYYY-MM-DD')
405
- - name: mapper
406
- type: Record<string, string>
407
- required: false
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
- })
431
- - name: paramsCasing
432
- type: "'camelcase'"
433
- required: false
434
- description: |
435
- Renames properties inside the generated path/query/header mocks. Body mocks are unaffected.
436
- important: |
437
- Set the same `paramsCasing` here as on `@kubb/plugin-ts` so the generated mocks stay assignable to the generated types.
438
- - name: regexGenerator
439
- type: "'faker' | 'randexp'"
440
- required: false
441
- default: "'faker'"
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.
447
- examples:
448
- - name: "'faker' (default)"
449
- files:
450
- - lang: typescript
451
- twoslash: false
452
- code: |
453
- faker.helpers.fromRegExp('^[A-Z]+$')
454
- - name: "'randexp'"
455
- files:
456
- - lang: typescript
457
- twoslash: false
458
- code: |
459
- new RandExp(/^[A-Z]+$/).gen()
460
- - name: seed
461
- type: number | number[]
462
- required: false
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
- })
481
- - name: locale
482
- type: string
483
- required: false
484
- default: "'en'"
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`.
489
- tip: |
490
- See [Faker.js localization](https://fakerjs.dev/api/localization.html) for the full list of locale codes.
491
- examples:
492
- - name: "'de'"
493
- files:
494
- - lang: typescript
495
- twoslash: false
496
- code: |
497
- import { fakerDE as faker } from '@faker-js/faker'
498
- - name: "'de_AT'"
499
- files:
500
- - lang: typescript
501
- twoslash: false
502
- code: |
503
- import { fakerDE_AT as faker } from '@faker-js/faker'
504
- - name: include
505
- type: Array<Include>
506
- required: false
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.
519
- codeBlock:
520
- lang: typescript
521
- title: Type definition
522
- code: |
523
- export type Include = {
524
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
525
- pattern: string | RegExp
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
- })
569
- - name: exclude
570
- type: Array<Exclude>
571
- required: false
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.
584
- codeBlock:
585
- lang: typescript
586
- title: Type definition
587
- code: |
588
- export type Exclude = {
589
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
590
- pattern: string | RegExp
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
- })
634
- - name: override
635
- type: Array<Override>
636
- required: false
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.
643
- codeBlock:
644
- lang: typescript
645
- title: Type definition
646
- code: |
647
- export type Override = {
648
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
649
- pattern: string | RegExp
650
- options: PluginOptions
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
- })
678
- - name: generators
679
- type: Array<Generator<PluginFaker>>
680
- required: false
681
- experimental: true
682
- description: |
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.
684
-
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.
688
- - name: resolver
689
- type: Partial<ResolverFaker>
690
- required: false
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.
693
- codeBlock:
694
- lang: typescript
695
- title: Append "Mock" to every factory name
696
- code: |
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
- ],
712
- })
713
- - name: transformer
714
- type: ast.Visitor
715
- required: false
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.
718
- codeBlock:
719
- lang: typescript
720
- title: Strip schema descriptions
721
- code: |
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
- ],
737
- })
738
- - name: printer
739
- type: '{ nodes?: PrinterFakerNodes }'
740
- required: false
741
- description: |
742
- Replaces the Faker handler for a specific schema type (e.g. `'integer'`, `'date'`, `'ref'`). Each handler returns the Faker expression as a string.
743
-
744
- Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
745
- examples:
746
- - name: Use faker.number.float() for integers
747
- files:
748
- - lang: typescript
749
- twoslash: false
750
- code: |
751
- import { defineConfig } from 'kubb'
752
- import { pluginFaker } from '@kubb/plugin-faker'
753
-
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
- },
765
- },
766
- }),
767
- ],
768
- })
769
- - name: Override date strings
770
- files:
771
- - lang: typescript
772
- twoslash: false
773
- code: |
774
- import { defineConfig } from 'kubb'
775
- import { pluginFaker } from '@kubb/plugin-faker'
776
-
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
- },
792
- },
793
- }),
794
- ],
795
- })
796
- examples:
797
- - name: kubb.config.ts
798
- files:
799
- - lang: typescript
800
- twoslash: false
801
- code: |
802
- import { defineConfig } from 'kubb'
803
- import { pluginFaker } from '@kubb/plugin-faker'
804
- import { pluginTs } from '@kubb/plugin-ts'
805
-
806
- export default defineConfig({
807
- input: { path: './petStore.yaml' },
808
- output: { path: './src/gen' },
809
- plugins: [
810
- pluginTs({
811
- output: { path: './types' },
812
- }),
813
- pluginFaker({
814
- output: { path: './mocks' },
815
- seed: [100],
816
- paramsCasing: 'camelcase',
817
- }),
818
- ],
819
- })