@kubb/core 5.0.0-alpha.73 → 5.0.0-alpha.74

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/src/types.ts CHANGED
@@ -13,25 +13,48 @@ import type { PluginDriver } from './PluginDriver.ts'
13
13
  export type { Renderer, RendererFactory } from './createRenderer.ts'
14
14
 
15
15
  /**
16
- * Safely extracts the type of key `K` from `T`, returning `{}` when `K` is not a key of `T`.
17
- * Used to implement optional interface augmentation for `Kubb.ConfigOptionsRegistry` and
18
- * `Kubb.PluginOptionsRegistry` so that middleware and plugin packages can extend core types
19
- * without requiring modifications to core.
16
+ * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
17
+ * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
18
+ * without requiring changes to core.
20
19
  *
21
20
  * @internal
22
21
  */
23
22
  type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}
24
23
 
24
+ /**
25
+ * Reference to an input file to generate code from.
26
+ *
27
+ * Specify an absolute path or a path relative to the config file location.
28
+ * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
29
+ */
25
30
  export type InputPath = {
26
31
  /**
27
- * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
32
+ * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * { path: './petstore.yaml' }
37
+ * { path: '/absolute/path/to/openapi.json' }
38
+ * ```
28
39
  */
29
40
  path: string
30
41
  }
31
42
 
43
+ /**
44
+ * Inline input data to generate code from.
45
+ *
46
+ * Useful when you want to pass the specification directly instead of from a file.
47
+ * Can be a string (YAML/JSON) or a parsed object.
48
+ */
32
49
  export type InputData = {
33
50
  /**
34
- * A `string` or `object` that contains your Swagger/OpenAPI data.
51
+ * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * { data: fs.readFileSync('./openapi.yaml', 'utf8') }
56
+ * { data: { openapi: '3.1.0', info: { ... } } }
57
+ * ```
35
58
  */
36
59
  data: string | unknown
37
60
  }
@@ -39,19 +62,18 @@ export type InputData = {
39
62
  type Input = InputPath | InputData
40
63
 
41
64
  /**
42
- * The raw source passed to an adapter's `parse` function.
43
- * Mirrors the shape of `Config['input']` with paths already resolved to absolute.
65
+ * Source data passed to an adapter's `parse` function.
66
+ * Mirrors the config input shape with paths resolved to absolute.
44
67
  */
45
68
  export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }
46
69
 
47
70
  /**
48
- * Type parameters for an adapter definition.
71
+ * Generic type parameters for an adapter definition.
49
72
  *
50
- * Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle:
51
- * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
52
- * - `TOptions` — raw user-facing options passed to the adapter factory
53
- * - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
54
- * - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
73
+ * - `TName` unique identifier (e.g. `'oas'`, `'asyncapi'`)
74
+ * - `TOptions` — user-facing options passed to the adapter factory
75
+ * - `TResolvedOptions` — options after defaults applied
76
+ * - `TDocument` — type of the parsed source document
55
77
  */
56
78
  export type AdapterFactoryOptions<
57
79
  TName extends string = string,
@@ -66,83 +88,94 @@ export type AdapterFactoryOptions<
66
88
  }
67
89
 
68
90
  /**
69
- * An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
91
+ * Adapter that converts input files or data into an `InputNode`.
70
92
  *
71
- * Adapters are the single entry-point for different schema formats
72
- * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
73
- * that all Kubb plugins consume.
93
+ * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
94
+ * universal intermediate representation that all plugins consume.
74
95
  *
75
96
  * @example
76
97
  * ```ts
77
- * import { oasAdapter } from '@kubb/adapter-oas'
98
+ * import { adapterOas } from '@kubb/adapter-oas'
78
99
  *
79
100
  * export default defineConfig({
80
- * adapter: adapterOas(), // default — OpenAPI / Swagger
81
- * input: { path: './openapi.yaml' },
101
+ * adapter: adapterOas(),
102
+ * input: { path: './openapi.yaml' },
82
103
  * plugins: [pluginTs(), pluginZod()],
83
104
  * })
84
105
  * ```
85
106
  */
86
107
  export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
87
108
  /**
88
- * Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
109
+ * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
89
110
  */
90
111
  name: TOptions['name']
91
112
  /**
92
- * Resolved options (after defaults have been applied).
113
+ * Resolved adapter options after defaults have been applied.
93
114
  */
94
115
  options: TOptions['resolvedOptions']
95
116
  /**
96
- * The raw source document produced after the first `parse()` call.
97
- * `undefined` before parsing; typed by the adapter's `TDocument` generic.
117
+ * Parsed source document after the first `parse()` call. `null` before parsing.
98
118
  */
99
119
  document: TOptions['document'] | null
100
120
  inputNode: InputNode | null
101
121
  /**
102
- * Convert the raw source into a universal `InputNode`.
122
+ * Parse the source into a universal `InputNode`.
103
123
  */
104
124
  parse: (source: AdapterSource) => PossiblePromise<InputNode>
105
125
  /**
106
- * Extracts `ImportNode` entries needed by a `SchemaNode` tree.
107
- * Populated after the first `parse()` call. Returns an empty array before that.
126
+ * Extract `ImportNode` entries for a schema tree.
127
+ * Returns an empty array before the first `parse()` call.
108
128
  *
109
129
  * The `resolve` callback receives the collision-corrected schema name and must
110
- * return the `{ name, path }` pair for the import, or `undefined` to skip it.
130
+ * return `{ name, path }` for the import, or `undefined` to skip it.
111
131
  */
