@kubb/core 5.0.0-beta.21 → 5.0.0-beta.23

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.
@@ -115,8 +115,12 @@ declare const logLevel: {
115
115
  //#endregion
116
116
  //#region src/createAdapter.d.ts
117
117
  /**
118
- * Source data passed to an adapter's `parse` function.
119
- * Mirrors the config input shape with paths resolved to absolute.
118
+ * Source data handed to an adapter's `parse` function. Mirrors the config
119
+ * input shape with paths resolved to absolute.
120
+ *
121
+ * - `{ type: 'path' }`: single file on disk.
122
+ * - `{ type: 'paths' }`: multiple files (e.g. split spec).
123
+ * - `{ type: 'data' }`: raw string or parsed object provided inline.
120
124
  */
121
125
  type AdapterSource = {
122
126
  type: 'path';
@@ -129,12 +133,12 @@ type AdapterSource = {
129
133
  paths: Array<string>;
130
134
  };
131
135
  /**
132
- * Generic type parameters for an adapter definition.
136
+ * Generic parameters used by `createAdapter` and the resulting `Adapter` type.
133
137
  *
134
- * - `TName` unique identifier (e.g. `'oas'`, `'asyncapi'`)
135
- * - `TOptions` user-facing options passed to the adapter factory
136
- * - `TResolvedOptions` options after defaults applied
137
- * - `TDocument` type of the parsed source document
138
+ * - `TName`: unique adapter identifier (`'oas'`, `'asyncapi'`, ...).
139
+ * - `TOptions`: user-facing options accepted by the adapter factory.
140
+ * - `TResolvedOptions`: options after defaults are applied.
141
+ * - `TDocument`: type of the parsed source document.
138
142
  */
139
143
  type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
140
144
  name: TName;
@@ -143,19 +147,23 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
143
147
  document: TDocument;
144
148
  };
145
149
  /**
146
- * Adapter that converts input files or data into an `InputNode`.
150
+ * Converts input files or inline data into Kubb's universal AST `InputNode`.
147
151
  *
148
- * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
149
- * universal intermediate representation that all plugins consume.
152
+ * Adapters live between the spec format and the plugins. The built-in
153
+ * `@kubb/adapter-oas` handles OpenAPI 2.0, 3.0, and 3.1; custom adapters can
154
+ * support GraphQL, gRPC, AsyncAPI, or any domain-specific schema language.
150
155
  *
151
156
  * @example
152
157
  * ```ts
158
+ * import { defineConfig } from 'kubb'
153
159
  * import { adapterOas } from '@kubb/adapter-oas'
160
+ * import { pluginTs } from '@kubb/plugin-ts'
154
161
  *
155
162
  * export default defineConfig({
163
+ * input: { path: './petStore.yaml' },
164
+ * output: { path: './src/gen' },
156
165
  * adapter: adapterOas(),
157
- * input: { path: './openapi.yaml' },
158
- * plugins: [pluginTs(), pluginZod()],
166
+ * plugins: [pluginTs()],
159
167
  * })
160
168
  * ```
161
169
  */
@@ -197,35 +205,40 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
197
205
  * Memory-efficient streaming variant of `parse()`.
198
206
  *
199
207
  * Returns an `InputStreamNode` whose `schemas` and `operations` are `AsyncIterable`.
200
- * Each `for await` loop creates a fresh parse pass over the cached in-memory document
201
- * no pre-built arrays are held in memory.
208
+ * Each `for await` loop creates a fresh parse pass over the cached in-memory document.
209
+ * No pre-built arrays are held in memory.
202
210
  */
203
211
  stream?: (source: AdapterSource) => Promise<InputStreamNode>;
204
212
  };
205
213
  type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
206
214
  /**
207
- * Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.
208
- *
209
- * Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.
210
- * Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.
215
+ * Defines a custom adapter that translates a spec format into Kubb's universal
216
+ * AST. Use this when you need to consume GraphQL, gRPC, AsyncAPI, or another
217
+ * domain-specific schema. Built-in adapters: `@kubb/adapter-oas` for
218
+ * OpenAPI/Swagger documents.
211
219
  *
212
- * @note Adapters must parse their input format to Kubb's `InputNode` structure.
220
+ * Adapters must return an `InputNode` from `parse`. That node is what every
221
+ * plugin in the build consumes.
213
222
  *
214
223
  * @example
215
224
  * ```ts
216
- * export const myAdapter = createAdapter<MyAdapter>((options) => {
217
- * return {
218
- * name: 'my-adapter',
219
- * options,
220
- * async parse(source) {
221
- * // Transform source format to InputNode
222
- * return { ... }
223
- * },
224
- * }
225
- * })
225
+ * import { createAdapter, ast, type AdapterFactoryOptions } from '@kubb/core'
226
+ *
227
+ * type MyAdapter = AdapterFactoryOptions<'my-adapter', { validate?: boolean }>
226
228
  *
227
- * // Instantiate:
228
- * const adapter = myAdapter({ validate: true })
229
+ * export const myAdapter = createAdapter<MyAdapter>((options) => ({
230
+ * name: 'my-adapter',
231
+ * options,
232
+ * document: null,
233
+ * async parse(_source) {
234
+ * // Convert `source` (path or inline data) into an InputNode.
235
+ * return ast.createInput()
236
+ * },
237
+ * getImports: () => [],
238
+ * async validate() {
239
+ * // Throw or call ctx.error here when the spec is invalid.
240
+ * },
241
+ * }))
229
242
  * ```
230
243
  */
