@kubb/plugin-cypress 5.0.0-beta.3 → 5.0.0-beta.30

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.
package/extension.yaml ADDED
@@ -0,0 +1,906 @@
1
+ $schema: https://kubb.dev/schemas/extension.json
2
+ kind: plugin
3
+ id: plugin-cypress
4
+ name: Cypress
5
+ description: Generate typed `cy.request()` wrappers from OpenAPI so end-to-end tests reuse one source of truth for API calls.
6
+ category: testing
7
+ type: official
8
+ npmPackage: '@kubb/plugin-cypress'
9
+ docsPath: /plugins/plugin-cypress
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
+ - cypress
19
+ - e2e-testing
20
+ - api-testing
21
+ - test-generation
22
+ - codegen
23
+ - openapi
24
+ dependencies:
25
+ - plugin-ts
26
+ resources:
27
+ documentation: https://kubb.dev/plugins/plugin-cypress
28
+ repository: https://github.com/kubb-labs/plugins
29
+ issues: https://github.com/kubb-labs/plugins/issues
30
+ changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-cypress/CHANGELOG.md
31
+ codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/cypress
32
+ featured: false
33
+ icon:
34
+ light: https://kubb.dev/feature/cypress.svg
35
+ intro: |
36
+ # @kubb/plugin-cypress
37
+
38
+ Generate one typed `cy.request()` wrapper per OpenAPI operation. Each helper has typed path params, body, query, and a typed response — so failing API calls in Cypress show up at compile time instead of inside the test runner.
39
+
40
+ Use these helpers in `before`/`beforeEach` hooks to seed data, in custom commands, or in API-only test specs.
41
+ options:
42
+ - name: output
43
+ type: Output
44
+ required: false
45
+ default: "{ path: 'cypress', barrel: { type: 'named' } }"
46
+ description: Where the generated Cypress helpers are written and how they are exported.
47
+ properties:
48
+ - name: path
49
+ type: string
50
+ required: true
51
+ description: |
52
+ Folder (or single file) where the plugin writes its generated code. The path is resolved against the global `output.path` set on `defineConfig`.
53
+
54
+ 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'`.
55
+ tip: |
56
+ When `output.path` points to a single file, the `group` option cannot be used because every operation ends up in the same file.
57
+ examples:
58
+ - name: kubb.config.ts
59
+ files:
60
+ - lang: typescript
61
+ twoslash: false
62
+ code: |
63
+ import { defineConfig } from 'kubb'
64
+ import { pluginTs } from '@kubb/plugin-ts'
65
+
66
+ export default defineConfig({
67
+ input: { path: './petStore.yaml' },
68
+ output: { path: './src/gen' },
69
+ plugins: [
70
+ pluginTs({
71
+ output: { path: './types' },
72
+ }),
73
+ ],
74
+ })
75
+ - name: Resulting tree
76
+ files:
77
+ - lang: text
78
+ twoslash: false
79
+ code: |
80
+ src/
81
+ └── gen/
82
+ └── types/
83
+ ├── Pet.ts
84
+ └── Store.ts
85
+ default: "'cypress'"
86
+ - name: barrel
87
+ type: "{ type: 'named' | 'all', nested?: boolean } | false"
88
+ required: false
89
+ default: "{ type: 'named' }"
90
+ description: |
91
+ Controls how the generated `index.ts` (barrel) file re-exports the plugin's output.
92
+
93
+ - `{ type: 'named' }` re-exports each symbol by name. Best for tree-shaking and explicit imports.
94
+ - `{ type: 'all' }` uses `export *`. Smaller barrel file, but exports everything.
95
+ - `{ nested: true }` creates a barrel in every subdirectory, so callers can import from any depth.
96
+ - `false` skips the barrel entirely. The plugin's files are also excluded from the root `index.ts`.
97
+ tip: |
98
+ 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.
99
+ examples:
100
+ - name: "'named' (default)"
101
+ files:
102
+ - name: kubb.config.ts
103
+ lang: typescript
104
+ twoslash: false
105
+ code: |
106
+ import { defineConfig } from 'kubb'
107
+ import { pluginTs } from '@kubb/plugin-ts'
108
+
109
+ export default defineConfig({
110
+ input: { path: './petStore.yaml' },
111
+ output: { path: './src/gen' },
112
+ plugins: [
113
+ pluginTs({
114
+ output: { barrel: { type: 'named' } },
115
+ }),
116
+ ],
117
+ })
118
+ - name: src/gen/types/index.ts
119
+ lang: typescript
120
+ twoslash: false
121
+ code: |
122
+ export { Pet, PetStatus } from './Pet'
123
+ export { Store } from './Store'
124
+ - name: "'all'"
125
+ files:
126
+ - name: kubb.config.ts
127
+ lang: typescript
128
+ twoslash: false
129
+ code: |
130
+ import { defineConfig } from 'kubb'
131
+ import { pluginTs } from '@kubb/plugin-ts'
132
+
133
+ export default defineConfig({
134
+ input: { path: './petStore.yaml' },
135
+ output: { path: './src/gen' },
136
+ plugins: [
137
+ pluginTs({
138
+ output: { barrel: { type: 'all' } },
139
+ }),
140
+ ],
141
+ })
142
+ - name: src/gen/types/index.ts
143
+ lang: typescript
144
+ twoslash: false
145
+ code: |
146
+ export * from './Pet'
147
+ export * from './Store'
148
+ - name: nested
149
+ files:
150
+ - name: kubb.config.ts
151
+ lang: typescript
152
+ twoslash: false
153
+ code: |
154
+ import { defineConfig } from 'kubb'
155
+ import { pluginTs } from '@kubb/plugin-ts'
156
+
157
+ export default defineConfig({
158
+ input: { path: './petStore.yaml' },
159
+ output: { path: './src/gen' },
160
+ plugins: [
161
+ pluginTs({
162
+ output: { barrel: { type: 'named', nested: true } },
163
+ }),
164
+ ],
165
+ })
166
+ - name: Generated tree
167
+ lang: text
168
+ twoslash: false
169
+ code: |
170
+ src/gen/types/
171
+ ├── index.ts # re-exports ./petController and ./storeController
172
+ ├── petController/
173
+ │ ├── index.ts # re-exports Pet, Store, ...
174
+ │ └── Pet.ts
175
+ └── storeController/
176
+ ├── index.ts
177
+ └── Store.ts
178
+ - name: 'false'
179
+ files:
180
+ - name: kubb.config.ts
181
+ lang: typescript
182
+ twoslash: false
183
+ code: |
184
+ import { defineConfig } from 'kubb'
185
+ import { pluginTs } from '@kubb/plugin-ts'
186
+
187
+ export default defineConfig({
188
+ input: { path: './petStore.yaml' },
189
+ output: { path: './src/gen' },
190
+ plugins: [
191
+ pluginTs({
192
+ output: { barrel: false },
193
+ }),
194
+ ],
195
+ })
196
+ - name: Result
197
+ lang: text
198
+ twoslash: false
199
+ code: |
200
+ # No index.ts is generated for this plugin.
201
+ # Its files are also excluded from the root index.ts.
202
+ - name: banner
203
+ type: 'string | ((node: RootNode) => string)'
204
+ required: false
205
+ description: |
206
+ Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives.
207
+
208
+ 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).
209
+ examples:
210
+ - name: Static banner
211
+ files:
212
+ - name: kubb.config.ts
213
+ lang: typescript
214
+ twoslash: false
215
+ code: |
216
+ import { defineConfig } from 'kubb'
217
+ import { pluginTs } from '@kubb/plugin-ts'
218
+
219
+ export default defineConfig({
220
+ input: { path: './petStore.yaml' },
221
+ output: { path: './src/gen' },
222
+ plugins: [
223
+ pluginTs({
224
+ output: {
225
+ banner: '/* eslint-disable */\n// @ts-nocheck',
226
+ },
227
+ }),
228
+ ],
229
+ })
230
+ - name: Generated file
231
+ lang: typescript
232
+ twoslash: false
233
+ code: |
234
+ /* eslint-disable */
235
+ // @ts-nocheck
236
+ export type Pet = {
237
+ id: number
238
+ name: string
239
+ }
240
+ - name: Dynamic banner
241
+ files:
242
+ - name: kubb.config.ts
243
+ lang: typescript
244
+ twoslash: false
245
+ code: |
246
+ import { defineConfig } from 'kubb'
247
+ import { pluginTs } from '@kubb/plugin-ts'
248
+
249
+ export default defineConfig({
250
+ input: { path: './petStore.yaml' },
251
+ output: { path: './src/gen' },
252
+ plugins: [
253
+ pluginTs({
254
+ output: {
255
+ banner: (node) => `// Source: ${node.path}\n// Generated at ${new Date().toISOString()}`,
256
+ },
257
+ }),
258
+ ],
259
+ })
260
+ - name: footer
261
+ type: 'string | ((node: RootNode) => string)'
262
+ required: false
263
+ description: |
264
+ 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.
265
+
266
+ Pass a string for a static footer, or a function that receives the file's `RootNode` and returns the footer text.
267
+ examples:
268
+ - name: Re-enable lint after a banner disable
269
+ files:
270
+ - name: kubb.config.ts
271
+ lang: typescript
272
+ twoslash: false
273
+ code: |
274
+ import { defineConfig } from 'kubb'
275
+ import { pluginTs } from '@kubb/plugin-ts'
276
+
277
+ export default defineConfig({
278
+ input: { path: './petStore.yaml' },
279
+ output: { path: './src/gen' },
280
+ plugins: [
281
+ pluginTs({
282
+ output: {
283
+ banner: '/* eslint-disable */',
284
+ footer: '/* eslint-enable */',
285
+ },
286
+ }),
287
+ ],
288
+ })
289
+ - name: override
290
+ type: boolean
291
+ required: false
292
+ default: 'false'
293
+ description: |
294
+ Allows the plugin to overwrite hand-written files that share a name with a generated file.
295
+
296
+ - `false` (default): Kubb skips a file if it already exists and is not marked as generated. This protects manual edits.
297
+ - `true`: Kubb overwrites any file at the target path, including hand-written ones.
298
+ warning: |
299
+ Enable this only when you are sure the target folder contains nothing you need to keep. Local edits are lost on the next generation.
300
+ examples:
301
+ - name: kubb.config.ts
302
+ files:
303
+ - lang: typescript
304
+ twoslash: false
305
+ code: |
306
+ import { defineConfig } from 'kubb'
307
+ import { pluginTs } from '@kubb/plugin-ts'
308
+
309
+ export default defineConfig({
310
+ input: { path: './petStore.yaml' },
311
+ output: { path: './src/gen' },
312
+ plugins: [
313
+ pluginTs({
314
+ output: { override: true },
315
+ }),
316
+ ],
317
+ })
318
+ - name: resolver
319
+ type: Partial<ResolverCypress> & ThisType<ResolverCypress>
320
+ required: false
321
+ description: |
322
+ 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.
323
+
324
+ 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.
325
+
326
+ 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.
327
+ body: |
328
+ Each plugin ships with a default resolver:
329
+
330
+ | Plugin | Default resolver |
331
+ | --- | --- |
332
+ | `@kubb/plugin-ts` | `resolverTs` |
333
+ | `@kubb/plugin-zod` | `resolverZod` |
334
+ | `@kubb/plugin-cypress` | `resolverCypress` |
335
+ | `@kubb/plugin-mcp` | `resolverMcp` |
336
+ | `@kubb/plugin-client` | `resolverClient` |
337
+ codeBlock:
338
+ lang: typescript
339
+ title: Add an Api prefix to every name
340
+ code: |
341
+ import { defineConfig } from 'kubb'
342
+ import { pluginTs } from '@kubb/plugin-ts'
343
+
344
+ export default defineConfig({
345
+ input: { path: './petStore.yaml' },
346
+ output: { path: './src/gen' },
347
+ plugins: [
348
+ pluginTs({
349
+ resolver: {
350
+ resolveName(name) {
351
+ return `Api${this.default(name, 'function')}`
352
+ },
353
+ },
354
+ }),
355
+ ],
356
+ })
357
+ tip: |
358
+ Use `resolver` for naming and file-location tweaks. For changing the AST nodes themselves (e.g. stripping descriptions), use `transformer` instead.
359
+ - name: paramsType
360
+ type: "'object' | 'inline'"
361
+ required: false
362
+ default: "'inline'"
363
+ description: |
364
+ How operation parameters (path, query, headers) are exposed in the generated function signature.
365
+
366
+ - `'inline'` (default) — each parameter is a separate positional argument. Compact for operations with one or two params.
367
+ - `'object'` — every parameter is wrapped in a single object argument. Easier to read for operations with many params and named at the call site.
368
+ tip: |
369
+ Setting `paramsType: 'object'` implicitly sets `pathParamsType: 'object'` as well, so call sites are consistent.
370
+ examples:
371
+ - name: "'inline' (default)"
372
+ files:
373
+ - name: Generated client
374
+ lang: typescript
375
+ twoslash: false
376
+ code: |
377
+ export async function deletePet(
378
+ petId: DeletePetPathParams['petId'],
379
+ headers?: DeletePetHeaderParams,
380
+ config: Partial<RequestConfig> = {},
381
+ ) {
382
+ // ...
383
+ }
384
+ - name: Caller
385
+ lang: typescript
386
+ twoslash: false
387
+ code: |
388
+ await deletePet(42)
389
+ - name: "'object'"
390
+ files:
391
+ - name: Generated client
392
+ lang: typescript
393
+ twoslash: false
394
+ code: |
395
+ export async function deletePet(
396
+ {
397
+ petId,
398
+ headers,
399
+ }: {
400
+ petId: DeletePetPathParams['petId']
401
+ headers?: DeletePetHeaderParams
402
+ },
403
+ config: Partial<RequestConfig> = {},
404
+ ) {
405
+ // ...
406
+ }
407
+ - name: Caller
408
+ lang: typescript
409
+ twoslash: false
410
+ code: |
411
+ await deletePet({ petId: 42, headers: { 'X-Api-Key': 'secret' } })
412
+ - name: paramsCasing
413
+ type: "'camelcase'"
414
+ required: false
415
+ description: |
416
+ Renames path, query, and header parameters in the generated client to the chosen casing. The HTTP request still uses the original names from the OpenAPI spec — Kubb writes the mapping for you.
417
+
418
+ - `'camelcase'` — turn `pet_id` and `X-Api-Key` into `petId` and `xApiKey` in your TypeScript code. The runtime URL still uses `/pet/{pet_id}` and the header is still sent as `X-Api-Key`.
419
+ important: |
420
+ Set the same `paramsCasing` on every plugin that touches operation parameters (`@kubb/plugin-ts`, `@kubb/plugin-client`, `@kubb/plugin-react-query`, `@kubb/plugin-faker`, `@kubb/plugin-mcp`). Mismatched casing causes type errors between generated layers.
421
+ examples:
422
+ - name: "With paramsCasing: 'camelcase'"
423
+ files:
424
+ - name: Generated client
425
+ lang: typescript
426
+ twoslash: false
427
+ code: |
428
+ // Function takes camelCase parameters
429
+ export async function deletePet(
430
+ petId: DeletePetPathParams['petId'],
431
+ headers?: DeletePetHeaderParams,
432
+ config: Partial<RequestConfig> = {},
433
+ ) {
434
+ // ...mapped back to the original API name internally
435
+ const pet_id = petId
436
+
437
+ return client({
438
+ method: 'DELETE',
439
+ url: `/pet/${pet_id}`,
440
+ ...config,
441
+ })
442
+ }
443
+ - name: Caller
444
+ lang: typescript
445
+ twoslash: false
446
+ code: |
447
+ await deletePet(42)
448
+ - name: Without paramsCasing
449
+ files:
450
+ - name: Generated client
451
+ lang: typescript
452
+ twoslash: false
453
+ code: |
454
+ // Function parameters mirror the OpenAPI spec
455
+ export async function deletePet(
456
+ pet_id: DeletePetPathParams['pet_id'],
457
+ headers?: DeletePetHeaderParams,
458
+ config: Partial<RequestConfig> = {},
459
+ ) {
460
+ return client({
461
+ method: 'DELETE',
462
+ url: `/pet/${pet_id}`,
463
+ ...config,
464
+ })
465
+ }
466
+ tip: |
467
+ Callers write friendly camelCase names. The generated client maps them back to whatever the API expects (snake_case path params, kebab-case headers, ...).
468
+ - name: pathParamsType
469
+ type: "'object' | 'inline'"
470
+ required: false
471
+ default: "'inline'"
472
+ description: |
473
+ How URL path parameters appear in the generated function signature. Affects only path params; query/header params follow `paramsType`.
474
+
475
+ - `'inline'` (default) — each path param is a positional argument: `getPetById(petId)`.
476
+ - `'object'` — path params are wrapped in a single object: `getPetById({ petId })`.
477
+ examples:
478
+ - name: "'inline' (default)"
479
+ files:
480
+ - lang: typescript
481
+ twoslash: false
482
+ code: |
483
+ export async function getPetById(
484
+ petId: GetPetByIdPathParams,
485
+ ) {
486
+ // ...
487
+ }
488
+ - name: "'object'"
489
+ files:
490
+ - lang: typescript
491
+ twoslash: false
492
+ code: |
493
+ export async function getPetById(
494
+ { petId }: GetPetByIdPathParams,
495
+ ) {
496
+ // ...
497
+ }
498
+ - name: dataReturnType
499
+ type: "'data' | 'full'"
500
+ required: false
501
+ default: "'data'"
502
+ description: |
503
+ Shape of the value returned from each generated client function.
504
+
505
+ - `'data'` returns only the response body (`response.data`). Concise and matches what most apps need.
506
+ - `'full'` returns the full response config — body, status code, headers, and the original request. Use this when callers need to inspect headers or status.
507
+ examples:
508
+ - name: "'data' (default)"
509
+ files:
510
+ - name: getPetById.ts
511
+ lang: typescript
512
+ twoslash: false
513
+ code: |
514
+ export async function getPetById<TData>(
515
+ petId: GetPetByIdPathParams,
516
+ ): Promise<ResponseConfig<TData>['data']> {
517
+ // ...
518
+ }
519
+ - name: usage.ts
520
+ lang: typescript
521
+ twoslash: false
522
+ code: |
523
+ const pet = await getPetById(1)
524
+ // ^? Pet
525
+ - name: "'full'"
526
+ files:
527
+ - name: getPetById.ts
528
+ lang: typescript
529
+ twoslash: false
530
+ code: |
531
+ export async function getPetById<TData>(
532
+ petId: GetPetByIdPathParams,
533
+ ): Promise<ResponseConfig<TData>> {
534
+ // ...
535
+ }
536
+ - name: usage.ts
537
+ lang: typescript
538
+ twoslash: false
539
+ code: |
540
+ const response = await getPetById(1)
541
+ // ^? ResponseConfig<Pet>
542
+ console.log(response.status, response.headers)
543
+ const pet = response.data
544
+ - name: baseURL
545
+ type: string
546
+ required: false
547
+ description: |
548
+ 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).
549
+
550
+ Set this when the generated client should point at a different environment (staging, production) than the one written in the spec.
551
+ examples:
552
+ - name: Override the spec's server URL
553
+ files:
554
+ - lang: typescript
555
+ twoslash: false
556
+ code: |
557
+ import { defineConfig } from 'kubb'
558
+ import { pluginClient } from '@kubb/plugin-client'
559
+
560
+ export default defineConfig({
561
+ input: { path: './petStore.yaml' },
562
+ output: { path: './src/gen' },
563
+ plugins: [
564
+ pluginClient({
565
+ baseURL: 'https://petstore.swagger.io/v2',
566
+ }),
567
+ ],
568
+ })
569
+ - name: group
570
+ type: Group
571
+ required: false
572
+ description: |
573
+ Splits generated files into subfolders based on the operation's tag, so each tag in your OpenAPI spec gets its own directory.
574
+
575
+ 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.
576
+ tip: |
577
+ 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.
578
+ examples:
579
+ - name: kubb.config.ts
580
+ files:
581
+ - lang: typescript
582
+ twoslash: false
583
+ code: |
584
+ import { defineConfig } from 'kubb'
585
+ import { pluginTs } from '@kubb/plugin-ts'
586
+
587
+ export default defineConfig({
588
+ input: { path: './petStore.yaml' },
589
+ output: { path: './src/gen' },
590
+ plugins: [
591
+ pluginTs({
592
+ group: {
593
+ type: 'tag',
594
+ name: ({ group }) => `${group}Controller`,
595
+ },
596
+ }),
597
+ ],
598
+ })
599
+ body: |
600
+ With the configuration above, the generator emits:
601
+
602
+ ```text
603
+ src/gen/
604
+ ├── petController/
605
+ │ ├── AddPet.ts
606
+ │ └── GetPet.ts
607
+ └── storeController/
608
+ ├── CreateStore.ts
609
+ └── GetStoreById.ts
610
+ ```
611
+ properties:
612
+ - name: type
613
+ type: "'tag'"
614
+ required: true
615
+ description: |
616
+ Property used to assign each operation to a group. Required whenever `group` is set.
617
+
618
+ 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.
619
+ note: |
620
+ `Required: true*` is conditional — only required when the parent `group` option is used. `group` itself stays optional.
621
+ - name: name
622
+ type: '(context: GroupContext) => string'
623
+ required: false
624
+ default: (ctx) => `${ctx.group}Requests`
625
+ description: Function that builds the folder/identifier name from a group key (the operation's first tag).
626
+ - name: include
627
+ type: Array<Include>
628
+ required: false
629
+ description: |
630
+ Restricts generation to operations that match at least one entry in the list. Anything not matched is skipped.
631
+
632
+ Each entry filters by one of:
633
+
634
+ - `tag` — the operation's first tag in the OpenAPI spec.
635
+ - `operationId` — the operation's `operationId`.
636
+ - `path` — the URL pattern (`'/pet/{petId}'`).
637
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
638
+ - `contentType` — the media type of the request body.
639
+
640
+ `pattern` accepts either a string (exact match) or a `RegExp` for fuzzy matches.
641
+ codeBlock:
642
+ lang: typescript
643
+ title: Type definition
644
+ code: |
645
+ export type Include = {
646
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
647
+ pattern: string | RegExp
648
+ }
649
+ examples:
650
+ - name: Only the pet tag
651
+ files:
652
+ - name: kubb.config.ts
653
+ lang: typescript
654
+ twoslash: false
655
+ code: |
656
+ import { defineConfig } from 'kubb'
657
+ import { pluginTs } from '@kubb/plugin-ts'
658
+
659
+ export default defineConfig({
660
+ input: { path: './petStore.yaml' },
661
+ output: { path: './src/gen' },
662
+ plugins: [
663
+ pluginTs({
664
+ include: [
665
+ { type: 'tag', pattern: 'pet' },
666
+ ],
667
+ }),
668
+ ],
669
+ })
670
+ - name: Only GET operations under /pet
671
+ files:
672
+ - name: kubb.config.ts
673
+ lang: typescript
674
+ twoslash: false
675
+ code: |
676
+ import { defineConfig } from 'kubb'
677
+ import { pluginTs } from '@kubb/plugin-ts'
678
+
679
+ export default defineConfig({
680
+ input: { path: './petStore.yaml' },
681
+ output: { path: './src/gen' },
682
+ plugins: [
683
+ pluginTs({
684
+ include: [
685
+ { type: 'method', pattern: 'get' },
686
+ { type: 'path', pattern: /^\/pet/ },
687
+ ],
688
+ }),
689
+ ],
690
+ })
691
+ - name: exclude
692
+ type: Array<Exclude>
693
+ required: false
694
+ description: |
695
+ Skips any operation that matches at least one entry in the list. The opposite of `include`.
696
+
697
+ Each entry filters by one of:
698
+
699
+ - `tag` — the operation's first tag.
700
+ - `operationId` — the operation's `operationId`.
701
+ - `path` — the URL pattern (`'/pet/{petId}'`).
702
+ - `method` — HTTP method (`'get'`, `'post'`, ...).
703
+ - `contentType` — the media type of the request body.
704
+
705
+ `pattern` accepts a plain string or a `RegExp`. When both `include` and `exclude` are set, `exclude` wins.
706
+ codeBlock:
707
+ lang: typescript
708
+ title: Type definition
709
+ code: |
710
+ export type Exclude = {
711
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
712
+ pattern: string | RegExp
713
+ }
714
+ examples:
715
+ - name: Skip everything under the store tag
716
+ files:
717
+ - name: kubb.config.ts
718
+ lang: typescript
719
+ twoslash: false
720
+ code: |
721
+ import { defineConfig } from 'kubb'
722
+ import { pluginTs } from '@kubb/plugin-ts'
723
+
724
+ export default defineConfig({
725
+ input: { path: './petStore.yaml' },
726
+ output: { path: './src/gen' },
727
+ plugins: [
728
+ pluginTs({
729
+ exclude: [
730
+ { type: 'tag', pattern: 'store' },
731
+ ],
732
+ }),
733
+ ],
734
+ })
735
+ - name: Skip a specific operation and all delete methods
736
+ files:
737
+ - name: kubb.config.ts
738
+ lang: typescript
739
+ twoslash: false
740
+ code: |
741
+ import { defineConfig } from 'kubb'
742
+ import { pluginTs } from '@kubb/plugin-ts'
743
+
744
+ export default defineConfig({
745
+ input: { path: './petStore.yaml' },
746
+ output: { path: './src/gen' },
747
+ plugins: [
748
+ pluginTs({
749
+ exclude: [
750
+ { type: 'operationId', pattern: 'deletePet' },
751
+ { type: 'method', pattern: 'delete' },
752
+ ],
753
+ }),
754
+ ],
755
+ })
756
+ - name: override
757
+ type: Array<Override>
758
+ required: false
759
+ description: |
760
+ 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.
761
+
762
+ 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.
763
+
764
+ Entries are evaluated top to bottom. The first matching entry's `options` is merged onto the plugin defaults; later entries do not stack.
765
+ codeBlock:
766
+ lang: typescript
767
+ title: Type definition
768
+ code: |
769
+ export type Override = {
770
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
771
+ pattern: string | RegExp
772
+ options: PluginOptions
773
+ }
774
+ examples:
775
+ - name: Use a different enum style for the user tag
776
+ files:
777
+ - name: kubb.config.ts
778
+ lang: typescript
779
+ twoslash: false
780
+ code: |
781
+ import { defineConfig } from 'kubb'
782
+ import { pluginTs } from '@kubb/plugin-ts'
783
+
784
+ export default defineConfig({
785
+ input: { path: './petStore.yaml' },
786
+ output: { path: './src/gen' },
787
+ plugins: [
788
+ pluginTs({
789
+ enumType: 'asConst',
790
+ override: [
791
+ {
792
+ type: 'tag',
793
+ pattern: 'user',
794
+ options: { enumType: 'literal' },
795
+ },
796
+ ],
797
+ }),
798
+ ],
799
+ })
800
+ - name: generators
801
+ type: Array<Generator<PluginCypress>>
802
+ required: false
803
+ experimental: true
804
+ description: |
805
+ 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.
806
+
807
+ 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).
808
+ warning: |
809
+ Generators are an experimental, low-level API. The signature may change between minor releases.
810
+ - name: transformer
811
+ type: Visitor
812
+ required: false
813
+ description: |
814
+ 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.
815
+
816
+ 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.
817
+ examples:
818
+ - name: Strip descriptions before printing
819
+ files:
820
+ - name: kubb.config.ts
821
+ lang: typescript
822
+ twoslash: false
823
+ code: |
824
+ import { defineConfig } from 'kubb'
825
+ import { pluginTs } from '@kubb/plugin-ts'
826
+
827
+ export default defineConfig({
828
+ input: { path: './petStore.yaml' },
829
+ output: { path: './src/gen' },
830
+ plugins: [
831
+ pluginTs({
832
+ transformer: {
833
+ schema(node) {
834
+ return { ...node, description: undefined }
835
+ },
836
+ },
837
+ }),
838
+ ],
839
+ })
840
+ - name: Prefix every operationId
841
+ files:
842
+ - name: kubb.config.ts
843
+ lang: typescript
844
+ twoslash: false
845
+ code: |
846
+ import { defineConfig } from 'kubb'
847
+ import { pluginTs } from '@kubb/plugin-ts'
848
+
849
+ export default defineConfig({
850
+ input: { path: './petStore.yaml' },
851
+ output: { path: './src/gen' },
852
+ plugins: [
853
+ pluginTs({
854
+ transformer: {
855
+ operation(node) {
856
+ return { ...node, operationId: `api_${node.operationId}` }
857
+ },
858
+ },
859
+ }),
860
+ ],
861
+ })
862
+ tip: |
863
+ Use `transformer` to rewrite node properties before printing. For changing the names of generated symbols and files, use `resolver` instead.
864
+ examples:
865
+ - name: kubb.config.ts
866
+ files:
867
+ - lang: typescript
868
+ twoslash: false
869
+ code: |
870
+ import { defineConfig } from 'kubb'
871
+ import { pluginTs } from '@kubb/plugin-ts'
872
+ import { pluginCypress } from '@kubb/plugin-cypress'
873
+
874
+ export default defineConfig({
875
+ input: { path: './petStore.yaml' },
876
+ output: { path: './src/gen' },
877
+ plugins: [
878
+ pluginTs(),
879
+ pluginCypress({
880
+ output: {
881
+ path: './cypress',
882
+ barrel: { type: 'named' },
883
+ banner: '/* eslint-disable */',
884
+ },
885
+ group: {
886
+ type: 'tag',
887
+ name: ({ group }) => `${group}Requests`,
888
+ },
889
+ }),
890
+ ],
891
+ })
892
+ - name: Using a generated helper
893
+ files:
894
+ - lang: typescript
895
+ twoslash: false
896
+ code: |
897
+ import { getPetByIdRequest } from '../gen/cypress/petRequests'
898
+
899
+ describe('Pet API', () => {
900
+ it('returns the pet by id', () => {
901
+ getPetByIdRequest(1).then((response) => {
902
+ expect(response.status).to.eq(200)
903
+ expect(response.body.id).to.eq(1)
904
+ })
905
+ })
906
+ })