112
132
  getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
113
133
  }
114
134
 
115
135
  export type DevtoolsOptions = {
116
136
  /**
117
- * Open the AST inspector view (`/ast`) in Kubb Studio.
118
- * When `false`, opens the main Studio page instead.
137
+ * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
119
138
  * @default false
120
139
  */
121
140
  ast?: boolean
122
141
  }
123
142
 
124
143
  /**
144
+ * Build configuration for Kubb code generation.
145
+ *
146
+ * The Config is the main entry point for customizing how Kubb generates code. It specifies:
147
+ * - What to generate from (adapter + input)
148
+ * - Where to output generated code (output)
149
+ * - How to generate (plugins + middleware)
150
+ * - Runtime details (parsers, storage, renderer)
151
+ *
152
+ * See `UserConfig` for a relaxed version with sensible defaults.
153
+ *
125
154
  * @private
126
155
  */
127
156
  export type Config<TInput = Input> = {
128
157
  /**
129
- * The name to display in the CLI output.
158
+ * Display name for this configuration in CLI output and logs.
159
+ * Useful when running multiple builds with `defineConfig` arrays.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * name: 'api-client'
164
+ * ```
130
165
  */
131
166
  name?: string
132
167
  /**
133
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
168
+ * Project root directory, absolute or relative to the config file.
134
169
  * @default process.cwd()
135
170
  */
136
171
  root: string
137
172
  /**
138
- * An array of parsers used to convert generated files to strings.
139
- * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
173
+ * Parsers that convert generated files to strings.
174
+ * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
175
+ * A fallback parser is appended for unhandled extensions.
176
+ * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
140
177
  *
141
- * A catch-all fallback parser is always appended last for any unhandled extension.
142
- *
143
- * When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
144
- * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
145
- * @default [parserTs] — from `@kubb/parser-ts`
178
+ * @default [parserTs] from `@kubb/parser-ts`
146
179
  * @example
147
180
  * ```ts
148
181
  * import { parserTs, tsxParser } from '@kubb/parser-ts'
@@ -153,125 +186,197 @@ export type Config<TInput = Input> = {
153
186
  */
154
187
  parsers: Array<Parser>
155
188
  /**
156
- * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
157
- * intermediate representation consumed by all Kubb plugins.
158
- *
159
- * - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
160
- * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
189
+ * Adapter that parses input files into the universal `InputNode` representation.
190
+ * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
161
191
  *
162
192
  * @example
163
193
  * ```ts
164
194
  * import { adapterOas } from '@kubb/adapter-oas'
165
195
  * export default defineConfig({
166
196
  * adapter: adapterOas(),
167
- * input: { path: './petStore.yaml' },
197
+ * input: { path: './petstore.yaml' },
168
198
  * })
169
199
  * ```
170
200
  */
171
201
  adapter: Adapter
172
202
  /**
173
203
  * Source file or data to generate code from.
174
- * Use `input.path` for a file on disk or `input.data` for an inline string or object.
204
+ * Use `input.path` for a file path or `input.data` for inline data.
175
205
  */
176
206
  input: TInput
177
207
  output: {
178
208
  /**
179
- * Output directory for generated files.
180
- * Accepts an absolute path or a path relative to `root`.
209
+ * Output directory for generated files, absolute or relative to `root`.
210
+ *
211
+ * All generated files will be written under this directory. Subdirectories can be created
212
+ * by plugins based on grouping strategy (by tag, path, etc.).
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * output: {
217
+ * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
218
+ * }
219
+ * ```
181
220
  */
182
221
  path: string
183
222
  /**
184
- * Clean the output directory before each build.
223
+ * Remove all files from the output directory before starting the build.
224
+ *
225
+ * Useful to ensure old generated files aren't mixed with new ones.
226
+ * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
227
+ *
228
+ * @default false
229
+ * @example
230
+ * ```ts
231
+ * clean: true // wipes ./src/gen/* before generating
232
+ * ```
185
233
  */
186
234
  clean?: boolean
187
235
  /**
188
- * Save files to the file system.
236
+ * Persists generated files to the file system.
237
+ *
189
238
  * @default true
190
- * @deprecated Use `storage` to control where files are written.
239
+ * @deprecated Use `storage` option to control where files are written instead.
191
240
  */
192
241
  write?: boolean
193
242
  /**
194
- * Specifies the formatting tool to be used.
195
- * - 'auto' automatically detects and uses oxfmt, biome, or prettier (in that order of preference).
196
- * - 'oxfmt' uses Oxfmt for code formatting.
197
- * - 'prettier' uses Prettier for code formatting.
198
- * - 'biome' uses Biome for code formatting.
199
- * - false disables code formatting.
243
+ * Auto-format generated files after code generation completes.
244
+ *
245
+ * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
246
+ * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
247
+ *
200
248
  * @default false
249
+ * @example
250
+ * ```ts
251
+ * format: 'auto' // auto-detect prettier, biome, or oxfmt
252
+ * format: 'prettier' // force prettier
253
+ * format: false // skip formatting
254
+ * ```
201
255
  */
202
256
  format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false
203
257
  /**
204
- * Specifies the linter that should be used to analyze the code.
205
- * - 'auto' automatically detects and uses oxlint, biome, or eslint (in that order of preference).
206
- * - 'oxlint' uses Oxlint for linting.
207
- * - 'eslint' uses ESLint for linting.
208
- * - 'biome' uses Biome for linting.
209
- * - false disables linting.
258
+ * Auto-lint generated files after code generation completes.
259
+ *
260
+ * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
261
+ * is available on your system. Pass `false` to skip linting.
262
+ *
210
263
  * @default false
264
+ * @example
265
+ * ```ts
266
+ * lint: 'auto' // auto-detect oxlint, biome, or eslint
267
+ * lint: 'eslint' // force eslint
268
+ * lint: false // skip linting
269
+ * ```
211
270
  */
212
271
  lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false
213
272
  /**
214
- * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
215
- * @default { '.ts': '.ts'}
273
+ * Map file extensions to different output extensions.
274
+ *
275
+ * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
276
+ * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
277
+ *
278
+ * @default { '.ts': '.ts' }
279
+ * @example
280
+ * ```ts
281
+ * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
282
+ * extension: { '.ts': '', '.tsx': '.jsx' }
283
+ * ```
216
284
  */
217
285
  extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
218
286
  /**
219
- * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
220
- * - 'simple' adds banner with link to Kubb.
221
- * - 'full' adds source, title, description, and OpenAPI version.
222
- * - false disables banner generation.
287
+ * Banner text prepended to every generated file.
288
+ *
289
+ * Useful for auto-generation notices or license headers. Choose a preset or write custom text.
290
+ * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
291
+ *
223
292
  * @default 'simple'
293
+ * @example
294
+ * ```ts
295
+ * defaultBanner: 'simple' // "This file was autogenerated by Kubb"
296
+ * defaultBanner: 'full' // adds source, title, description, API version
297
+ * defaultBanner: false // no banner
298
+ * ```
224
299
  */
225
300
  defaultBanner?: 'simple' | 'full' | false
226
301
  /**
227
- * Whether to override existing external files if they already exist.
228
- * When setting the option in the global configuration, all plugins inherit the same behavior by default.
229
- * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
302
+ * When `true`, overwrites existing files. When `false`, skips generated files that already exist.
303
+ *
304
+ * Individual plugins can override this setting. This is useful for preventing accidental data loss
305
+ * when re-generating while you have local edits in the output folder.
306
+ *
230
307
  * @default false
308
+ * @example
309
+ * ```ts
310
+ * override: true // regenerate everything, even existing files
311
+ * override: false // skip files that already exist
312
+ * ```
231
313
  */
232
314
  override?: boolean
233
315
  } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>
234
316
  /**
235
- * Storage backend for generated files.
236
- * Defaults to `fsStorage()` — the built-in filesystem driver.
237
- * Accepts any object implementing the {@link Storage} interface.
238
- * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
317
+ * Storage backend that controls where and how generated files are persisted.
318
+ *
319
+ * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
320
+ * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
321
+ *
239
322
  * @default fsStorage()
240
323
  * @example
241
324
  * ```ts
242
325
  * import { memoryStorage } from '@kubb/core'
326
+ *
327
+ * // Keep generated files in memory (useful for testing, CI pipelines)
243
328
  * storage: memoryStorage()
329
+ *
330
+ * // Use custom S3 storage
331
+ * storage: myS3Storage()
244
332
  * ```
333
+ *
334
+ * @see {@link Storage} interface for implementing custom backends.
245
335
  */
246
336
  storage?: Storage
247
337
  /**
248
- * An array of Kubb plugins used for code generation.
249
- * Each plugin may declare additional configurable options.
250
- * If a plugin depends on another, an error is thrown when the dependency is missing.
251
- * Use `dependencies` on the plugin to declare execution order.
338
+ * Plugins that execute during the build to generate code and transform the AST.
339
+ *
340
+ * Each plugin processes the AST produced by the adapter and can emit files for different
341
+ * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
342
+ * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
343
+ *
344
+ * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * import { pluginTs } from '@kubb/plugin-ts'
349
+ * import { pluginZod } from '@kubb/plugin-zod'
350
+ *
351
+ * plugins: [
352
+ * pluginTs({ output: { path: './src/gen' } }),
353
+ * pluginZod({ output: { path: './src/gen' } }),
354
+ * ]
355
+ * ```
252
356
  */
253
357
  plugins: Array<Plugin>
254
358
  /**
255
- * Middleware instances that observe and post-process the build output.
256
- * Each middleware receives the `hooks` emitter and attaches its own listeners.
257
- * Middleware listeners are always registered after all plugin listeners,
258
- * so middleware hooks fire last for any given event.
359
+ * Middleware instances that observe build events and post-process generated code.
360
+ *
361
+ * Middleware fires AFTER all plugins for each event. Perfect for tasks like:
362
+ * - Auditing what was generated
363
+ * - Adding barrel/index files
364
+ * - Validating output
365
+ * - Running custom transformations
259
366
  *
260
367
  * @example
261
368
  * ```ts
262
369
  * import { middlewareBarrel } from '@kubb/middleware-barrel'
263
- * export default defineConfig({
264
- * middleware: [middlewareBarrel],
265
- * plugins: [pluginTs(), pluginZod()],
266
- * })
370
+ *
371
+ * middleware: [middlewareBarrel()]
267
372
  * ```
373
+ *
374
+ * @see {@link defineMiddleware} to create custom middleware.
268
375
  */
269
376
  middleware?: Array<Middleware>
270
377
  /**
271
- * Project-wide renderer factory. All plugins and generators that do not declare their own
272
- * `renderer` ultimately fall back to this value.
273
- *
274
- * The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
378
+ * Default renderer factory used by all plugins and generators.
379
+ * Resolution chain: `generator.renderer` `plugin.renderer` `config.renderer` `undefined` (raw FileNode[] mode).
275
380
  *
276
381
  * @example
277
382
  * ```ts
@@ -282,9 +387,34 @@ export type Config<TInput = Input> = {
282
387
  * })
283
388
  * ```
284
389
  */
390
+ /**
391
+ * Renderer that converts generated AST nodes to code strings.
392
+ *
393
+ * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support
394
+ * different output formats (template engines, code generation DSLs, etc.).
395
+ *
396
+ * @default rendererJsx() // from @kubb/renderer-jsx
397
+ * @example
398
+ * ```ts
399
+ * import { rendererJsx } from '@kubb/renderer-jsx'
400
+ * renderer: rendererJsx()
401
+ * ```
402
+ *
403
+ * @see {@link Renderer} to implement a custom renderer.
404
+ */
285
405
  renderer?: RendererFactory
286
406
  /**
287
- * Devtools configuration for Kubb Studio integration.
407
+ * Kubb Studio cloud integration settings.
408
+ *
409
+ * Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
410
+ * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
411
+ *
412
+ * @default false // disabled by default
413
+ * @example
414
+ * ```ts
415
+ * devtools: true // use default Kubb Studio
416
+ * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
417
+ * ```
288
418
  */
289
419
  devtools?:
290
420
  | true
@@ -296,12 +426,33 @@ export type Config<TInput = Input> = {
296
426
  studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})
