@kubb/plugin-faker 5.0.0-beta.3 → 5.0.0-beta.31

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 (37) hide show
  1. package/README.md +26 -5
  2. package/dist/{Faker-CdyPfOPg.d.ts → Faker-BaLJxPyl.d.ts} +2 -2
  3. package/dist/{Faker-fcQEB9i5.js → Faker-DwIc_lta.js} +38 -100
  4. package/dist/Faker-DwIc_lta.js.map +1 -0
  5. package/dist/{Faker-BgleOzVN.cjs → Faker-XuyEQflW.cjs} +37 -123
  6. package/dist/Faker-XuyEQflW.cjs.map +1 -0
  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-BBr2WsG8.cjs} +236 -60
  11. package/dist/fakerGenerator-BBr2WsG8.cjs.map +1 -0
  12. package/dist/{fakerGenerator-D7daHCh6.js → fakerGenerator-BDNxA7KY.js} +235 -59
  13. package/dist/fakerGenerator-BDNxA7KY.js.map +1 -0
  14. package/dist/fakerGenerator-DSvAJTq3.d.ts +15 -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 +213 -42
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +33 -12
  21. package/dist/index.js +214 -43
  22. package/dist/index.js.map +1 -1
  23. package/dist/{printerFaker-CJiwzoto.d.ts → printerFaker-Bhwq62d1.d.ts} +63 -26
  24. package/extension.yaml +817 -0
  25. package/package.json +9 -13
  26. package/src/components/Faker.tsx +50 -64
  27. package/src/generators/fakerGenerator.tsx +107 -67
  28. package/src/plugin.ts +25 -21
  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
