@kubb/plugin-msw 5.0.0-beta.42 → 5.0.0-beta.56

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/{components--3aER8iM.js → components-Bi7cN-ws.js} +63 -152
  2. package/dist/components-Bi7cN-ws.js.map +1 -0
  3. package/dist/{components-BW5VCVSO.cjs → components-Bp69JYOt.cjs} +62 -157
  4. package/dist/components-Bp69JYOt.cjs.map +1 -0
  5. package/dist/components.cjs +1 -2
  6. package/dist/components.d.ts +1 -14
  7. package/dist/components.js +2 -2
  8. package/dist/{generators-CLKAZMic.js → generators-BnEvTy3q.js} +14 -12
  9. package/dist/generators-BnEvTy3q.js.map +1 -0
  10. package/dist/{generators-B6qnyBTW.cjs → generators-d22_s2UN.cjs} +13 -11
  11. package/dist/generators-d22_s2UN.cjs.map +1 -0
  12. package/dist/generators.cjs +1 -1
  13. package/dist/generators.d.ts +1 -1
  14. package/dist/generators.js +1 -1
  15. package/dist/index.cjs +34 -11
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +34 -11
  19. package/dist/index.js.map +1 -1
  20. package/dist/{types-CwhQTrui.d.ts → types-B1yTWOfj.d.ts} +9 -13
  21. package/package.json +8 -16
  22. package/src/components/Mock.tsx +2 -2
  23. package/src/components/MockWithFaker.tsx +2 -2
  24. package/src/components/index.ts +0 -1
  25. package/src/generators/{handlersGenerator.tsx → handlersGenerator.ts} +20 -18
  26. package/src/generators/index.ts +1 -1
  27. package/src/generators/mswGenerator.tsx +2 -2
  28. package/src/plugin.ts +2 -2
  29. package/src/resolvers/resolverMsw.ts +2 -2
  30. package/src/types.ts +8 -12
  31. package/dist/components--3aER8iM.js.map +0 -1
  32. package/dist/components-BW5VCVSO.cjs.map +0 -1
  33. package/dist/generators-B6qnyBTW.cjs.map +0 -1
  34. package/dist/generators-CLKAZMic.js.map +0 -1
  35. package/extension.yaml +0 -752
  36. package/src/components/Handlers.tsx +0 -19