297
427
  }
298
428
  /**
299
- * Hooks triggered when a specific action occurs in Kubb.
429
+ * Lifecycle hooks that execute during or after the build process.
430
+ *
431
+ * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
432
+ * Currently supports the `done` hook which fires after all plugins and middleware complete.
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * hooks: {
437
+ * done: 'prettier --write "./src/gen"', // auto-format generated files
438
+ * // or multiple commands:
439
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
440
+ * }
441
+ * ```
300
442
  */
301
443
  hooks?: {
302
444
  /**
303
- * Hook that triggers at the end of all executions.
304
- * Useful for running Prettier or ESLint to format/lint your code.
445
+ * Command(s) to run after all plugins and middleware complete generation.
446
+ *
447
+ * Useful for post-processing: formatting, linting, copying files, or custom validation.
448
+ * Pass a single command string or array of command strings to run sequentially.
449
+ * Commands are executed relative to the `root` directory.
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * done: 'prettier --write "./src/gen"'
454
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
455
+ * ```
305
456
  */
306
457
  done?: string | Array<string>
307
458
  }
@@ -310,7 +461,7 @@ export type Config<TInput = Input> = {
310
461
  // plugin
311
462
 
312
463
  /**
313
- * A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
464
+ * Type/string pattern filter for include/exclude/override matching.
314
465
  */
315
466
  type PatternFilter = {
316
467
  type: string
@@ -318,18 +469,14 @@ type PatternFilter = {
318
469
  }
319
470
 
320
471
  /**
321
- * A pattern filter paired with partial option overrides to apply when the pattern matches.
472
+ * Pattern filter with partial option overrides applied when the pattern matches.
322
473
  */
323
474
  type PatternOverride<TOptions> = PatternFilter & {
324
475
  options: Omit<Partial<TOptions>, 'override'>
325
476
  }
326
477
 
327
478
  /**
328
- * Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
329
- * for a given operation or schema node.
330
- */
331
- /**
332
- * Resolves filtered options for a given operation or schema node.
479
+ * Context for resolving filtered options for a given operation or schema node.
333
480
  *
334
481
  * @internal
335
482
  */
@@ -343,9 +490,8 @@ export type ResolveOptionsContext<TOptions> = {
343
490
  /**
344
491
  * Base constraint for all plugin resolver objects.
345
492
  *
346
- * `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
347
- * by `defineResolver` — plugin authors may override them but never need to implement them
348
- * from scratch.
493
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
494
+ * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
349
495
  *
350
496
  * @example
351
497
  * ```ts
@@ -368,20 +514,20 @@ export type Resolver = {
368
514
 
369
515
  export type PluginFactoryOptions<
370
516
  /**
371
- * Name to be used for the plugin.
517
+ * Unique plugin name.
372
518
  */
373
519
  TName extends string = string,
374
520
  /**
375
- * Options of the plugin.
521
+ * User-facing plugin options.
376
522
  */
377
523
  TOptions extends object = object,
378
524
  /**
379
- * Options of the plugin that can be used later on, see `options` inside your plugin config.
525
+ * Plugin options after defaults are applied.
380
526
  */
381
527
  TResolvedOptions extends object = TOptions,
382
528
  /**
383
- * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
384
- * Use `defineResolver` to define the resolver object and export it alongside the plugin.
529
+ * Resolver that encapsulates naming and path-resolution helpers.
530
+ * Define with `defineResolver` and export alongside the plugin.
385
531
  */
386
532
  TResolver extends Resolver = Resolver,
387
533
  > = {
@@ -392,9 +538,9 @@ export type PluginFactoryOptions<
392
538
  }
393
539
 
394
540
  /**
395
- * Internal representation of a plugin after normalization.
396
- * Extends the user-facing `Plugin` with runtime fields populated during `kubb:plugin:setup`.
397
- * Not part of the public API — use `Plugin` for external-facing interactions.
541
+ * Normalized plugin after setup, with runtime fields populated.
542
+ * For internal use only plugins use the public `Plugin` type externally.
543
+ *
398
544
  * @internal
399
545
  */
400
546
  export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
@@ -413,30 +559,86 @@ export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFacto
413
559
  }
414
560
 
415
561
  /**
416
- * Partial version of {@link Config} intended for user-facing config entry points.
562
+ * Partial `Config` for user-facing entry points with sensible defaults.
417
563
  *
418
- * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
564
+ * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
565
+ * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
566
+ * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.
567
+ *
568
+ * @example
569
+ * ```ts
570
+ * export default defineConfig({
571
+ * input: { path: './petstore.yaml' },
572
+ * output: { path: './src/gen' },
573
+ * plugins: [pluginTs(), pluginZod()],
574
+ * })
575
+ * ```
419
576
  */
420
577
  export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
421
578
  /**
422
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
579
+ * Project root directory, absolute or relative to the config file location.
580
+ *
581
+ * Used as the base path for `root`-relative paths (e.g., `output.path`, file paths in hooks).
582
+ *
423
583
  * @default process.cwd()
584
+ * @example
585
+ * ```ts
586
+ * root: '/home/user/my-project'
587
+ * root: './my-project' // relative to config file
588
+ * ```
424
589
  */
425
590
  root?: string
426
591
  /**
427
- * An array of parsers used to convert generated files to strings.
428
- * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
592
+ * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
593
+ *
594
+ * Each parser handles a specific file type. By default, Kubb uses `parserTs` from `@kubb/parser-ts` for TypeScript files.
595
+ * Pass custom parsers to support additional languages or custom formats.
596
+ *
597
+ * @default [parserTs] // from @kubb/parser-ts
598
+ * @example
599
+ * ```ts
600
+ * import { parserTs } from '@kubb/parser-ts'
601
+ * import { parserJsonSchema } from '@kubb/parser-json-schema'
602
+ *
603
+ * parsers: [parserTs(), parserJsonSchema()]
604
+ * ```
429
605
  *
430
- * A catch-all fallback parser is always appended last for any unhandled extension.
606
+ * @see {@link Parser} to implement a custom parser.
431
607
  */
432
608
  parsers?: Array<Parser>
433
609
  /**
434
- * Adapter that converts the input file into a `@kubb/ast` `InputNode`.
610
+ * Adapter that parses your API specification (OpenAPI, GraphQL, AsyncAPI, etc.) into Kubb's universal AST.
611
+ *
612
+ * The adapter bridge between your input format and Kubb's internal representation. By default, uses the OAS adapter.
613
+ * Pass an alternative adapter (or multiple configs with different adapters) to support different spec formats.
614
+ *
615
+ * @default new OasAdapter() // from @kubb/adapter-oas
616
+ * @example
617
+ * ```ts
618
+ * import { Oas } from '@kubb/adapter-oas'
619
+ *
620
+ * adapter: new Oas({ apiVersion: '3.0.0' })
621
+ * ```
622
+ *
623
+ * @see {@link Adapter} to implement a custom adapter for GraphQL or other formats.
435
624
  */
436
625
  adapter?: Adapter
437
626
  /**
438
- * An array of Kubb plugins used for code generation.
439
- * Each entry is a hook-style plugin created with `definePlugin`.
627
+ * Plugins that execute during the build to generate code and transform the AST.
628
+ *
629
+ * Each plugin processes the AST produced by the adapter and can emit files for different
630
+ * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
631
+ *
632
+ * @default [] // no plugins (useful for setup/testing)
633
+ * @example
634
+ * ```ts
635
+ * plugins: [
636
+ * pluginTs({ output: { path: './src/gen' } }),
637
+ * pluginZod({ output: { path: './src/gen' } }),
638
+ * ]
639
+ * ```
640
+ *
641
+ * @see {@link definePlugin} to create a custom plugin.
440
642
  */
441
643
  plugins?: Array<Plugin>
442
644
  }
@@ -445,121 +647,114 @@ export type ResolveNameParams = {
445
647
  name: string
446
648
  pluginName?: string
447
649
  /**
448
- * Specifies the type of entity being named.
449
- * - `'file'` — customizes the name of the created file (camelCase).
450
- * - `'function'` — customizes the exported function names (camelCase).
451
- * - `'type'` — customizes TypeScript type names (PascalCase).
452
- * - `'const'` — customizes variable names (camelCase).
650
+ * Entity type being named.
651
+ * - `'file'` — file name (camelCase)
652
+ * - `'function'` — exported function name (camelCase)
653
+ * - `'type'` — TypeScript type name (PascalCase)
654
+ * - `'const'` — variable name (camelCase)
453
655
  */
454
656
  type?: 'file' | 'function' | 'type' | 'const'
455
657
  }
456
658
  /**
457
- * Context object passed as the second argument to generator `schema`, `operation`, and
458
- * `operations` methods.
659
+ * Context object passed to generator `schema`, `operation`, and `operations` methods.
459
660
  *
460
- * Generators are only invoked from `runPluginAstHooks`, which already guards against a
461
- * missing adapter. This type reflects that guarantee `ctx.adapter` and `ctx.inputNode`
462
- * are always defined, so no runtime checks or casts are needed inside generator bodies.
463
- *
464
- * `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
465
- * (after exclude/include/override filtering) and the plugin-level options for `operations`.
661
+ * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
662
+ * are needed. `ctx.options` carries resolved per-node options after exclude/include/override
663
+ * filtering for individual schema/operation calls, or plugin-level options for operations.
466
664
  */
467
665
  export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
468
666
  config: Config
469
667
  /**
470
- * Absolute path to the output directory for the current plugin.
471
- * Shorthand for `path.resolve(config.root, config.output.path)`.
668
+ * Absolute path to the current plugin's output directory.
472
669
  */
473
670
  root: string
474
671
  /**
475
- * Returns the output mode for the given output config.
476
- * Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
672
+ * Determine output mode based on the output config.
673
+ * Returns `'single'` when `output.path` is a file, `'split'` for a directory.
477
674
  */
478
675
  getMode: (output: { path: string }) => 'single' | 'split'
479
676
  driver: PluginDriver
480
677
  /**
481
- * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
482
- * the name is a registered key, otherwise returns the generic `Plugin`.
678
+ * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
483
679
  */
484
680
  getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
485
681
  getPlugin(name: string): Plugin | undefined
486
682
  /**
487
- * Like `getPlugin` but throws a descriptive error when the plugin is not found.
683
+ * Get a plugin by name, throws an error if not found.
488
684
  */
489
685
  requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
490
686
  requirePlugin(name: string): Plugin
491
687
  /**
492
- * Get a resolver by plugin name. Returns the resolver typed via `Kubb.PluginRegistry` when
493
- * the name is a registered key, otherwise returns the generic `Resolver`.
688
+ * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
494
689
  */
495
690
  getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']
496
691
  getResolver(name: string): Resolver
497
692
  /**
498
- * Add files only when they do not exist yet.
693
+ * Add files only if they don't exist.
499
694
  */
500
695
  addFile: (...file: Array<FileNode>) => Promise<void>
501
696
  /**
502
- * Merge multiple sources into the same output file.
697
+ * Merge sources into the same output file.
503
698
  */
504
699
  upsertFile: (...file: Array<FileNode>) => Promise<void>
505
700
  hooks: AsyncEventEmitter<KubbHooks>
506
701
  /**
507
- * The current plugin.
702
+ * The current plugin instance.
508
703
  */
509
704
  plugin: Plugin<TOptions>
510
705
  /**
511
- * Resolver for the current plugin.
706
+ * The current plugin's resolver.
512
707
  */
513
708
  resolver: TOptions['resolver']
514
709
  /**
515
- * Composed transformer for the current plugin.
710
+ * The current plugin's transformer.
516
711
  */
517
712
  transformer: Visitor | undefined
518
713
  /**
519
- * Emit a warning via the build event system.
714
+ * Emit a warning.
520
715
  */
521
716
  warn: (message: string) => void
522
717
  /**
523
- * Emit an error via the build event system.
718
+ * Emit an error.
524
719
  */
525
720
  error: (error: string | Error) => void
526
721
  /**
527
- * Emit an info message via the build event system.
722
+ * Emit an info message.
528
723
  */
529
724
  info: (message: string) => void
530
725
  /**
531
- * Opens the Kubb Studio URL for the current `inputNode` in the default browser.
726
+ * Open the current input node in Kubb Studio.
532
727
  */
533
728
  openInStudio: (options?: DevtoolsOptions) => Promise<void>
534
729
  /**
535
- * The adapter from `@kubb/ast`.
730
+ * The configured adapter instance.
536
731
  */
537
732
  adapter: Adapter
538
733
  /**
539
- * The universal `@kubb/ast` `InputNode` produced by the configured adapter.
734
+ * The universal `InputNode` produced by the adapter.
540
735
  */
541
736
  inputNode: InputNode
542
737
  /**
543
- * Per-node resolved options (after exclude/include/override filtering).
738
+ * Resolved options after exclude/include/override filtering.
544
739
  */
545
740
  options: TOptions['resolvedOptions']
546
741
  }
