@kubb/plugin-faker 5.0.0-beta.22 → 5.0.0-beta.27

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 (36) hide show
  1. package/dist/{Faker-BMgoFj8b.d.ts → Faker-BQpBZ2hU.d.ts} +2 -2
  2. package/dist/{Faker-AHTTvWZS.js → Faker-C7Cu9GKC.js} +3 -3
  3. package/dist/Faker-C7Cu9GKC.js.map +1 -0
  4. package/dist/{Faker-BoPNqNfi.cjs → Faker-DaKMu5pc.cjs} +3 -3
  5. package/dist/Faker-DaKMu5pc.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-DnCf6Dr6.cjs → fakerGenerator-C00Es7eC.cjs} +14 -8
  10. package/dist/fakerGenerator-C00Es7eC.cjs.map +1 -0
  11. package/dist/fakerGenerator-C85ME3uM.d.ts +15 -0
  12. package/dist/{fakerGenerator-Br2FyPbG.js → fakerGenerator-Crs3X84u.js} +14 -8
  13. package/dist/fakerGenerator-Crs3X84u.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 +54 -14
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +33 -12
  20. package/dist/index.js +54 -14
  21. package/dist/index.js.map +1 -1
  22. package/dist/{printerFaker-W0pLunAj.d.ts → printerFaker-GYscoNnG.d.ts} +50 -26
  23. package/extension.yaml +572 -122
  24. package/package.json +5 -5
  25. package/src/components/Faker.tsx +1 -1
  26. package/src/generators/fakerGenerator.tsx +15 -6
  27. package/src/plugin.ts +23 -6
  28. package/src/printers/printerFaker.ts +28 -10
  29. package/src/resolvers/resolverFaker.ts +10 -11
  30. package/src/types.ts +29 -23
  31. package/src/utils.ts +2 -2
  32. package/dist/Faker-AHTTvWZS.js.map +0 -1
  33. package/dist/Faker-BoPNqNfi.cjs.map +0 -1
  34. package/dist/fakerGenerator-B-QnVz9o.d.ts +0 -9
  35. package/dist/fakerGenerator-Br2FyPbG.js.map +0 -1
  36. package/dist/fakerGenerator-DnCf6Dr6.cjs.map +0 -1
package/extension.yaml CHANGED
@@ -2,7 +2,7 @@ $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
8
  npmPackage: '@kubb/plugin-faker'
@@ -36,332 +36,782 @@ 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
46
  default: "{ path: 'mocks', barrel: { type: 'named' } }"
45
- description: Specify the export location for the files and define the behavior of the output.
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
87
  - name: barrel
55
88
  type: "{ type: 'named' | 'all', nested?: boolean } | false"
56
89
  required: false
57
90
  default: "{ type: 'named' }"
58
- description: 'Configure barrel file export strategy. Use `type` to control named vs. wildcard exports; set `nested: true` to generate hierarchical barrels in subdirectories.'
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.
59
100
  examples:
60
- - name: all
101
+ - name: "'named' (default)"
61
102
  files:
62
- - lang: typescript
103
+ - name: kubb.config.ts
104
+ lang: typescript
105
+ twoslash: false
63
106
  code: |
64
- 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
65
121
  twoslash: false
66
- - name: named
122
+ code: |
123
+ export { Pet, PetStatus } from './Pet'
124
+ export { Store } from './Store'
125
+ - name: "'all'"
67
126
  files:
68
- - lang: typescript
127
+ - name: kubb.config.ts
128
+ lang: typescript
129
+ twoslash: false
69
130
  code: |
70
- 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
71
145
  twoslash: false
146
+ code: |
147
+ export * from './Pet'
148
+ export * from './Store'
72
149
  - name: nested
73
150
  files:
74
151
  - name: kubb.config.ts
75
152
  lang: typescript
153
+ twoslash: false
76
154
  code: |
77
- output: {
78
- path: './gen',
79
- barrel: { type: 'named', nested: true },
80
- }
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
81
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
82
179
  - name: 'false'
83
180
  files:
84
- - lang: typescript
85
- code: ''
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
86
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.
87
203
  - name: banner
88
204
  type: 'string | ((node: RootNode) => string)'
89
205
  required: false
90
- 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
+ })
91
261
  - name: footer
92
262
  type: 'string | ((node: RootNode) => string)'
93
263
  required: false
94
- 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
+ })
95
290
  - name: override
96
291
  type: boolean
97
292
  required: false
98
293
  default: 'false'
99
- description: Whether Kubb overrides existing external files that can be generated if they already exist.
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
+ })
100
319
  - name: group
101
320
  type: Group
102
321
  required: false
103
322
  description: |
104
- 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.
105
328
  examples:
106
329
  - name: kubb.config.ts