package/extension.yaml DELETED
@@ -1,752 +0,0 @@
1
- $schema: https://kubb.dev/schemas/extension.json
2
- kind: plugin
3
- id: plugin-msw
4
- name: MSW
5
- description: Generate MSW request handlers from OpenAPI so you can mock the entire API in tests and during local development.
6
- category: mocks
7
- type: official
8
- npmPackage: '@kubb/plugin-msw'
9
- docsPath: /plugins/plugin-msw
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
- - msw
19
- - mock-service-worker
20
- - api-mocking
21
- - mocks
22
- - testing
23
- - codegen
24
- - openapi
25
- dependencies:
26
- - plugin-ts
27
- - plugin-faker
28
- resources:
29
- documentation: https://kubb.dev/plugins/plugin-msw
30
- repository: https://github.com/kubb-labs/plugins
31
- issues: https://github.com/kubb-labs/plugins/issues
32
- changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-msw/CHANGELOG.md
33
- codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/msw
34
- featured: false
35
- icon:
36
- light: https://kubb.dev/feature/msw.svg
37
- intro: |
38
- # @kubb/plugin-msw
39
-
40
- Generate [MSW](https://mswjs.io/) handlers from your OpenAPI spec. Drop them into your test setup or service worker to mock the API end-to-end — request path, method, status, and response body all stay in sync with the spec.
41
-
42
- Combine with `@kubb/plugin-faker` to seed handlers with realistic data, or feed them custom payloads from tests.
43
- options:
44
- - name: output
45
- type: Output
46
- required: false
47
- default: "{ path: 'handlers', barrel: { type: 'named' } }"
48
- description: Where the generated MSW handlers are written and how they are exported.
49
- properties:
50
- - name: path
51
- type: string
52
- required: true
53
- description: |
54
- Folder (or single file) where the plugin writes its generated code. The path is resolved against the global `output.path` set on `defineConfig`.
55
-
56
- 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'`.
57
- tip: |
58
- When `output.path` points to a single file, the `group` option cannot be used because every operation ends up in the same file.
59
- examples:
60
- - name: kubb.config.ts
61
- files:
62
- - lang: typescript
63
- twoslash: false
64
- code: |
65
- import { defineConfig } from 'kubb'
66
- import { pluginTs } from '@kubb/plugin-ts'
67
-
68
- export default defineConfig({
69
- input: { path: './petStore.yaml' },
70
- output: { path: './src/gen' },
71
- plugins: [
72
- pluginTs({
73
- output: { path: './types' },
74
- }),
75
- ],
76
- })
77
- - name: Resulting tree
78
- files:
79
- - lang: text
80
- twoslash: false
81
- code: |
82
- src/
83
- └── gen/
84
- └── types/
85
- ├── Pet.ts
86
- └── Store.ts
87
- default: "'handlers'"
88
- - name: barrel
89
- type: "{ type: 'named' | 'all', nested?: boolean } | false"
90
- required: false
91
- default: "{ type: 'named' }"
92
- description: |
93
- Controls how the generated `index.ts` (barrel) file re-exports the plugin's output.
94
-
95
- - `{ type: 'named' }` re-exports each symbol by name. Best for tree-shaking and explicit imports.
96
- - `{ type: 'all' }` uses `export *`. Smaller barrel file, but exports everything.
97
- - `{ nested: true }` creates a barrel in every subdirectory, so callers can import from any depth.
98
- - `false` skips the barrel entirely. The plugin's files are also excluded from the root `index.ts`.
99
- tip: |
100
- 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.
101
- examples:
102
- - name: "'named' (default)"
103
- files:
104
- - name: kubb.config.ts
105
- lang: typescript
106
- twoslash: false
107
- code: |
108
- import { defineConfig } from 'kubb'
109
- import { pluginTs } from '@kubb/plugin-ts'
110
-
111
- export default defineConfig({
112
- input: { path: './petStore.yaml' },
113
- output: { path: './src/gen' },
114
- plugins: [
115
- pluginTs({
116
- output: { barrel: { type: 'named' } },
117
- }),
118
- ],
119
- })
120
- - name: src/gen/types/index.ts
121
- lang: typescript
122
- twoslash: false
123
- code: |
124
- export { Pet, PetStatus } from './Pet'
125
- export { Store } from './Store'
126
- - name: "'all'"
127
- files:
128
- - name: kubb.config.ts
129
- lang: typescript
130
- twoslash: false
131
- code: |
132
- import { defineConfig } from 'kubb'
133
- import { pluginTs } from '@kubb/plugin-ts'
134
-
135
- export default defineConfig({
136
- input: { path: './petStore.yaml' },
137
- output: { path: './src/gen' },
138
- plugins: [
139
- pluginTs({
140
- output: { barrel: { type: 'all' } },
141
- }),
142
- ],
143
- })
144
- - name: src/gen/types/index.ts
145
- lang: typescript
146
- twoslash: false
147
- code: |
148
- export * from './Pet'
149
- export * from './Store'
150
- - name: nested
151
- files:
152
- - name: kubb.config.ts
153
- lang: typescript
154
- twoslash: false
155
- code: |
156
- import { defineConfig } from 'kubb'
157
- import { pluginTs } from '@kubb/plugin-ts'
158
-
159
- export default defineConfig({
160
- input: { path: './petStore.yaml' },
161
- output: { path: './src/gen' },
162
- plugins: [
163
- pluginTs({
164
- output: { barrel: { type: 'named', nested: true } },
165
- }),
166
- ],
167
- })
168
- - name: Generated tree
169
- lang: text
170
- twoslash: false
171
- code: |
172
- src/gen/types/
173
- ├── index.ts # re-exports ./petController and ./storeController
174
- ├── petController/
175
- │ ├── index.ts # re-exports Pet, Store, ...
176
- │ └── Pet.ts
177
- └── storeController/
178
- ├── index.ts
179
- └── Store.ts
180
- - name: 'false'
181
- files:
182
- - name: kubb.config.ts
183
- lang: typescript
184
- twoslash: false
185
- code: |
186
- import { defineConfig } from 'kubb'
187
- import { pluginTs } from '@kubb/plugin-ts'
188
-
189
- export default defineConfig({
190
- input: { path: './petStore.yaml' },
191
- output: { path: './src/gen' },
192
- plugins: [
193
- pluginTs({
194
- output: { barrel: false },
195
- }),
196
- ],
197
- })
198
- - name: Result
199
- lang: text
200
- twoslash: false
201
- code: |
202
- # No index.ts is generated for this plugin.
203
- # Its files are also excluded from the root index.ts.
204
- - name: banner
205
- type: 'string | ((node: RootNode) => string)'
206
- required: false
207
- description: |
208
- Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives.
209
-
210
- 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).
211
- examples:
212
- - name: Static banner
213
- files:
214
- - name: kubb.config.ts
215
- lang: typescript
216
- twoslash: false
217
- code: |
218
- import { defineConfig } from 'kubb'
219
- import { pluginTs } from '@kubb/plugin-ts'
220
-
221
- export default defineConfig({
222
- input: { path: './petStore.yaml' },
223
- output: { path: './src/gen' },
224
- plugins: [
225
- pluginTs({
226
- output: {
227
- banner: '/* eslint-disable */\n// @ts-nocheck',
228
- },
229
- }),
230
- ],
231
- })
232
- - name: Generated file
233
- lang: typescript
234
- twoslash: false
235
- code: |
236
- /* eslint-disable */
237
- // @ts-nocheck
238
- export type Pet = {
239
- id: number
240
- name: string
241
- }
242
- - name: Dynamic banner
243
- files:
244
- - name: kubb.config.ts
245
- lang: typescript
246
- twoslash: false
247
- code: |
248
- import { defineConfig } from 'kubb'
249
- import { pluginTs } from '@kubb/plugin-ts'
250
-
251
- export default defineConfig({
252
- input: { path: './petStore.yaml' },
253
- output: { path: './src/gen' },
254
- plugins: [
255
- pluginTs({
256
- output: {
257
- banner: (node) => `// Source: ${node.path}\n// Generated at ${new Date().toISOString()}`,
258
- },
259
- }),
260
- ],
261
- })
262
- - name: footer
263
- type: 'string | ((node: RootNode) => string)'
264
- required: false
265
- description: |
266
- 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.
267
-
268
- Pass a string for a static footer, or a function that receives the file's `RootNode` and returns the footer text.
269
- examples:
270
- - name: Re-enable lint after a banner disable
271
- files:
272
- - name: kubb.config.ts
273
- lang: typescript
274
- twoslash: false
275
- code: |
276
- import { defineConfig } from 'kubb'
277
- import { pluginTs } from '@kubb/plugin-ts'
278
-
279
- export default defineConfig({
280
- input: { path: './petStore.yaml' },
281
- output: { path: './src/gen' },
282
- plugins: [
283
- pluginTs({
284
- output: {
285
- banner: '/* eslint-disable */',
286
- footer: '/* eslint-enable */',
287
- },
288
- }),
289
- ],
290
- })
291
- - name: override
292
- type: boolean
293
- required: false
294
- default: 'false'
295
- description: |
296
- Allows the plugin to overwrite hand-written files that share a name with a generated file.
297
-
298
- - `false` (default): Kubb skips a file if it already exists and is not marked as generated. This protects manual edits.
299
- - `true`: Kubb overwrites any file at the target path, including hand-written ones.
300
- warning: |
301
- Enable this only when you are sure the target folder contains nothing you need to keep. Local edits are lost on the next generation.
302
- examples:
303
- - name: kubb.config.ts
304
- files:
305
- - lang: typescript
306
- twoslash: false
307
- code: |
308
- import { defineConfig } from 'kubb'
309
- import { pluginTs } from '@kubb/plugin-ts'
310
-
311
- export default defineConfig({
312
- input: { path: './petStore.yaml' },
313
- output: { path: './src/gen' },
314
- plugins: [
315
- pluginTs({
316
- output: { override: true },
317
- }),
318
- ],
319
- })
320
- - name: handlers
321
- type: boolean
322
- required: false
323
- default: 'false'
324
- description: |
325
- Emits a `handlers.ts` file that re-exports every generated handler grouped by HTTP method. Drop this file into your MSW `setupServer(...handlers)` or `setupWorker(...handlers)` call.
326
- examples:
327
- - name: setup.ts
328
- files:
329
- - lang: typescript
330
- twoslash: false
331
- code: |
332
- import { setupServer } from 'msw/node'
333
- import { handlersGet, handlersPost } from './gen/handlers'
334
-
335
- export const server = setupServer(...handlersGet, ...handlersPost)
336
- - name: baseURL
337
- type: string
338
- required: false
339
- description: |
340
- Base URL prepended to every request URL in the generated client. When omitted, the URL comes from the OpenAPI spec's `servers[0].url` (or whichever index the adapter is configured to read).
341
-
342
- Set this when the generated client should point at a different environment (staging, production) than the one written in the spec.
343
- examples:
344
- - name: Override the spec's server URL
345
- files:
346
- - lang: typescript
347
- twoslash: false
348
- code: |
349
- import { defineConfig } from 'kubb'
350
- import { pluginClient } from '@kubb/plugin-client'
351
-
352
- export default defineConfig({
353
- input: { path: './petStore.yaml' },
354
- output: { path: './src/gen' },
355
- plugins: [
356
- pluginClient({
357
- baseURL: 'https://petstore.swagger.io/v2',
358
- }),
359
- ],
360
- })
361
- - name: group
362
- type: Group
363
- required: false
364
- description: |
365
- Splits generated files into subfolders based on the operation's tag, so each tag in your OpenAPI spec gets its own directory.
366
-
367
- 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.
368
- tip: |
369
- 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.
370
- examples:
371
- - name: kubb.config.ts
372
- files:
373
- - lang: typescript
374
- twoslash: false
375
- code: |
376
- import { defineConfig } from 'kubb'
377
- import { pluginTs } from '@kubb/plugin-ts'
378
-
379
- export default defineConfig({
380
- input: { path: './petStore.yaml' },
381
- output: { path: './src/gen' },
382
- plugins: [
383
- pluginTs({
384
- group: {
385
- type: 'tag',
386
- name: ({ group }) => `${group}Controller`,
387
- },
388
- }),
389
- ],
390
- })
391
- body: |
392
- With the configuration above, the generator emits:
393
-
394
- ```text
395
- src/gen/
396
- ├── petController/
397
- │ ├── AddPet.ts
398
- │ └── GetPet.ts
399
- └── storeController/
400
- ├── CreateStore.ts
401
- └── GetStoreById.ts
402
- ```
403
- properties:
404
- - name: type
405
- type: "'tag'"
406
- required: true
407
- description: |
408
- Property used to assign each operation to a group. Required whenever `group` is set.
409
-
410
- 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.
411
- note: |
412
- `Required: true*` is conditional — only required when the parent `group` option is used. `group` itself stays optional.
413
- - name: name
414
- type: '(context: GroupContext) => string'
415
- required: false
416
- default: (ctx) => `${ctx.group}Controller`
417
- description: Function that builds the folder/identifier name from a group key (the operation's first tag).
418
- - name: parser
419
- type: "'data' | 'faker'"
420
- required: false
421
- default: "'data'"
422
- description: |
423
- Source of the response body returned by each generated handler.
424
-
425
- - `'data'` (default) — handlers return a typed empty/example payload, ready for you to fill in from tests.
426
- - `'faker'` — handlers return a value produced by `@kubb/plugin-faker`. Requires the Faker plugin in the plugins array.
427
- examples:
428
- - name: "'faker'"
429
- files:
430
- - lang: typescript
431
- twoslash: false
432
- code: |
433
- import { defineConfig } from 'kubb'
434
- import { pluginTs } from '@kubb/plugin-ts'
435
- import { pluginFaker } from '@kubb/plugin-faker'
436
- import { pluginMsw } from '@kubb/plugin-msw'
437
-
438
- export default defineConfig({
439
- input: { path: './petStore.yaml' },
440
- output: { path: './src/gen' },
441
- plugins: [
442
- pluginTs(),
443
- pluginFaker(),
444
- pluginMsw({ parser: 'faker' }),
445
- ],
446
- })
447
- - name: include
448
- type: Array<Include>
449
- required: false
450
- description: |
451
- Restricts generation to operations that match at least one entry in the list. Anything not matched is skipped.
452
-
453
- Each entry filters by one of:
454
-
455
- - `tag` — the operation's first tag in the OpenAPI spec.
456
- - `operationId` — the operation's `operationId`.
457
- - `path` — the URL pattern (`'/pet/{petId}'`).
458
- - `method` — HTTP method (`'get'`, `'post'`, ...).
459
- - `contentType` — the media type of the request body.
460
-
461
- `pattern` accepts either a string (exact match) or a `RegExp` for fuzzy matches.
462
- codeBlock:
463
- lang: typescript
464
- title: Type definition
465
- code: |
466
- export type Include = {
467
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
468
- pattern: string | RegExp
469
- }
470
- examples:
471
- - name: Only the pet tag
472
- files:
473
- - name: kubb.config.ts
474
- lang: typescript
475
- twoslash: false
476
- code: |
477
- import { defineConfig } from 'kubb'
478
- import { pluginTs } from '@kubb/plugin-ts'
479
-
480
- export default defineConfig({
481
- input: { path: './petStore.yaml' },
482
- output: { path: './src/gen' },
483
- plugins: [
484
- pluginTs({
485
- include: [
486
- { type: 'tag', pattern: 'pet' },
487
- ],
488
- }),
489
- ],
490
- })
491
- - name: Only GET operations under /pet
492
- files:
493
- - name: kubb.config.ts
494
- lang: typescript
495
- twoslash: false
496
- code: |
497
- import { defineConfig } from 'kubb'
498
- import { pluginTs } from '@kubb/plugin-ts'
499
-
500
- export default defineConfig({
501
- input: { path: './petStore.yaml' },
502
- output: { path: './src/gen' },
503
- plugins: [
504
- pluginTs({
505
- include: [
506
- { type: 'method', pattern: 'get' },
507
- { type: 'path', pattern: /^\/pet/ },
508
- ],
509
- }),
510
- ],
511
- })
512
- - name: exclude
513
- type: Array<Exclude>
514
- required: false
515
- description: |
516
- Skips any operation that matches at least one entry in the list. The opposite of `include`.
517
-
518
- Each entry filters by one of:
519
-
520
- - `tag` — the operation's first tag.
521
- - `operationId` — the operation's `operationId`.
522
- - `path` — the URL pattern (`'/pet/{petId}'`).
523
- - `method` — HTTP method (`'get'`, `'post'`, ...).
524
- - `contentType` — the media type of the request body.
525
-
526
- `pattern` accepts a plain string or a `RegExp`. When both `include` and `exclude` are set, `exclude` wins.
527
- codeBlock:
528
- lang: typescript
529
- title: Type definition
530
- code: |
531
- export type Exclude = {
532
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
533
- pattern: string | RegExp
534
- }
535
- examples:
536
- - name: Skip everything under the store tag
537
- files:
538
- - name: kubb.config.ts
539
- lang: typescript
540
- twoslash: false
541
- code: |
542
- import { defineConfig } from 'kubb'
543
- import { pluginTs } from '@kubb/plugin-ts'
544
-
545
- export default defineConfig({
546
- input: { path: './petStore.yaml' },
547
- output: { path: './src/gen' },
548
- plugins: [
549
- pluginTs({
550
- exclude: [
551
- { type: 'tag', pattern: 'store' },
552
- ],
553
- }),
554
- ],
555
- })
556
- - name: Skip a specific operation and all delete methods
557
- files:
558
- - name: kubb.config.ts
559
- lang: typescript
560
- twoslash: false
561
- code: |
562
- import { defineConfig } from 'kubb'
563
- import { pluginTs } from '@kubb/plugin-ts'
564
-
565
- export default defineConfig({
566
- input: { path: './petStore.yaml' },
567
- output: { path: './src/gen' },
568
- plugins: [
569
- pluginTs({
570
- exclude: [
571
- { type: 'operationId', pattern: 'deletePet' },
572
- { type: 'method', pattern: 'delete' },
573
- ],
574
- }),
575
- ],
576
- })
577
- - name: override
578
- type: Array<Override>
579
- required: false
580
- description: |
581
- 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.
582
-
583
- 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.
584
-
585
- Entries are evaluated top to bottom. The first matching entry's `options` is merged onto the plugin defaults; later entries do not stack.
586
- codeBlock:
587
- lang: typescript
588
- title: Type definition
589
- code: |
590
- export type Override = {
591
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
592
- pattern: string | RegExp
593
- options: PluginOptions
594
- }
595
- examples:
596
- - name: Use a different enum style for the user tag
597
- files:
598
- - name: kubb.config.ts
599
- lang: typescript
600
- twoslash: false
601
- code: |
602
- import { defineConfig } from 'kubb'
603
- import { pluginTs } from '@kubb/plugin-ts'
604
-
605
- export default defineConfig({
606
- input: { path: './petStore.yaml' },
607
- output: { path: './src/gen' },
608
- plugins: [
609
- pluginTs({
610
- enumType: 'asConst',
611
- override: [
612
- {
613
- type: 'tag',
614
- pattern: 'user',
615
- options: { enumType: 'literal' },
616
- },
617
- ],
618
- }),
619
- ],
620
- })
621
- - name: generators
622
- type: Array<Generator<PluginMsw>>
623
- required: false
624
- experimental: true
625
- description: |
626
- 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.
627
-
628
- 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).
629
- warning: |
630
- Generators are an experimental, low-level API. The signature may change between minor releases.
631
- - name: resolver
632
- type: Partial<ResolverMsw> & ThisType<ResolverMsw>
633
- required: false
634
- description: |
635
- Overrides how the plugin builds names and paths for generated files and symbols. Use this to add prefixes, suffixes, or to swap the casing strategy without forking the plugin.
636
-
637
- Only override the methods you want to change. Anything you omit falls back to the plugin's default resolver. A method that returns `null` or `undefined` also falls back.
638
-
639
- Inside each method, `this` is bound to the full resolver, so you can call `this.default(name, 'function')` to delegate to the built-in implementation.
640
- body: |
641
- Each plugin ships with a default resolver:
642
-
643
- | Plugin | Default resolver |
644
- | --- | --- |
645
- | `@kubb/plugin-ts` | `resolverTs` |
646
- | `@kubb/plugin-zod` | `resolverZod` |
647
- | `@kubb/plugin-faker` | `resolverFaker` |
648
- | `@kubb/plugin-cypress` | `resolverCypress` |
649
- | `@kubb/plugin-msw` | `resolverMsw` |
650
- | `@kubb/plugin-mcp` | `resolverMcp` |
651
- | `@kubb/plugin-client` | `resolverClient` |
652
- codeBlock:
653
- lang: typescript
654
- title: Prefix every handler name with "Mock"
655
- code: |
656
- import { defineConfig } from 'kubb'
657
- import { pluginMsw } from '@kubb/plugin-msw'
658
-
659
- export default defineConfig({
660
- input: { path: './petStore.yaml' },
661
- output: { path: './src/gen' },
662
- plugins: [
663
- pluginMsw({
664
- resolver: {
665
- resolveName(name) {
666
- return `Mock${this.default(name, 'function')}`
667
- },
668
- },
669
- }),
670
- ],
671
- })
672
- tip: |
673
- Use `resolver` for naming and file-location tweaks. For changing the AST nodes themselves (e.g. stripping descriptions), use `transformer` instead.
674
- - name: transformer
675
- type: Visitor
676
- required: false
677
- description: |
678
- Modifies AST nodes before they are printed to source code. Use this when you need to rewrite operation IDs, drop descriptions, or change schema metadata without forking the generator.
679
-
680
- Each visitor method (e.g. `schema`, `operation`) receives the node and a context object. Return a new node to replace it, or return `undefined` to leave it untouched. Methods you omit keep the plugin's default behavior.
681
- examples:
682
- - name: Strip descriptions before printing
683
- files:
684
- - name: kubb.config.ts
685
- lang: typescript
686
- twoslash: false
687
- code: |
688
- import { defineConfig } from 'kubb'
689
- import { pluginTs } from '@kubb/plugin-ts'
690
-
691
- export default defineConfig({
692
- input: { path: './petStore.yaml' },
693
- output: { path: './src/gen' },
694
- plugins: [
695
- pluginTs({
696
- transformer: {
697
- schema(node) {
698
- return { ...node, description: undefined }
699
- },
700
- },
701
- }),
702
- ],
703
- })
704
- - name: Prefix every operationId
705
- files:
706
- - name: kubb.config.ts
707
- lang: typescript
708
- twoslash: false
709
- code: |
710
- import { defineConfig } from 'kubb'
711
- import { pluginTs } from '@kubb/plugin-ts'
712
-
713
- export default defineConfig({
714
- input: { path: './petStore.yaml' },
715
- output: { path: './src/gen' },
716
- plugins: [
717
- pluginTs({
718
- transformer: {
719
- operation(node) {
720
- return { ...node, operationId: `api_${node.operationId}` }
721
- },
722
- },
723
- }),
724
- ],
725
- })
726
- tip: |
727
- Use `transformer` to rewrite node properties before printing. For changing the names of generated symbols and files, use `resolver` instead.
728
- examples:
729
- - name: kubb.config.ts
730
- files:
731
- - lang: typescript
732
- twoslash: false
733
- code: |
734
- import { defineConfig } from 'kubb'
735
- import { pluginMsw } from '@kubb/plugin-msw'
736
- import { pluginTs } from '@kubb/plugin-ts'
737
-
738
- export default defineConfig({
739
- input: { path: './petStore.yaml' },
740
- output: { path: './src/gen' },
741
- plugins: [
742
- pluginTs(),
743
- pluginMsw({
744
- output: { path: './mocks' },
745
- group: {
746
- type: 'tag',
747
- name: ({ group }) => `${group}Service`,
748
- },
749
- handlers: true,
750
- }),
751
- ],
752
- })