547
742
  /**
548
- * Configure generated file output location and behavior.
743
+ * Output configuration for generated files.
549
744
  */
550
745
  export type Output<_TOptions = unknown> = {
551
746
  /**
552
- * Path to the output folder or file that will contain generated code.
747
+ * Output folder or file path for generated code.
553
748
  */
554
749
  path: string
555
750
  /**
556
- * Text or function appended at the start of every generated file.
557
- * When a function, receives the current `InputNode` and must return a string.
751
+ * Text or function prepended to every generated file.
752
+ * When a function, receives the current `InputNode` and returns a string.
558
753
  */
559
754
  banner?: string | ((node?: InputNode) => string)
560
755
  /**
561
- * Text or function appended at the end of every generated file.
562
- * When a function, receives the current `InputNode` and must return a string.
756
+ * Text or function appended to every generated file.
757
+ * When a function, receives the current `InputNode` and returns a string.
563
758
  */
564
759
  footer?: string | ((node?: InputNode) => string)
565
760
  /**
@@ -571,27 +766,28 @@ export type Output<_TOptions = unknown> = {
571
766
 
572
767
  export type Group = {
573
768
  /**
574
- * Determines how files are grouped into subdirectories.
575
- * - `'tag'` groups files by OpenAPI tags.
576
- * - `'path'` groups files by OpenAPI paths.
769
+ * How to group files into subdirectories.
770
+ * - `'tag'` group by OpenAPI tags
771
+ * - `'path'` group by OpenAPI paths
577
772
  */
578
773
  type: 'tag' | 'path'
579
774
  /**
580
- * Returns the subdirectory name for a given group value.
581
- * Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
775
+ * Function that returns the subdirectory name for a group value.
776
+ * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
582
777
  */
583
778
  name?: (context: { group: string }) => string
584
779
  }