107
330
  files:
108
331
  - lang: typescript
109
- code: |
110
- group: {
111
- type: 'tag',
112
- name({ group }) {
113
- return `${group}Controller`
114
- }
115
- }
116
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
+ })
117
349
  body: |
118
350
  With the configuration above, the generator emits:
119
351
 
120
352
  ```text
121
- .
122
- ├── src/
123
- └── petController/
124
- │ ├── addPet.ts
125
- │ │ └── getPet.ts
126
- │ └── storeController/
127
- │ ├── createStore.ts
128
- │ └── getStoreById.ts
129
- ├── petStore.yaml
130
- ├── kubb.config.ts
131
- └── package.json
353
+ src/gen/
354
+ ├── petController/
355
+ ├── AddPet.ts
356
+ └── GetPet.ts
357
+ └── storeController/
358
+ ├── CreateStore.ts
359
+ └── GetStoreById.ts
132
360
  ```
133
361
  properties:
134
362
  - name: type
135
363
  type: "'tag'"
136
364
  required: true
137
- 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.
138
369
  note: |
139
- `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
140
- body: |
141
- - `'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.
142
371
  - name: name
143
372
  type: '(context: GroupContext) => string'
144
373
  required: false
145
374
  default: (ctx) => `${ctx.group}Controller`
146
- 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).
147
376
  - name: dateParser
148
377
  type: "'faker' | 'dayjs' | 'moment' | string"
149
378
  required: false
150
379
  default: "'faker'"
151
- 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.
152
384
  tip: |
153
- 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.
154
386
  examples:
155
- - name: "'faker'"
387
+ - name: "'faker' (default)"
156
388
  files:
157
- - lang: ts
389
+ - lang: typescript
390
+ twoslash: false
158
391
  code: |
159
392
  faker.date.anytime().toISOString().substring(0, 10)
160
393
  - name: "'dayjs'"
161
394
  files:
162
- - lang: ts
395
+ - lang: typescript
396
+ twoslash: false
163
397
  code: |
164
398
  dayjs(faker.date.anytime()).format('YYYY-MM-DD')
165
399
  - name: "'moment'"
166
400
  files:
167
- - lang: ts
401
+ - lang: typescript
402
+ twoslash: false
168
403
  code: |
169
404
  moment(faker.date.anytime()).format('YYYY-MM-DD')
170
405
  - name: mapper
171
406
  type: Record<string, string>
172
407
  required: false
173
- 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
+ })
174
431
  - name: paramsCasing
175
432
  type: "'camelcase'"
176
433
  required: false
177
- 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.
178
436
  important: |
179
- 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.
180
438
  - name: regexGenerator
181
439
  type: "'faker' | 'randexp'"
182
440
  required: false
183
441
  default: "'faker'"
184
- 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.
185
447
  examples:
186
- - name: "'faker'"
448
+ - name: "'faker' (default)"
187
449
  files:
188
- - lang: ts
450
+ - lang: typescript
451
+ twoslash: false
189
452
  code: |
190
453
  faker.helpers.fromRegExp('^[A-Z]+$')
191
454
  - name: "'randexp'"
192
455
  files:
193
- - lang: ts
456
+ - lang: typescript
457
+ twoslash: false
194
458
  code: |
195
459
  new RandExp(/^[A-Z]+$/).gen()
196
460
  - name: seed
197
461
  type: number | number[]
198
462
  required: false
199
- 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
+ })
200
481
  - name: locale
201
482
  type: string
202
483
  required: false
203
484
  default: "'en'"