231
244
  declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
@@ -277,17 +290,37 @@ type Renderer<TElement = unknown> = {
277
290
  */
278
291
  type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
279
292
  /**
280
- * Wraps a renderer factory for use in generator definitions.
293
+ * Defines a renderer factory. Renderers turn the generator's return value
294
+ * (JSX, a template string, a tree of any shape) into `FileNode`s that get
295
+ * written to disk.
281
296
  *
282
- * @example
297
+ * Use this to support output formats beyond JSX — for instance, a Handlebars
298
+ * renderer, a string-template renderer, or a renderer that writes binary
299
+ * files. Plugins and generators pick the renderer to use via the `renderer`
300
+ * field on `defineGenerator`.
301
+ *
302
+ * @example A minimal renderer that wraps a custom runtime
283
303
  * ```ts
284
- * export const jsxRenderer = createRenderer(() => {
285
- * const runtime = new Runtime()
304
+ * import { createRenderer } from '@kubb/core'
305
+ *
306
+ * export const myRenderer = createRenderer(() => {
307
+ * const runtime = new MyRuntime()
286
308
  * return {
287
- * async render(element) { await runtime.render(element) },
288
- * get files() { return runtime.nodes },
289
- * dispose() { runtime.unmount() },
290
- * unmount(error) { runtime.unmount(error) },
309
+ * async render(element) {
310
+ * await runtime.render(element)
311
+ * },
312
+ * get files() {
313
+ * return runtime.files
314
+ * },
315
+ * dispose() {
316
+ * runtime.dispose()
317
+ * },
318
+ * unmount(error) {
319
+ * runtime.dispose(error)
320
+ * },
321
+ * [Symbol.dispose]() {
322
+ * this.dispose()
323
+ * },
291
324
  * }
292
325
  * })
293
326
  * ```
@@ -295,70 +328,83 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
295
328
  declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
296
329
  //#endregion
297
330
  //#region src/createStorage.d.ts
331
+ /**
332
+ * Backend that persists generated files. Kubb ships with `fsStorage` (writes
333
+ * to disk) and `memoryStorage` (keeps everything in RAM). Implement this
334
+ * interface to write to S3, a database, or any other target.
335
+ */
298
336
  type Storage = {
299
337
  /**
300
- * Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
338
+ * Identifier used in logs and diagnostics (`'fs'`, `'memory'`, `'s3'`).
301
339
  */
302
340
  readonly name: string;
303
341
  /**
304
- * Returns `true` when an entry for `key` exists in storage.
342
+ * Returns `true` when an entry for `key` exists.
305
343
  */
306
344
  hasItem(key: string): Promise<boolean>;
307
345
  /**
308
- * Returns the stored string value, or `null` when `key` does not exist.
346
+ * Reads the stored string. Returns `null` when the key is missing.
309
347
  */
310
348
  getItem(key: string): Promise<string | null>;
311
349
  /**
312
- * Persists `value` under `key`, creating any required structure.
350
+ * Stores `value` under `key`, creating any required structure (directories,
351
+ * buckets, ...).
313
352
  */
314
353
  setItem(key: string, value: string): Promise<void>;
315
354
  /**
316
- * Removes the entry for `key`. No-ops when the key does not exist.
355
+ * Deletes the entry for `key`. No-op when the key does not exist.
317
356
  */
318
357
  removeItem(key: string): Promise<void>;
319
358
  /**
320
- * Returns all keys, optionally filtered to those starting with `base`.
359
+ * Returns every key. Pass `base` to filter to keys starting with that prefix.
321
360
  */
322
361
  getKeys(base?: string): Promise<Array<string>>;
323
362
  /**
324
- * Removes all entries, optionally scoped to those starting with `base`.
363
+ * Removes every entry. Pass `base` to scope the wipe to a key prefix.
325
364
  */
326
365
  clear(base?: string): Promise<void>;
327
366
  /**
328
- * Optional teardown hook called after the build completes.
367
+ * Optional teardown hook called after the build completes. Use to flush
368
+ * buffers, close connections, or release file locks.
329
369
  */
330
370
  dispose?(): Promise<void>;
331
371
  };
332
372
  /**
333
- * Factory for implementing custom storage backends that control where generated files are written.
373
+ * Defines a custom storage backend. The builder receives user options and
374
+ * returns a `Storage` implementation. Kubb ships with filesystem and
375
+ * in-memory storages — reach for this when you need to write generated files
376
+ * elsewhere (cloud storage, a database, a remote API).
334
377
  *
335
- * Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.
336
- * Kubb provides filesystem and in-memory implementations out of the box.
337
- *
338
- * @note Call the returned factory with optional options to instantiate the storage adapter.
339
- *
340
- * @example
378
+ * @example In-memory storage (the built-in implementation)
341
379
  * ```ts
342
380
  * import { createStorage } from '@kubb/core'
343
381
  *
344
382
  * export const memoryStorage = createStorage(() => {
345
383
  * const store = new Map<string, string>()
384
+ *
346
385
  * return {
347
386
  * name: 'memory',
348
- * async hasItem(key) { return store.has(key) },
349
- * async getItem(key) { return store.get(key) ?? null },
350
- * async setItem(key, value) { store.set(key, value) },
351
- * async removeItem(key) { store.delete(key) },
387
+ * async hasItem(key) {
388
+ * return store.has(key)
389
+ * },
390
+ * async getItem(key) {
391
+ * return store.get(key) ?? null
392
+ * },
393
+ * async setItem(key, value) {
394
+ * store.set(key, value)
395
+ * },
396
+ * async removeItem(key) {
397
+ * store.delete(key)
398
+ * },
352
399
  * async getKeys(base) {
353
400
  * const keys = [...store.keys()]
354
401
  * return base ? keys.filter((k) => k.startsWith(base)) : keys
355
402
  * },
356
- * async clear(base) { if (!base) store.clear() },
403
+ * async clear(base) {
404
+ * if (!base) store.clear()
405
+ * },
357
406
  * }
358
407
  * })
359
- *
360
- * // Instantiate:
361
- * const storage = memoryStorage()
362
408
  * ```
363
409
  */
364
410
  declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
@@ -376,36 +422,44 @@ type DevtoolsOptions = {
376
422
  type PrintOptions = {
377
423
  extname?: FileNode['extname'];
378
424
  };
425
+ /**
426
+ * Converts a resolved {@link FileNode} into the final source string that gets
427
+ * written to disk. Kubb ships with TypeScript and TSX parsers; add your own
428
+ * for new file types (JSON, Markdown, ...).
429
+ */
379
430
  type Parser<TMeta extends object = any> = {
431
+ /**
432
+ * Display name used in diagnostics and the parser registry.
433
+ */
380
434
  name: string;
381
435
  /**
382
- * File extensions this parser handles.
383
- * Use `undefined` to create a catch-all fallback parser.
436
+ * File extensions this parser handles. Set to `undefined` to define a
437
+ * catch-all fallback used when no other parser claims the extension.
384
438
  *
385
- * @example Handled extensions
439
+ * @example
386
440
  * `['.ts', '.js']`
387
441
  */
388
442
  extNames: Array<FileNode['extname']> | undefined;
389
443
  /**
390
- * Convert a resolved file to a string.
444
+ * Serialise the file's AST into source code.
391
445
  */
392
446
  parse(file: FileNode<TMeta>, options?: PrintOptions): string;
393
447
  };
394
448
  /**
395
- * Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.
396
- *
397
- * @note Call the returned factory with optional options to instantiate the parser.
449
+ * Defines a parser with type-safe `this`. Used to register handlers for new
450
+ * file extensions or to plug a non-TypeScript output into the build.
398
451
  *
399
452
  * @example
400
453
  * ```ts
401
- * import { defineParser } from '@kubb/core'
454
+ * import { defineParser, ast } from '@kubb/core'
402
455
  *
403
456
  * export const jsonParser = defineParser({
404
457
  * name: 'json',
405
458
  * extNames: ['.json'],
406
459
  * parse(file) {
407
- * const { extractStringsFromNodes } = await import('@kubb/ast')
408
- * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
460
+ * return file.sources
461
+ * .map((source) => ast.extractStringsFromNodes(source.nodes ?? []))
462
+ * .join('\n')
409
463
  * },
410
464
  * })
411
465
  * ```
@@ -457,47 +511,67 @@ declare class FileProcessor {
457
511
  }
458
512
  //#endregion
459
513
  //#region src/defineLogger.d.ts
514
+ /**
515
+ * Options accepted by a logger's `install` callback.
516
+ */
460
517
  type LoggerOptions = {
461
518
  /**
462
- * Log level for output verbosity.
463
- * @default 3
519
+ * Output verbosity. Use the `logLevel` constants exported from `@kubb/core`
520
+ * (`silent`, `error`, `warn`, `info`, `verbose`, `debug`).
464
521
  */
465
522
  logLevel: (typeof logLevel)[keyof typeof logLevel];
466
523
  };
467
524
  /**
468
- * Shared context passed to plugins, parsers, and other internals.
525
+ * Event emitter handed to `Logger.install`. Use `.on('kubb:info', ...)` and
526
+ * friends to subscribe to build events.
469
527
  */
470
528
  type LoggerContext = AsyncEventEmitter<KubbHooks>;
529
+ /**
530
+ * Logger contract. A logger receives the build's event emitter and subscribes
531
+ * to whichever lifecycle events it wants to forward to its destination
532
+ * (console, file, remote sink).
533
+ */
471
534
  type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {
535
+ /**
536
+ * Display name used in diagnostics.
537
+ */
472
538
  name: string;
539
+ /**
540
+ * Called once per build with the shared event emitter. Subscribe to events
541
+ * here. The return value (if any) is forwarded to whoever installed the
542
+ * logger, which is handy for sink factories.
543
+ */
473
544
  install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>;
474
545
  };
475
546
  type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>;
476
547
  /**
477
- * Wraps a logger definition into a typed {@link Logger}.
478
- *
479
- * The optional second type parameter `TInstallReturn` allows loggers to return
480
- * a value from `install` — for example, a sink factory that the caller can
481
- * forward to hook execution.
548
+ * Defines a typed logger. Use the second type parameter to declare a return
549
+ * value from `install`, which is handy when the logger exposes a sink factory
550
+ * or cleanup callback to the caller.
482
551
  *
483
552
  * @example Basic logger
484
553
  * ```ts
554
+ * import { defineLogger } from '@kubb/core'
555
+ *
485
556
  * export const myLogger = defineLogger({
486
557
  * name: 'my-logger',
487
- * install(context, options) {
488
- * context.on('kubb:info', (message) => console.log('ℹ', message))
489
- * context.on('kubb:error', (error) => console.error('✗', error.message))
558
+ * install(context) {
559
+ * context.on('kubb:info', ({ message }) => console.log('ℹ', message))
560
+ * context.on('kubb:error', ({ error }) => console.error('✗', error.message))
490
561
  * },
491
562
  * })
492
563
  * ```
493
564
  *
494
565
  * @example Logger that returns a hook sink factory
495
566
  * ```ts
567
+ * import { defineLogger, type LoggerOptions } from '@kubb/core'
568
+ * import type { HookSinkFactory } from './sinks'
569
+ *
496
570
  * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
497
571
  * name: 'my-logger',
498
- * install(context, options) {
572
+ * install(context) {
499
573
  * // … register event handlers …
500
- * return (commandWithArgs) => ({ onStdout: console.log })
574
+ * return () => ({ onStdout: console.log })
501
575
  * },
502
576
  * })
503
577
  * ```
@@ -506,36 +580,34 @@ declare function defineLogger<Options extends LoggerOptions = LoggerOptions, TIn
506
580
  //#endregion
507
581
  //#region src/defineMiddleware.d.ts
508
582
  /**
509
- * A middleware instance produced by calling a factory created with `defineMiddleware`.
510
- * It declares event handlers under a `hooks` object which are registered on the
511
- * shared emitter after all plugin hooks, so middleware handlers for any event
512
- * always fire last.
583
+ * A middleware instance. Subscribes to lifecycle events via `hooks`. Middleware
584
+ * handlers always fire after every plugin handler for the same event, so they
585
+ * see the full set of generated files.
513
586
  */
514
587
  type Middleware = {
515
588
  /**
516
- * Unique identifier for this middleware.
589
+ * Unique name. Use a `middleware-<feature>` convention (e.g.
590
+ * `middleware-barrel`).
517
591
  */
518
592
  name: string;
519
593
  /**
520
- * Lifecycle event handlers for this middleware.
521
- * Any event from the global `KubbHooks` map can be subscribed to here.
522
- * Handlers are registered after all plugin handlers, so they always fire last.
594
+ * Lifecycle event handlers. Any event from the global `KubbHooks` map can be
595
+ * subscribed to here. Handlers run after all plugin handlers for that event.
523
596
  */
524
597
  hooks: { [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void> };
525
598
  };
526
599
  /**
527
- * Creates a middleware factory using the hook-style `hooks` API.
600
+ * Creates a middleware factory. Middleware fires after every plugin handler
601
+ * for the same event, which makes it the natural place for post-processing
602
+ * (barrel files, lint runs, audit logs).
528
603
  *
529
- * Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.
530
- * Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.
604
+ * Per-build state belongs inside the factory closure so each `createKubb`
605
+ * invocation gets its own isolated instance.
531
606
  *
532
- * @note The factory can accept typed options. See examples for using options and per-build state patterns.
533
- *
534
- * @example
607
+ * @example Stateless middleware
535
608
  * ```ts
536
609
  * import { defineMiddleware } from '@kubb/core'
537
610
  *
538
- * // Stateless middleware
539
611
  * export const logMiddleware = defineMiddleware(() => ({
540
612
  * name: 'log-middleware',
541
613
  * hooks: {
@@ -544,8 +616,12 @@ type Middleware = {
544
616
  * },
545
617
  * },
546
618
  * }))
619
+ * ```
620
+ *
621
+ * @example Middleware with options and per-build state
622
+ * ```ts
623
+ * import { defineMiddleware } from '@kubb/core'
547
624
  *
548
- * // Middleware with options and per-build state
549
625
  * export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {
550
626
  * const seen = new Set<string>()
551
627
  * return {
@@ -717,49 +793,44 @@ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'],
717
793
  pluginName: T['name'];
718
794
  } & ThisType<T['resolver']>;
719
795
  /**
720
- * Defines a resolver for a plugin, injecting built-in defaults for name casing,
721
- * include/exclude/override filtering, path resolution, and file construction.
796
+ * Defines a plugin resolver. The resolver is the object that decides what
797
+ * every generated symbol and file path is called. Built-in defaults handle
798
+ * name casing, include/exclude/override filtering, output path computation,
799
+ * and file construction. Supply your own to override any of them:
722
800
  *
723
- * All four defaults can be overridden by providing them in the builder function:
724
- * - `default` — name casing strategy (camelCase / PascalCase)
725
- * - `resolveOptions` — include/exclude/override filtering
726
- * - `resolvePath` — output path computation
727
- * - `resolveFile` full `FileNode` construction
801
+ * - `default` name casing strategy (camelCase / PascalCase).
802
+ * - `resolveOptions` — include/exclude/override filtering.
803
+ * - `resolvePath` — output path computation.
804
+ * - `resolveFile` — full `FileNode` construction.
805
+ * - `resolveBanner` / `resolveFooter` — top/bottom-of-file text.
728
806
  *
729
- * Methods in the returned object can call sibling resolver methods via `this`.
807
+ * Methods in the returned object can call sibling resolver methods via `this`,
808
+ * which keeps custom rules small (`this.default(name, 'type')` to delegate).
730
809
  *
731
810
  * @example Basic resolver with naming helpers
732
811
  * ```ts
733
- * export const resolver = defineResolver<PluginTs>(() => ({
812
+ * export const resolverTs = defineResolver<PluginTs>(() => ({
734
813
  * name: 'default',
735
- * resolveName(node) {
736
- * return this.default(node.name, 'function')
814
+ * resolveName(name) {
815
+ * return this.default(name, 'function')
737
816
  * },
738
- * resolveTypedName(node) {
739
- * return this.default(node.name, 'type')
817
+ * resolveTypeName(name) {
818
+ * return this.default(name, 'type')
740
819
  * },
741
820
  * }))
742
821
  * ```
743
822
  *
744
- * @example Override resolvePath for a custom output structure
823
+ * @example Custom output path
745
824
  * ```ts
746
- * export const resolver = defineResolver<PluginTs>(() => ({
825
+ * import path from 'node:path'
826
+ *
827
+ * export const resolverTs = defineResolver<PluginTs>(() => ({
747
828
  * name: 'custom',
748
829
  * resolvePath({ baseName }, { root, output }) {
749
830
  * return path.resolve(root, output.path, 'generated', baseName)
750
831
  * },
751
832
  * }))
752
833
  * ```
753
- *
754
- * @example Use this.default inside a helper
755
- * ```ts
756
- * export const resolver = defineResolver<PluginTs>(() => ({
757
- * name: 'default',
758
- * resolveParamName(node, param) {
759
- * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
760
- * },
761
- * }))
762
- * ```
763
834
  */
764
835
  declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
765
836
  //#endregion
@@ -773,39 +844,48 @@ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverB
773
844
  */
774
845
  type ExtractRegistryKey$1<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
775
846
  /**
776
- * Output configuration for generated files.
847
+ * Output configuration shared by every plugin. Each plugin extends this with
848
+ * its own keys via the `Kubb.PluginOptionsRegistry.output` interface merge.
777
849
  */
778
850
  type Output<_TOptions = unknown> = {
779
851
  /**
780
- * Output folder or file path for generated code.
852
+ * Folder (or single file) where the plugin writes its generated code.
853
+ * Resolved against the global `output.path` set on `defineConfig`.
781
854
  */
782
855
  path: string;
783
856
  /**
784
- * Text or function prepended to every generated file.
785
- * When a function, receives the document metadata and returns a string.
857
+ * Text prepended to every generated file. Useful for license headers,
858
+ * lint disables, or `@ts-nocheck` directives. Pass a function to compute
859
+ * the banner from the file's `InputMeta`.
786
860
  */
787
861
  banner?: string | ((meta?: InputMeta) => string);
788
862
  /**
789
- * Text or function appended to every generated file.
790
- * When a function, receives the document metadata and returns a string.
863
+ * Text appended at the end of every generated file. Mirror of `banner`.
864
+ * Pass a function to compute the footer from the file's `InputMeta`.
791
865
  */
792
866
  footer?: string | ((meta?: InputMeta) => string);
793
867
  /**
794
- * Whether to override existing external files if they already exist.
868
+ * Allows the plugin to overwrite hand-written files at the same path.
869
+ * Defaults to `false` to protect manual edits.
870
+ *
795
871
  * @default false
796
872
  */
797
873
  override?: boolean;
798
874
  } & ExtractRegistryKey$1<Kubb.PluginOptionsRegistry, 'output'>;
875
+ /**
876
+ * Groups generated files into subdirectories based on an OpenAPI tag or path
877
+ * segment.
878
+ */
799
879
  type Group = {
800
880
  /**
801
- * How to group files into subdirectories.
802
- * - `'tag'` — group by OpenAPI tags
803
- * - `'path'` — group by OpenAPI paths
881
+ * Property used to assign each operation to a group.
882
+ * - `'tag'` — uses the first tag (`operation.getTags().at(0)?.name`).
883
+ * - `'path'` — uses the first segment of the operation's URL.
804
884
  */
805
885
  type: 'tag' | 'path';
806
886
  /**
807
- * Function that returns the subdirectory name for a group value.
808
- * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
887
+ * Returns the subdirectory name from the group key. Defaults to
888
+ * `${camelCase(group)}Controller` for tags, or the first path segment.
809
889
  */
810
890
  name?: (context: {
811
891
  group: string;
@@ -872,42 +952,39 @@ type ByContentType = {
872
952
  pattern: string | RegExp;
873
953
  };
874
954
  /**
875
- * A pattern filter that prevents matching nodes from being generated.
876
- *
877
- * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
878
- * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
955
+ * Filter that skips matching operations or schemas during generation. Use it
956
+ * to drop deprecated endpoints, internal-only schemas, or anything you do
957
+ * not want code generated for.
879
958
  *
880
959
  * @example
881
960
  * ```ts
882
961
  * exclude: [
883
- * { type: 'tag', pattern: 'internal' }, // skip "internal" tag
884
- * { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
885
- * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
962
+ * { type: 'tag', pattern: 'internal' },
963
+ * { type: 'path', pattern: /^\/admin/ },
964
+ * { type: 'operationId', pattern: /^deprecated_/ },
886
965
  * ]
887
966
  * ```
888
967
  */
889
968
  type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
890
969
  /**
891
- * A pattern filter that restricts generation to only matching nodes.
892
- *
893
- * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
894
- * tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
970
+ * Filter that restricts generation to operations or schemas matching at least
971
+ * one entry. Useful for partial builds (one tag, one API version).
895
972
  *
896
973
  * @example
897
974
  * ```ts
898
975
  * include: [
899
- * { type: 'tag', pattern: 'public' }, // generate only "public" tag
900
- * { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
976
+ * { type: 'tag', pattern: 'public' },
977
+ * { type: 'path', pattern: /^\/api\/v1/ },
901
978
  * ]
902
979
  * ```
903
980
  */
904
981
  type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
905
982
  /**
906
- * A pattern filter paired with partial option overrides applied when the pattern matches.
983
+ * Filter paired with a partial options object. When the filter matches, the
984
+ * options are merged on top of the plugin defaults for that operation only.
985
+ * Useful for "this one tag goes to a different folder" rules.
907
986
  *
908
- * Use to customize generation for specific operations or schemas. For example, apply different output paths
909
- * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
910
- * HTTP method, schema name, or content type.
987
+ * Entries are evaluated top to bottom; the first matching entry wins.
911
988
  *
912
989
  * @example
913
990
  * ```ts
@@ -915,13 +992,13 @@ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySch
915
992
  * {
916
993
  * type: 'tag',
917
994
  * pattern: 'admin',
918
- * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
995
+ * options: { output: { path: './src/gen/admin' } },
919
996
  * },
920
997
  * {
921
998
  * type: 'operationId',
922
999
  * pattern: 'listPets',
923
- * options: { exclude: true } // skip this specific operation
924
- * }
1000
+ * options: { enumType: 'literal' },
1001
+ * },
925
1002
  * ]
926
1003
  * ```
927
1004
  */
@@ -1075,13 +1152,13 @@ type KubbPluginEndContext = {
1075
1152
  upsertFile: (...files: Array<FileNode>) => void;
1076
1153
  };
1077
1154
  /**
1078
- * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
1079
- *
1080
- * Handlers live in a single `hooks` object (inspired by Astro integrations).
1081
- * All lifecycle events from `KubbHooks` are available for subscription.
1155
+ * Wraps a plugin factory and returns a function that accepts user options and
1156
+ * yields a fully typed `Plugin`. Lifecycle handlers go inside a single
1157
+ * `hooks` object (inspired by Astro integrations).
1082
1158
  *
1083
- * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
1084
- * Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
1159
+ * Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
1160
+ * `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
1161
+ * convention (`plugin-react-query`, `plugin-zod`, ...).
1085
1162
  *
1086
1163
  * @example
1087
1164
  * ```ts
@@ -1343,8 +1420,8 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
1343
1420
  * Declares a named generator unit that walks the AST and emits files.
1344
1421
  *
1345
1422
  * Each method (`schema`, `operation`, `operations`) is called for the matching node type.
1346
- * Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.
1347
- * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.
1423
+ * Each method returns `TElement | Array<FileNode> | undefined | null`. JSX-based generators require a `renderer` factory.
1424
+ * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `undefined` or `null` to bypass rendering.
1348
1425
  *
1349
1426
  * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
1350
1427
  *
@@ -1394,24 +1471,47 @@ type Generator$1<TOptions extends PluginFactoryOptions = PluginFactoryOptions, T
1394
1471
  * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1395
1472
  * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1396
1473
  */
1397
- schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1474
+ schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1398
1475
  /**
1399
1476
  * Called for each operation node in the AST walk.
1400
1477
  * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1401
1478
  * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1402
1479
  */
1403
- operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1480
+ operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1404
1481
  /**
1405
1482
  * Called once after all operations have been walked.
1406
1483
  * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1407
1484
  * plus `ctx.options` with the plugin-level options for the batch call.
1408
1485
  */
1409
- operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1486
+ operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1410
1487
  };
1411
1488
  /**
1412
- * Defines a generator. Returns the object as-is with correct `this` typings.
1413
- * `applyHookResult` handles renderer elements and `File[]` uniformly using
1414
- * the generator's declared `renderer` factory.
1489
+ * Defines a generator: a unit of work that runs during the plugin's AST walk
1490
+ * and produces files. Plugins register generators via `ctx.addGenerator()`
1491
+ * inside `kubb:plugin:setup`.
1492
+ *
1493
+ * The returned object is the input as-is, but with `this` types preserved so
1494
+ * `schema`/`operation`/`operations` methods are correctly typed against the
1495
+ * plugin's `PluginFactoryOptions`. Renderer elements and `FileNode[]` returns
1496
+ * are both handled by the runtime — pick whichever style fits.
1497
+ *
1498
+ * @example JSX-based schema generator
1499
+ * ```tsx
1500
+ * import { defineGenerator } from '@kubb/core'
1501
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1502
+ *
1503
+ * export const typeGenerator = defineGenerator({
1504
+ * name: 'typescript',
1505
+ * renderer: jsxRenderer,
1506
+ * schema(node, ctx) {
1507
+ * return (
1508
+ * <File path={`${ctx.root}/${node.name}.ts`}>
1509
+ * <Type node={node} resolver={ctx.resolver} />
1510
+ * </File>
1511
+ * )
1512
+ * },
1513
+ * })
1514
+ * ```
1415
1515
  */
1416
1516
  declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator$1<TOptions, TElement>): Generator$1<TOptions, TElement>;
1417
1517
  //#endregion
@@ -1486,22 +1586,25 @@ type Config<TInput = Input> = {
1486
1586
  */
1487
1587
  name?: string;
1488
1588
  /**
1489
- * Project root directory, absolute or relative to the config file.
1490
- * @default process.cwd()
1589
+ * Project root directory, absolute or relative to the config file. Already
1590
+ * resolved on the `Config` instance — see `UserConfig` for the optional
1591
+ * form that defaults to `process.cwd()`.
1491
1592
  */
1492
1593
  root: string;
1493
1594
  /**
1494
- * Parsers that convert generated files to strings.
1495
- * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
1496
- * A fallback parser is appended for unhandled extensions.
1497
- * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
1595
+ * Parsers that convert generated files into strings. Each parser handles a
1596
+ * set of file extensions; a fallback parser handles anything else.
1597
+ *
1598
+ * Already resolved on the `Config` instance — see `UserConfig` for the
1599
+ * optional form that defaults to `[parserTs, parserTsx]`.
1498
1600
  *
1499
- * @default [parserTs] from `@kubb/parser-ts`
1500
1601
  * @example
1501
1602
  * ```ts
1502
- * import { parserTs, tsxParser } from '@kubb/parser-ts'
1603
+ * import { defineConfig } from 'kubb'
1604
+ * import { parserTs, parserTsx } from '@kubb/parser-ts'
1605
+ *
1503
1606
  * export default defineConfig({
1504
- * parsers: [parserTs, tsxParser],
1607
+ * parsers: [parserTs, parserTsx],
1505
1608
  * })
1506
1609
  * ```
1507
1610
  */
@@ -2192,6 +2295,11 @@ type CLIOptions = {
2192
2295
  * Path to the Kubb config file.
2193
2296
  */
2194
2297
  config?: string;
2298
+ /**
2299
+ * OpenAPI input path passed as the positional argument to `kubb generate`.
2300
+ * Overrides `config.input.path` when set.
2301
+ */
2302
+ input?: string;
2195
2303
  /**
2196
2304
  * Re-run generation whenever input files change.
2197
2305
  */
@@ -2199,9 +2307,9 @@ type CLIOptions = {
2199
2307
  /**
2200
2308
  * Controls how much output the CLI prints.
2201
2309
  *
2202
- * @default 'silent'
2310
+ * @default 'info'
2203
2311
  */
2204
- logLevel?: 'silent' | 'info' | 'debug';
2312
+ logLevel?: 'silent' | 'info' | 'verbose' | 'debug';
2205
2313
  };
2206
2314
  /**
2207
2315
  * All accepted forms of a Kubb configuration.
@@ -2298,10 +2406,26 @@ declare class Kubb$1 {
2298
2406
  [Symbol.dispose](): void;
2299
2407
  }
2300
2408
  /**
2301
- * Factory for {@link Kubb}. Equivalent to `new Kubb(userConfig, options)` and kept
2302
- * as the canonical public entry point.
2409
+ * Constructs a {@link Kubb} build orchestrator from a user config. Equivalent
2410
+ * to `new Kubb(userConfig, options)` and the canonical public entry point.
2411
+ *
2412
+ * @example
2413
+ * ```ts
2414
+ * import { createKubb } from '@kubb/core'
2415
+ * import { adapterOas } from '@kubb/adapter-oas'
2416
+ * import { pluginTs } from '@kubb/plugin-ts'
2417
+ *
2418
+ * const kubb = createKubb({
2419
+ * input: { path: './petStore.yaml' },
2420
+ * output: { path: './src/gen' },
2421
+ * adapter: adapterOas(),
2422
+ * plugins: [pluginTs()],
2423
+ * })
2424
+ *
2425
+ * await kubb.build()
2426
+ * ```
2303
2427
  */
2304
2428
  declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
2305
2429
  //#endregion
2306
2430
  export { ResolverFileParams as $, createKubb as A, KubbPluginEndContext as B, KubbLifecycleStartContext as C, createAdapter as Ct, KubbWarnContext as D, KubbVersionNewContext as E, KubbDriver as F, Override as G, KubbPluginStartContext as H, FileManager as I, definePlugin as J, Plugin as K, Exclude as L, Generator$1 as M, GeneratorContext as N, PossibleConfig as O, defineGenerator as P, ResolverContext as Q, Group as R, KubbInfoContext as S, AdapterSource as St, KubbSuccessContext as T, AsyncEventEmitter as Tt, NormalizedPlugin as U, KubbPluginSetupContext as V, Output as W, ResolveOptionsContext as X, ResolveBannerContext as Y, Resolver as Z, KubbGenerationStartContext as _, Renderer as _t, InputPath as a, LoggerContext as at, KubbHookStartContext as b, Adapter as bt, KubbBuildStartContext as c, defineLogger as ct, KubbErrorContext as d, ParsedFile as dt, ResolverPathParams as et, KubbFileProcessingUpdate as f, Parser as ft, KubbGenerationEndContext as g, createStorage as gt, KubbFilesProcessingUpdateContext as h, Storage as ht, InputData as i, Logger as it, isInputPath as j, UserConfig as k, KubbConfigEndContext as l, FileProcessor as lt, KubbFilesProcessingStartContext as m, DevtoolsOptions as mt, CLIOptions as n, Middleware as nt, Kubb$1 as o, LoggerOptions as ot, KubbFilesProcessingEndContext as p, defineParser as pt, PluginFactoryOptions as q, Config as r, defineMiddleware as rt, KubbBuildEndContext as s, UserLogger as st, BuildOutput as t, defineResolver as tt, KubbDebugContext as u, FileProcessorEvents as ut, KubbGenerationSummaryContext as v, RendererFactory as vt, KubbPluginsEndContext as w, logLevel as wt, KubbHooks as x, AdapterFactoryOptions as xt, KubbHookEndContext as y, createRenderer as yt, Include as z };
2307
- //# sourceMappingURL=createKubb-CYrw_xaR.d.ts.map
2431
+ //# sourceMappingURL=createKubb-CvfQXK_j.d.ts.map