585
780
 
586
781
  export type LoggerOptions = {
587
782
  /**
783
+ * Log level for output verbosity.
588
784
  * @default 3
589
785
  */
590
786
  logLevel: (typeof logLevel)[keyof typeof logLevel]
591
787
  }
592
788
 
593
789
  /**
594
- * Shared context passed to all plugins, parsers, and other internals.
790
+ * Shared context passed to plugins, parsers, and other internals.
595
791
  */
596
792
  export type LoggerContext = AsyncEventEmitter<KubbHooks>
597
793
 
@@ -609,44 +805,35 @@ export type { Plugin } from './definePlugin.ts'
609
805
  export type { Kubb, KubbHooks } from './Kubb.ts'
610
806
 
611
807
  /**
612
- * Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
613
- * Provides methods to register generators, configure the resolver, transformer,
614
- * and renderer, as well as access to the current build configuration.
808
+ * Context for hook-style plugin `kubb:plugin:setup` handler.
809
+ * Provides methods to register generators, configure resolvers, transformers, and renderers.
615
810
  */
616
811
  export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
617
812
  /**
618
- * Register a generator on this plugin. Generators are invoked during the AST walk
619
- * (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
813
+ * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
814
+ * just like generators declared statically on `createPlugin`.
620
815
  */
621
816
  addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