204
- 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`.
205
487
  tip: |
206
- See the [Faker.js localization docs](https://fakerjs.dev/api/localization.html) for the full list of supported locales.
488
+ See [Faker.js localization](https://fakerjs.dev/api/localization.html) for the full list of locale codes.
207
489
  examples:
208
490
  - name: "'de'"
209
491
  files:
210
- - lang: ts
492
+ - lang: typescript
493
+ twoslash: false
211
494
  code: |
212
495
  import { fakerDE as faker } from '@faker-js/faker'
213
496
  - name: "'de_AT'"
214
497
  files:
215
- - lang: ts
498
+ - lang: typescript
499
+ twoslash: false
216
500
  code: |
217
501
  import { fakerDE_AT as faker } from '@faker-js/faker'
218
502
  - name: include
219
503
  type: Array<Include>
220
504
  required: false
221
- description: Array containing include parameters to include tags, operations, methods, paths, or content types.
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.
222
517
  codeBlock:
223
518
  lang: typescript
224
- title: Include
519
+ title: Type definition
225
520
  code: |
226
521
  export type Include = {
227
522
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
228
523
  pattern: string | RegExp
229
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
+ })
230
567
  - name: exclude
231
568
  type: Array<Exclude>
232
569
  required: false
233
- description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
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.
234
582
  codeBlock:
235
583
  lang: typescript
236
- title: Exclude
584
+ title: Type definition
237
585
  code: |
238
586
  export type Exclude = {
239
587
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
240
588
  pattern: string | RegExp
241
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
+ })
242
632
  - name: override
243
633
  type: Array<Override>
244
634
  required: false
245
- description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
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.
246
641
  codeBlock:
247
642
  lang: typescript
248
- title: Override
643
+ title: Type definition
249
644
  code: |
250
645
  export type Override = {
251
646
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
252
647
  pattern: string | RegExp
253
648
  options: PluginOptions
254
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
+ })
255
676
  - name: generators
256
677
  type: Array<Generator<PluginFaker>>
257
678
  required: false
258
679
  experimental: true
259
680
  description: |
260
- Define additional generators next to the built-in generators.
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.
261
682
 
262
- See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
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.
263
686
  - name: resolver
264
687
  type: Partial<ResolverFaker>
265
688
  required: false
266
- description: Customize helper naming on top of the active compatibility preset.
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.
267
691
  codeBlock:
268
692
  lang: typescript
693
+ title: Append "Mock" to every factory name
269
694
  code: |
270
- pluginFaker({
271
- resolver: {
272
- resolveName(name) {
273
- return `${this.default(name)}Mock`
274
- },
275
- },
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
+ ],
276
710
  })
277
711
  - name: transformer
278
712
  type: ast.Visitor
279
713
  required: false
280
- description: Apply a single AST visitor before the faker helpers are rendered.
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.
281
716
  codeBlock:
282
717
  lang: typescript
718
+ title: Strip schema descriptions
283
719
  code: |
284
- pluginFaker({
285
- transformer: {
286
- schema(node) {
287
- return { ...node, description: undefined }
288
- },
289
- },
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
+ ],
290
735
  })
291
736
  - name: printer
292
737
  type: '{ nodes?: PrinterFakerNodes }'
293
738
  required: false
294
739
  description: |
295
- Override individual printer node handlers to customize how specific schema types are rendered.
740
+ Replaces the Faker handler for a specific schema type (e.g. `'integer'`, `'date'`, `'ref'`). Each handler returns the Faker expression as a string.
296
741
 
297
- 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.
742
+ Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
298
743
  examples:
299
- - name: Override integer to float()
744
+ - name: Use faker.number.float() for integers
300
745
  files:
301
746
  - lang: typescript
747
+ twoslash: false
302
748
  code: |
749
+ import { defineConfig } from 'kubb'
303
750
  import { pluginFaker } from '@kubb/plugin-faker'
304
751
 
305
- pluginFaker({
306
- printer: {
307
- nodes: {
308
- integer() {
309
- return 'faker.number.float()'
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
+ },
310
763
  },
311
- },
312
- },
764
+ }),
765
+ ],
313
766
  })
314
- twoslash: false
315
767
  - name: Override date strings
316
768
  files:
317
769
  - lang: typescript
770
+ twoslash: false
318
771
  code: |
772
+ import { defineConfig } from 'kubb'
319
773
  import { pluginFaker } from '@kubb/plugin-faker'
320
774
 
321
- pluginFaker({
322
- printer: {
323
- nodes: {
324
- date(node) {
325
- if (node.representation === 'string') {
326
- return 'new Date().toISOString().substring(0, 10)'
327
- }
328
-
329
- return 'new Date()'
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
+ },
330
790
  },
331
- },
332
- },
791
+ }),
792
+ ],
333
793
  })
334
- twoslash: false
335
794
  examples:
336
795
  - name: kubb.config.ts
337
796
  files:
338
797
  - lang: typescript
798
+ twoslash: false
339
799
  code: |
340
800
  import { defineConfig } from 'kubb'
341
801
  import { pluginFaker } from '@kubb/plugin-faker'
342
802
  import { pluginTs } from '@kubb/plugin-ts'
343
803
 
344
804
  export default defineConfig({
345
- input: {
346
- path: './petStore.yaml',
347
- },
348
- output: {
349
- path: './src/gen',
350
- },
805
+ input: { path: './petStore.yaml' },
806
+ output: { path: './src/gen' },
351
807
  plugins: [
352
808
  pluginTs({
353
- output: {
354
- path: './types',
355
- },
809
+ output: { path: './types' },
356
810
  }),
357
811
  pluginFaker({
358
- output: {
359
- path: './mocks',
360
- barrel: { type: 'named' },
361
- },
812
+ output: { path: './mocks' },
362
813
  seed: [100],
363
814
  paramsCasing: 'camelcase',
364
815
  }),
365
816
  ],
366
817
  })
367
- twoslash: false