package/extension.yaml ADDED
@@ -0,0 +1,817 @@
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`.
487
+ tip: |
488
+ See [Faker.js localization](https://fakerjs.dev/api/localization.html) for the full list of locale codes.
489
+ examples:
490
+ - name: "'de'"
491
+ files:
492
+ - lang: typescript
493
+ twoslash: false
494
+ code: |
495
+ import { fakerDE as faker } from '@faker-js/faker'
496
+ - name: "'de_AT'"
497
+ files:
498
+ - lang: typescript
499
+ twoslash: false
500
+ code: |
501
+ import { fakerDE_AT as faker } from '@faker-js/faker'
502
+ - name: include
503
+ type: Array<Include>
504
+ required: false
505
+ description: |
506
+ Restricts generation to operations that match at least one entry in the list. Anything not matched is skipped.
507
+
508
+ Each entry filters by one of:
509
+
510
+ - `tag` — the operation's first tag in the OpenAPI spec.
511
+ - `operationId` — the operation's `operationId`.
512
+ - `path` — the URL pattern (`'/pet/{petId}'`).
513
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
514
+ - `contentType` — the media type of the request body.
515
+
516
+ `pattern` accepts either a string (exact match) or a `RegExp` for fuzzy matches.
517
+ codeBlock:
518
+ lang: typescript
519
+ title: Type definition
520
+ code: |
521
+ export type Include = {
522
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
523
+ pattern: string | RegExp
524
+ }
525
+ examples:
526
+ - name: Only the pet tag
527
+ files:
528
+ - name: kubb.config.ts
529
+ lang: typescript
530
+ twoslash: false
531
+ code: |
532
+ import { defineConfig } from 'kubb'
533
+ import { pluginTs } from '@kubb/plugin-ts'
534
+
535
+ export default defineConfig({
536
+ input: { path: './petStore.yaml' },
537
+ output: { path: './src/gen' },
538
+ plugins: [
539
+ pluginTs({
540
+ include: [
541
+ { type: 'tag', pattern: 'pet' },
542
+ ],
543
+ }),
544
+ ],
545
+ })
546
+ - name: Only GET operations under /pet
547
+ files:
548
+ - name: kubb.config.ts
549
+ lang: typescript
550
+ twoslash: false
551
+ code: |
552
+ import { defineConfig } from 'kubb'
553
+ import { pluginTs } from '@kubb/plugin-ts'
554
+
555
+ export default defineConfig({
556
+ input: { path: './petStore.yaml' },
557
+ output: { path: './src/gen' },
558
+ plugins: [
559
+ pluginTs({
560
+ include: [
561
+ { type: 'method', pattern: 'get' },
562
+ { type: 'path', pattern: /^\/pet/ },
563
+ ],
564
+ }),
565
+ ],
566
+ })
567
+ - name: exclude
568
+ type: Array<Exclude>
569
+ required: false
570
+ description: |
571
+ Skips any operation that matches at least one entry in the list. The opposite of `include`.
572
+
573
+ Each entry filters by one of:
574
+
575
+ - `tag` — the operation's first tag.
576
+ - `operationId` — the operation's `operationId`.
577
+ - `path` — the URL pattern (`'/pet/{petId}'`).
578
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
579
+ - `contentType` — the media type of the request body.
580
+
581
+ `pattern` accepts a plain string or a `RegExp`. When both `include` and `exclude` are set, `exclude` wins.
582
+ codeBlock:
583
+ lang: typescript
584
+ title: Type definition
585
+ code: |
586
+ export type Exclude = {
587
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
588
+ pattern: string | RegExp
589
+ }
590
+ examples:
591
+ - name: Skip everything under the store tag
592
+ files:
593
+ - name: kubb.config.ts
594
+ lang: typescript
595
+ twoslash: false
596
+ code: |
597
+ import { defineConfig } from 'kubb'
598
+ import { pluginTs } from '@kubb/plugin-ts'
599
+
600
+ export default defineConfig({
601
+ input: { path: './petStore.yaml' },
602
+ output: { path: './src/gen' },
603
+ plugins: [
604
+ pluginTs({
605
+ exclude: [
606
+ { type: 'tag', pattern: 'store' },
607
+ ],
608
+ }),
609
+ ],
610
+ })
611
+ - name: Skip a specific operation and all delete methods
612
+ files:
613
+ - name: kubb.config.ts
614
+ lang: typescript
615
+ twoslash: false
616
+ code: |
617
+ import { defineConfig } from 'kubb'
618
+ import { pluginTs } from '@kubb/plugin-ts'
619
+
620
+ export default defineConfig({
621
+ input: { path: './petStore.yaml' },
622
+ output: { path: './src/gen' },
623
+ plugins: [
624
+ pluginTs({
625
+ exclude: [
626
+ { type: 'operationId', pattern: 'deletePet' },
627
+ { type: 'method', pattern: 'delete' },
628
+ ],
629
+ }),
630
+ ],
631
+ })
632
+ - name: override
633
+ type: Array<Override>
634
+ required: false
635
+ description: |
636
+ 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.
637
+
638
+ 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.
639
+
640
+ Entries are evaluated top to bottom. The first matching entry's `options` is merged onto the plugin defaults; later entries do not stack.
641
+ codeBlock:
642
+ lang: typescript
643
+ title: Type definition
644
+ code: |
645
+ export type Override = {
646
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
647
+ pattern: string | RegExp
648
+ options: PluginOptions
649
+ }
650
+ examples:
651
+ - name: Use a different enum style for the user tag
652
+ files:
653
+ - name: kubb.config.ts
654
+ lang: typescript
655
+ twoslash: false
656
+ code: |
657
+ import { defineConfig } from 'kubb'
658
+ import { pluginTs } from '@kubb/plugin-ts'
659
+
660
+ export default defineConfig({
661
+ input: { path: './petStore.yaml' },
662
+ output: { path: './src/gen' },
663
+ plugins: [
664
+ pluginTs({
665
+ enumType: 'asConst',
666
+ override: [
667
+ {
668
+ type: 'tag',
669
+ pattern: 'user',
670
+ options: { enumType: 'literal' },
671
+ },
672
+ ],
673
+ }),
674
+ ],
675
+ })
676
+ - name: generators
677
+ type: Array<Generator<PluginFaker>>
678
+ required: false
679
+ experimental: true
680
+ description: |
681
+ 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.
682
+
683
+ 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).
684
+ warning: |
685
+ Generators are an experimental, low-level API. The signature may change between minor releases.
686
+ - name: resolver
687
+ type: Partial<ResolverFaker>
688
+ required: false
689
+ description: |
690
+ 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.
691
+ codeBlock:
692
+ lang: typescript
693
+ title: Append "Mock" to every factory name
694
+ code: |
695
+ import { defineConfig } from 'kubb'
696
+ import { pluginFaker } from '@kubb/plugin-faker'
697
+
698
+ export default defineConfig({
699
+ input: { path: './petStore.yaml' },
700
+ output: { path: './src/gen' },
701
+ plugins: [
702
+ pluginFaker({
703
+ resolver: {
704
+ resolveName(name) {
705
+ return `${this.default(name)}Mock`
706
+ },
707
+ },
708
+ }),
709
+ ],
710
+ })
711
+ - name: transformer
712
+ type: ast.Visitor
713
+ required: false
714
+ description: |
715
+ 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.
716
+ codeBlock:
717
+ lang: typescript
718
+ title: Strip schema descriptions
719
+ code: |
720
+ import { defineConfig } from 'kubb'
721
+ import { pluginFaker } from '@kubb/plugin-faker'
722
+
723
+ export default defineConfig({
724
+ input: { path: './petStore.yaml' },
725
+ output: { path: './src/gen' },
726
+ plugins: [
727
+ pluginFaker({
728
+ transformer: {
729
+ schema(node) {
730
+ return { ...node, description: undefined }
731
+ },
732
+ },
733
+ }),
734
+ ],
735
+ })
736
+ - name: printer
737
+ type: '{ nodes?: PrinterFakerNodes }'
738
+ required: false
739
+ description: |
740
+ Replaces the Faker handler for a specific schema type (e.g. `'integer'`, `'date'`, `'ref'`). Each handler returns the Faker expression as a string.
741
+
742
+ Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
743
+ examples:
744
+ - name: Use faker.number.float() for integers
745
+ files:
746
+ - lang: typescript
747
+ twoslash: false
748
+ code: |
749
+ import { defineConfig } from 'kubb'
750
+ import { pluginFaker } from '@kubb/plugin-faker'
751
+
752
+ export default defineConfig({
753
+ input: { path: './petStore.yaml' },
754
+ output: { path: './src/gen' },
755
+ plugins: [
756
+ pluginFaker({
757
+ printer: {
758
+ nodes: {
759
+ integer() {
760
+ return 'faker.number.float()'
761
+ },
762
+ },
763
+ },
764
+ }),
765
+ ],
766
+ })
767
+ - name: Override date strings
768
+ files:
769
+ - lang: typescript
770
+ twoslash: false
771
+ code: |
772
+ import { defineConfig } from 'kubb'
773
+ import { pluginFaker } from '@kubb/plugin-faker'
774
+
775
+ export default defineConfig({
776
+ input: { path: './petStore.yaml' },
777
+ output: { path: './src/gen' },
778
+ plugins: [
779
+ pluginFaker({
780
+ printer: {
781
+ nodes: {
782
+ date(node) {
783
+ if (node.representation === 'string') {
784
+ return 'new Date().toISOString().substring(0, 10)'
785
+ }
786
+
787
+ return 'new Date()'
788
+ },
789
+ },
790
+ },
791
+ }),
792
+ ],
793
+ })
794
+ examples:
795
+ - name: kubb.config.ts
796
+ files:
797
+ - lang: typescript
798
+ twoslash: false
799
+ code: |
800
+ import { defineConfig } from 'kubb'
801
+ import { pluginFaker } from '@kubb/plugin-faker'
802
+ import { pluginTs } from '@kubb/plugin-ts'
803
+
804
+ export default defineConfig({
805
+ input: { path: './petStore.yaml' },
806
+ output: { path: './src/gen' },
807
+ plugins: [
808
+ pluginTs({
809
+ output: { path: './types' },
810
+ }),
811
+ pluginFaker({
812
+ output: { path: './mocks' },
813
+ seed: [100],
814
+ paramsCasing: 'camelcase',
815
+ }),
816
+ ],
817
+ })