622
817
  /**
623
- * Set or partially override the resolver for this plugin.
624
- * The resolver controls file naming and path resolution for generated files.
625
- *
626
- * When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
627
- * the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
818
+ * Set or override the resolver for this plugin.
819
+ * The resolver controls file naming and path resolution.
628
820
  */
629
821
  setResolver(resolver: Partial<TFactory['resolver']>): void
630
822
  /**
631
- * Set the AST transformer (visitor) for this plugin.
632
- * The transformer pre-processes nodes before they reach the generators.
823
+ * Set the AST transformer to pre-process nodes before they reach generators.
633
824
  */
634
825
  setTransformer(visitor: Visitor): void
635
826
  /**
636
- * Set the renderer factory for this plugin.
637
- * Used to process JSX elements returned by generators.
827
+ * Set the renderer factory to process JSX elements from generators.
638
828
  */
639
829
  setRenderer(renderer: RendererFactory): void
640
830
  /**
641
- * Set the resolved options for the build loop. These options are merged into the
642
- * normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
643
- *
644
- * Call this in `kubb:plugin:setup` to provide the resolved options that generators
645
- * and the build loop need (e.g., `enumType`, `optionalType`, `group`).
831
+ * Set resolved options merged into the normalized plugin's `options`.
832
+ * Call this in `kubb:plugin:setup` to provide options generators need.
646
833
  */
647
834
  setOptions(options: TFactory['resolvedOptions']): void
648
835
  /**
649
- * Inject a raw file into the build output, bypassing the normal generation pipeline.
836
+ * Inject a raw file into the build output, bypassing the generation pipeline.
650
837
  */
651
838
  injectFile(userFileNode: UserFileNode): void
652
839
  /**
@@ -654,17 +841,17 @@ export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = Plugi
654
841
  */
655
842
  updateConfig(config: Partial<Config>): void
656
843
  /**
657
- * The resolved build configuration at the time of setup.
844
+ * The resolved build configuration at setup time.
658
845
  */
659
846
  config: Config
660
847
  /**
661
- * The plugin's own options as passed by the user.
848
+ * The plugin's user-provided options.
662
849
  */
663
850
  options: TFactory['options']
664
851
  }
665
852
 
666
853
  /**
667
- * Context passed to a hook-style plugin's `kubb:build:start` handler.
854
+ * Context for hook-style plugin `kubb:build:start` handler.
668
855
  * Fires immediately before the plugin execution loop begins.
669
856
  */
670
857
  export type KubbBuildStartContext = {
@@ -672,15 +859,13 @@ export type KubbBuildStartContext = {
672
859
  adapter: Adapter
673
860
  inputNode: InputNode
674
861
  /**
675
- * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
676
- * the name is a registered key, otherwise returns the generic `Plugin`.
862
+ * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
677
863
  */
678
864
  getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
679
865
  getPlugin(name: string): Plugin | undefined
680
866
  /**
681
- * Returns all files currently in the file manager.
682
- * Call this lazily (e.g. inside a `kubb:plugin:end` listener) to see files added by plugins
683
- * that have already run.
867
+ * Get all files currently in the file manager.
868
+ * Call this lazily (e.g. in `kubb:plugin:end`) to see files added by prior plugins.
684
869
  */
685
870
  readonly files: ReadonlyArray<FileNode>
686
871
  /**
@@ -692,27 +877,25 @@ export type KubbBuildStartContext = {
692
877
  }
693
878
 
694
879
  /**
695
- * Context passed to `kubb:plugins:end` handlers.
696
- * Fires after all plugins have run and per-plugin barrels have been written,
697
- * but BEFORE files are written to disk.
698
- * Middleware that needs to inject final files (e.g. a root barrel) should use this event.
880
+ * Context for `kubb:plugins:end` handlers.
881
+ * Fires after plugins run and per-plugin barrels are written, before final write to disk.
882
+ * Middleware that needs final files (e.g. root barrel) use this event.
699
883
  */
700
884
  export type KubbPluginsEndContext = {
701
885
  config: Config
702
886
  /**
703
- * Returns all files currently in the file manager (lazy snapshot).
704
- * Includes files added by plugins and per-plugin barrel middleware.
887
+ * All files currently in the file manager (lazy snapshot).
705
888
  */
706
889
  readonly files: ReadonlyArray<FileNode>
707
890
  /**
708
- * Upsert one or more files into the file manager.
709
- * Files added here will be included in the write pass that follows.
891
+ * Upsert files into the file manager.
892
+ * Files added here are included in the write pass.
710
893
  */
711
894
  upsertFile: (...files: Array<FileNode>) => void
712
895
  }
713
896
 
714
897
  /**
715
- * Context passed to a hook-style plugin's `kubb:build:end` handler.
898
+ * Context for hook-style plugin `kubb:build:end` handler.
716
899
  * Fires after all files have been written to disk.
717
900
  */
718
901
  export type KubbBuildEndContext = {
@@ -785,11 +968,11 @@ export type KubbFilesProcessingStartContext = {
785
968
 
786
969
  export type KubbFileProcessingUpdateContext = {
787
970
  /**
788
- * Number of files processed so far.
971
+ * Number of files processed.
789
972
  */
790
973
  processed: number
791
974
  /**
792
- * Total number of files to process.
975
+ * Total files to process.
793
976
  */
794
977
  total: number
795
978
  /**
@@ -805,8 +988,7 @@ export type KubbFileProcessingUpdateContext = {
805
988
  */
806
989
  file: FileNode
807
990
  /**
808
- * Kubb configuration.
809
- * Provides access to the current config during file processing.
991
+ * The current build configuration.
810
992
  */
811
993
  config: Config
812
994
  }
@@ -851,22 +1033,46 @@ export type KubbHookEndContext = {
851
1033
  }
852
1034
 
853
1035
  type ByTag = {
1036
+ /**
1037
+ * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
1038
+ */
854
1039
  type: 'tag'
1040
+ /**
1041
+ * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
1042
+ */
855
1043
  pattern: string | RegExp
856
1044
  }
857
1045
 
858
1046
  type ByOperationId = {
1047
+ /**
1048
+ * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
1049
+ */
859
1050
  type: 'operationId'
1051
+ /**
1052
+ * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
1053
+ */
860
1054
  pattern: string | RegExp
861
1055
  }
862
1056
 
863
1057
  type ByPath = {
1058
+ /**
1059
+ * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
1060
+ */
864
1061
  type: 'path'
1062
+ /**
1063
+ * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
1064
+ */
865
1065
  pattern: string | RegExp
866
1066
  }
867
1067
 
868
1068
  type ByMethod = {
1069
+ /**
1070
+ * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
1071
+ */
869
1072
  type: 'method'
1073
+ /**
1074
+ * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
1075
+ */
870
1076
  pattern: HttpMethod | RegExp
871
1077
  }
872
1078
  // TODO implement as alternative for ByMethod
@@ -876,30 +1082,82 @@ type ByMethod = {
876
1082
  // }
877
1083
 
878
1084
  type BySchemaName = {
1085
+ /**
1086
+ * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
1087
+ */
879
1088
  type: 'schemaName'
1089
+ /**
1090
+ * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
1091
+ */
880
1092
  pattern: string | RegExp
881
1093
  }
882
1094
 
883
1095
  type ByContentType = {
1096
+ /**
1097
+ * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
1098
+ */
884
1099
  type: 'contentType'
1100
+ /**
1101
+ * Content type to match (case-sensitive). Can be a literal string or regex pattern.
1102
+ */
885
1103
  pattern: string | RegExp
886
1104
  }
887
1105
 
888
1106
  /**
889
1107
  * A pattern filter that prevents matching nodes from being generated.
890
- * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1108
+ *
1109
+ * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
1110
+ * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1111
+ *
1112
+ * @example
1113
+ * ```ts
1114
+ * exclude: [
1115
+ * { type: 'tag', pattern: 'internal' }, // skip "internal" tag
1116
+ * { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
1117
+ * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
1118
+ * ]
1119
+ * ```
891
1120
  */
892
1121
  export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
893
1122
 
894
1123
  /**
895
1124
  * A pattern filter that restricts generation to only matching nodes.
896
- * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1125
+ *
1126
+ * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
1127
+ * tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1128
+ *
1129
+ * @example
1130
+ * ```ts
1131
+ * include: [
1132
+ * { type: 'tag', pattern: 'public' }, // generate only "public" tag
1133
+ * { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
1134
+ * ]
1135
+ * ```
897
1136
  */
898
1137
  export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
899
1138
 
900
1139
  /**
901
1140
  * A pattern filter paired with partial option overrides applied when the pattern matches.
902
- * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
1141
+ *
1142
+ * Use to customize generation for specific operations or schemas. For example, apply different output paths
1143
+ * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
1144
+ * HTTP method, schema name, or content type.
1145
+ *
1146
+ * @example
1147
+ * ```ts
1148
+ * override: [
1149
+ * {
1150
+ * type: 'tag',
1151
+ * pattern: 'admin',
1152
+ * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
1153
+ * },
1154
+ * {
1155
+ * type: 'operationId',
1156
+ * pattern: 'listPets',
1157
+ * options: { exclude: true } // skip this specific operation
1158
+ * }
1159
+ * ]
1160
+ * ```
903
1161
  */
904
1162
  export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
905
1163
  //TODO should be options: Omit<Partial<TOptions>, 'override'>