@kubb/oas 4.20.2 → 4.20.5

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/dist/index.d.cts CHANGED
@@ -5,8 +5,7 @@ import { Operation as Operation$1 } from "oas/operation";
5
5
  import { OpenAPIV3, OpenAPIV3 as OpenAPIV3$1, OpenAPIV3_1, OpenAPIV3_1 as OpenAPIV3_1$1 } from "openapi-types";
6
6
  import * as OasTypes from "oas/types";
7
7
  import { DiscriminatorObject as DiscriminatorObject$1, HttpMethods as HttpMethods$1, MediaTypeObject as MediaTypeObject$1, OASDocument, ParameterObject, ResponseObject as ResponseObject$1, SchemaObject as SchemaObject$1 } from "oas/types";
8
- import { KubbFile } from "@kubb/fabric-core/types";
9
- import { Fabric } from "@kubb/react-fabric";
8
+ import { Config } from "@kubb/core";
10
9
 
11
10
  //#region rolldown:runtime
12
11
  //#endregion
@@ -74,608 +73,6 @@ declare class Oas extends BaseOas {
74
73
  };
75
74
  }
76
75
  //#endregion
77
- //#region ../core/src/Kubb.d.ts
78
- type DebugEvent = {
79
- date: Date;
80
- logs: string[];
81
- fileName?: string;
82
- };
83
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
84
- hookName: H;
85
- plugins: Array<Plugin>;
86
- };
87
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
88
- hookName: H;
89
- };
90
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
91
- strategy: Strategy;
92
- hookName: H;
93
- plugin: Plugin;
94
- parameters?: unknown[] | undefined;
95
- output?: unknown;
96
- };
97
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
98
- duration: number;
99
- strategy: Strategy;
100
- hookName: H;
101
- plugin: Plugin;
102
- parameters?: unknown[] | undefined;
103
- output?: unknown;
104
- };
105
- /**
106
- * Events emitted during the Kubb code generation lifecycle.
107
- * These events can be listened to for logging, progress tracking, and custom integrations.
108
- *
109
- * @example
110
- * ```typescript
111
- * import type { AsyncEventEmitter } from '@kubb/core'
112
- * import type { KubbEvents } from '@kubb/core'
113
- *
114
- * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
115
- *
116
- * events.on('lifecycle:start', () => {
117
- * console.log('Starting Kubb generation')
118
- * })
119
- *
120
- * events.on('plugin:end', (plugin, { duration }) => {
121
- * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
122
- * })
123
- * ```
124
- */
125
- interface KubbEvents {
126
- /**
127
- * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
128
- */
129
- 'lifecycle:start': [version: string];
130
- /**
131
- * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
132
- */
133
- 'lifecycle:end': [];
134
- /**
135
- * Emitted when configuration loading starts.
136
- */
137
- 'config:start': [];
138
- /**
139
- * Emitted when configuration loading is complete.
140
- */
141
- 'config:end': [configs: Array<Config>];
142
- /**
143
- * Emitted when code generation phase starts.
144
- */
145
- 'generation:start': [config: Config];
146
- /**
147
- * Emitted when code generation phase completes.
148
- */
149
- 'generation:end': [Config: Config];
150
- /**
151
- * Emitted with a summary of the generation results.
152
- * Contains summary lines, title, and success status.
153
- */
154
- 'generation:summary': [Config: Config, {
155
- failedPlugins: Set<{
156
- plugin: Plugin;
157
- error: Error;
158
- }>;
159
- status: 'success' | 'failed';
160
- hrStart: [number, number];
161
- filesCreated: number;
162
- pluginTimings?: Map<string, number>;
163
- }];
164
- /**
165
- * Emitted when code formatting starts (e.g., running Biome or Prettier).
166
- */
167
- 'format:start': [];
168
- /**
169
- * Emitted when code formatting completes.
170
- */
171
- 'format:end': [];
172
- /**
173
- * Emitted when linting starts.
174
- */
175
- 'lint:start': [];
176
- /**
177
- * Emitted when linting completes.
178
- */
179
- 'lint:end': [];
180
- /**
181
- * Emitted when plugin hooks execution starts.
182
- */
183
- 'hooks:start': [];
184
- /**
185
- * Emitted when plugin hooks execution completes.
186
- */
187
- 'hooks:end': [];
188
- /**
189
- * Emitted when a single hook execution starts. (e.g., format or lint).
190
- * The callback should be invoked when the command completes.
191
- */
192
- 'hook:start': [{
193
- id?: string;
194
- command: string;
195
- args?: readonly string[];
196
- }];
197
- /**
198
- * Emitted when a single hook execution completes.
199
- */
200
- 'hook:end': [{
201
- id?: string;
202
- command: string;
203
- args?: readonly string[];
204
- success: boolean;
205
- error: Error | null;
206
- }];
207
- /**
208
- * Emitted when a new version of Kubb is available.
209
- */
210
- 'version:new': [currentVersion: string, latestVersion: string];
211
- /**
212
- * Informational message event.
213
- */
214
- info: [message: string, info?: string];
215
- /**
216
- * Error event. Emitted when an error occurs during code generation.
217
- */
218
- error: [error: Error, meta?: Record<string, unknown>];
219
- /**
220
- * Success message event.
221
- */
222
- success: [message: string, info?: string];
223
- /**
224
- * Warning message event.
225
- */
226
- warn: [message: string, info?: string];
227
- /**
228
- * Debug event for detailed logging.
229
- * Contains timestamp, log messages, and optional filename.
230
- */
231
- debug: [meta: DebugEvent];
232
- /**
233
- * Emitted when file processing starts.
234
- * Contains the list of files to be processed.
235
- */
236
- 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
237
- /**
238
- * Emitted for each file being processed, providing progress updates.
239
- * Contains processed count, total count, percentage, and file details.
240
- */
241
- 'file:processing:update': [{
242
- /** Number of files processed so far */
243
- processed: number;
244
- /** Total number of files to process */
245
- total: number;
246
- /** Processing percentage (0-100) */
247
- percentage: number;
248
- /** Optional source identifier */
249
- source?: string;
250
- /** The file being processed */
251
- file: KubbFile.ResolvedFile;
252
- /**
253
- * Kubb configuration (not present in Fabric).
254
- * Provides access to the current config during file processing.
255
- */
256
- config: Config;
257
- }];
258
- /**
259
- * Emitted when file processing completes.
260
- * Contains the list of processed files.
261
- */
262
- 'files:processing:end': [files: KubbFile.ResolvedFile[]];
263
- /**
264
- * Emitted when a plugin starts executing.
265
- */
266
- 'plugin:start': [plugin: Plugin];
267
- /**
268
- * Emitted when a plugin completes execution.
269
- * Duration in ms
270
- */
271
- 'plugin:end': [plugin: Plugin, meta: {
272
- duration: number;
273
- success: boolean;
274
- error?: Error;
275
- }];
276
- /**
277
- * Emitted when plugin hook progress tracking starts.
278
- * Contains the hook name and list of plugins to execute.
279
- */
280
- 'plugins:hook:progress:start': [meta: ProgressStartMeta];
281
- /**
282
- * Emitted when plugin hook progress tracking ends.
283
- * Contains the hook name that completed.
284
- */
285
- 'plugins:hook:progress:end': [meta: ProgressStopMeta];
286
- /**
287
- * Emitted when a plugin hook starts processing.
288
- * Contains strategy, hook name, plugin, parameters, and output.
289
- */
290
- 'plugins:hook:processing:start': [meta: ExecutingMeta];
291
- /**
292
- * Emitted when a plugin hook completes processing.
293
- * Contains duration, strategy, hook name, plugin, parameters, and output.
294
- */
295
- 'plugins:hook:processing:end': [meta: ExecutedMeta];
296
- }
297
- //#endregion
298
- //#region ../core/src/utils/AsyncEventEmitter.d.ts
299
- declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
300
- #private;
301
- constructor(maxListener?: number);
302
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
303
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
304
- onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
305
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
306
- removeAll(): void;
307
- }
308
- //#endregion
309
- //#region ../core/src/utils/types.d.ts
310
- type PossiblePromise<T> = Promise<T> | T;
311
- //#endregion
312
- //#region ../core/src/types.d.ts
313
- declare global {
314
- namespace Kubb {
315
- interface PluginContext {}
316
- }
317
- }
318
- /**
319
- * Config used in `kubb.config.ts`
320
- *
321
- * @example
322
- * import { defineConfig } from '@kubb/core'
323
- * export default defineConfig({
324
- * ...
325
- * })
326
- */
327
-
328
- type InputPath = {
329
- /**
330
- * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
331
- */
332
- path: string;
333
- };
334
- type InputData = {
335
- /**
336
- * A `string` or `object` that contains your Swagger/OpenAPI data.
337
- */
338
- data: string | unknown;
339
- };
340
- type Input = InputPath | InputData | Array<InputPath>;
341
- type BarrelType = 'all' | 'named' | 'propagate';
342
- /**
343
- * @private
344
- */
345
- type Config<TInput = Input> = {
346
- /**
347
- * The name to display in the CLI output.
348
- */
349
- name?: string;
350
- /**
351
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
352
- * @default process.cwd()
353
- */
354
- root: string;
355
- /**
356
- * You can use either `input.path` or `input.data`, depending on your specific needs.
357
- */
358
- input: TInput;
359
- output: {
360
- /**
361
- * The path where all generated files receives exported.
362
- * This can be an absolute path or a path relative to the specified root option.
363
- */
364
- path: string;
365
- /**
366
- * Clean the output directory before each build.
367
- */
368
- clean?: boolean;
369
- /**
370
- * Save files to the file system.
371
- * @default true
372
- */
373
- write?: boolean;
374
- /**
375
- * Specifies the formatting tool to be used.
376
- * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
377
- * - 'prettier' uses Prettier for code formatting.
378
- * - 'biome' uses Biome for code formatting.
379
- * - 'oxfmt' uses Oxfmt for code formatting.
380
- * - false disables code formatting.
381
- * @default 'prettier'
382
- */
383
- format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
384
- /**
385
- * Specifies the linter that should be used to analyze the code.
386
- * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
387
- * - 'eslint' uses ESLint for linting.
388
- * - 'biome' uses Biome for linting.
389
- * - 'oxlint' uses Oxlint for linting.
390
- * - false disables linting.
391
- * @default 'auto'
392
- */
393
- lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
394
- /**
395
- * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
396
- * @default { '.ts': '.ts'}
397
- */
398
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
399
- /**
400
- * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
401
- * @default 'named'
402
- */
403
- barrelType?: Exclude<BarrelType, 'propagate'> | false;
404
- /**
405
- * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
406
- * - 'simple' adds banner with link to Kubb.
407
- * - 'full' adds source, title, description, and OpenAPI version.
408
- * - false disables banner generation.
409
- * @default 'simple'
410
- */
411
- defaultBanner?: 'simple' | 'full' | false;
412
- /**
413
- * Whether to override existing external files if they already exist.
414
- * When setting the option in the global configuration, all plugins inherit the same behavior by default.
415
- * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
416
- * @default false
417
- */
418
- override?: boolean;
419
- };
420
- /**
421
- * An array of Kubb plugins that used in the generation.
422
- * Each plugin may include additional configurable options(defined in the plugin itself).
423
- * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
424
- */
425
- plugins?: Array<Plugin>;
426
- /**
427
- * Hooks triggered when a specific action occurs in Kubb.
428
- */
429
- hooks?: {
430
- /**
431
- * Hook that triggers at the end of all executions.
432
- * Useful for running Prettier or ESLint to format/lint your code.
433
- */
434
- done?: string | Array<string>;
435
- };
436
- };
437
- type PluginFactoryOptions<
438
- /**
439
- * Name to be used for the plugin, this will also be used for they key.
440
- */
441
- TName extends string = string,
442
- /**
443
- * Options of the plugin.
444
- */
445
- TOptions extends object = object,
446
- /**
447
- * Options of the plugin that can be used later on, see `options` inside your plugin config.
448
- */
449
- TResolvedOptions extends object = TOptions,
450
- /**
451
- * Context that you want to expose to other plugins.
452
- */
453
- TContext = any,
454
- /**
455
- * When calling `resolvePath` you can specify better types.
456
- */
457
- TResolvePathOptions extends object = object> = {
458
- name: TName;
459
- /**
460
- * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
461
- */
462
- key: PluginKey<TName | string>;
463
- options: TOptions;
464
- resolvedOptions: TResolvedOptions;
465
- context: TContext;
466
- resolvePathOptions: TResolvePathOptions;
467
- };
468
- type PluginKey<TName> = [name: TName, identifier?: string | number];
469
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
470
- /**
471
- * Unique name used for the plugin
472
- * @example @kubb/typescript
473
- */
474
- name: TOptions['name'];
475
- /**
476
- * Internal key used when a developer uses more than one of the same plugin
477
- * @private
478
- */
479
- key: TOptions['key'];
480
- /**
481
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
482
- * Can be used to validate dependent plugins.
483
- */
484
- pre?: Array<string>;
485
- /**
486
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
487
- */
488
- post?: Array<string>;
489
- /**
490
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
491
- */
492
- options: TOptions['resolvedOptions'];
493
- install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
494
- /**
495
- * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
496
- */
497
- inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
498
- };
499
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
500
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
501
- /**
502
- * Start of the lifecycle of a plugin.
503
- * @type hookParallel
504
- */
505
- install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
506
- /**
507
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
508
- * Options can als be included.
509
- * @type hookFirst
510
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
511
- */
512
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
513
- /**
514
- * Resolve to a name based on a string.
515
- * Useful when converting to PascalCase or camelCase.
516
- * @type hookFirst
517
- * @example ('pet') => 'Pet'
518
- */
519
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
520
- };
521
- type PluginLifecycleHooks = keyof PluginLifecycle;
522
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
523
- type ResolvePathParams<TOptions = object> = {
524
- pluginKey?: Plugin['key'];
525
- baseName: KubbFile.BaseName;
526
- mode?: KubbFile.Mode;
527
- /**
528
- * Options to be passed to 'resolvePath' 3th parameter
529
- */
530
- options?: TOptions;
531
- };
532
- type ResolveNameParams = {
533
- name: string;
534
- pluginKey?: Plugin['key'];
535
- /**
536
- * Specifies the type of entity being named.
537
- * - 'file' customizes the name of the created file (uses camelCase).
538
- * - 'function' customizes the exported function names (uses camelCase).
539
- * - 'type' customizes TypeScript types (uses PascalCase).
540
- * - 'const' customizes variable names (uses camelCase).
541
- * @default undefined
542
- */
543
- type?: 'file' | 'function' | 'type' | 'const';
544
- };
545
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
546
- fabric: Fabric;
547
- config: Config;
548
- pluginManager: PluginManager;
549
- /**
550
- * Only add when the file does not exist yet
551
- */
552
- addFile: (...file: Array<KubbFile.File>) => Promise<void>;
553
- /**
554
- * merging multiple sources into the same output file
555
- */
556
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
557
- events: AsyncEventEmitter<KubbEvents>;
558
- mode: KubbFile.Mode;
559
- /**
560
- * Current plugin
561
- */
562
- plugin: Plugin<TOptions>;
563
- } & Kubb.PluginContext;
564
- //#endregion
565
- //#region ../core/src/PluginManager.d.ts
566
- type RequiredPluginLifecycle = Required<PluginLifecycle>;
567
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
568
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
569
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
570
- result: Result;
571
- plugin: Plugin;
572
- };
573
- type Options = {
574
- fabric: Fabric;
575
- events: AsyncEventEmitter<KubbEvents>;
576
- /**
577
- * @default Number.POSITIVE_INFINITY
578
- */
579
- concurrency?: number;
580
- };
581
- type GetFileProps<TOptions = object> = {
582
- name: string;
583
- mode?: KubbFile.Mode;
584
- extname: KubbFile.Extname;
585
- pluginKey: Plugin['key'];
586
- options?: TOptions;
587
- };
588
- declare class PluginManager {
589
- #private;
590
- readonly config: Config;
591
- readonly options: Options;
592
- constructor(config: Config, options: Options);
593
- get events(): AsyncEventEmitter<KubbEvents>;
594
- getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
595
- get plugins(): Array<Plugin>;
596
- getFile<TOptions = object>({
597
- name,
598
- mode,
599
- extname,
600
- pluginKey,
601
- options
602
- }: GetFileProps<TOptions>): KubbFile.File<{
603
- pluginKey: Plugin['key'];
604
- }>;
605
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
606
- resolveName: (params: ResolveNameParams) => string;
607
- /**
608
- * Run a specific hookName for plugin x.
609
- */
610
- hookForPlugin<H extends PluginLifecycleHooks>({
611
- pluginKey,
612
- hookName,
613
- parameters
614
- }: {
615
- pluginKey: Plugin['key'];
616
- hookName: H;
617
- parameters: PluginParameter<H>;
618
- }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
619
- /**
620
- * Run a specific hookName for plugin x.
621
- */
622
- hookForPluginSync<H extends PluginLifecycleHooks>({
623
- pluginKey,
624
- hookName,
625
- parameters
626
- }: {
627
- pluginKey: Plugin['key'];
628
- hookName: H;
629
- parameters: PluginParameter<H>;
630
- }): Array<ReturnType<ParseResult<H>>> | null;
631
- /**
632
- * Returns the first non-null result.
633
- */
634
- hookFirst<H extends PluginLifecycleHooks>({
635
- hookName,
636
- parameters,
637
- skipped
638
- }: {
639
- hookName: H;
640
- parameters: PluginParameter<H>;
641
- skipped?: ReadonlySet<Plugin> | null;
642
- }): Promise<SafeParseResult<H>>;
643
- /**
644
- * Returns the first non-null result.
645
- */
646
- hookFirstSync<H extends PluginLifecycleHooks>({
647
- hookName,
648
- parameters,
649
- skipped
650
- }: {
651
- hookName: H;
652
- parameters: PluginParameter<H>;
653
- skipped?: ReadonlySet<Plugin> | null;
654
- }): SafeParseResult<H>;
655
- /**
656
- * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
657
- */
658
- hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
659
- hookName,
660
- parameters
661
- }: {
662
- hookName: H;
663
- parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
664
- }): Promise<Awaited<TOutput>[]>;
665
- /**
666
- * Chains plugins
667
- */
668
- hookSeq<H extends PluginLifecycleHooks>({
669
- hookName,
670
- parameters
671
- }: {
672
- hookName: H;
673
- parameters?: PluginParameter<H>;
674
- }): Promise<void>;
675
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
676
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
677
- }
678
- //#endregion
679
76
  //#region src/utils.d.ts
680
77
  declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1$1.Document;
681
78
  declare function isParameterObject(obj: ParameterObject | SchemaObject$1): obj is ParameterObject;
package/dist/index.d.ts CHANGED
@@ -6,8 +6,7 @@ import { DiscriminatorObject as DiscriminatorObject$1, HttpMethods as HttpMethod
6
6
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
7
  import { Operation as Operation$1 } from "oas/operation";
8
8
  import { OpenAPIV3, OpenAPIV3 as OpenAPIV3$1, OpenAPIV3_1, OpenAPIV3_1 as OpenAPIV3_1$1 } from "openapi-types";
9
- import { KubbFile } from "@kubb/fabric-core/types";
10
- import { Fabric } from "@kubb/react-fabric";
9
+ import { Config } from "@kubb/core";
11
10
 
12
11
  //#region src/types.d.ts
13
12
  type contentType = 'application/json' | (string & {});
@@ -73,608 +72,6 @@ declare class Oas extends BaseOas {
73
72
  };
74
73
  }
75
74
  //#endregion
76
- //#region ../core/src/Kubb.d.ts
77
- type DebugEvent = {
78
- date: Date;
79
- logs: string[];
80
- fileName?: string;
81
- };
82
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
83
- hookName: H;
84
- plugins: Array<Plugin>;
85
- };
86
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
87
- hookName: H;
88
- };
89
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
90
- strategy: Strategy;
91
- hookName: H;
92
- plugin: Plugin;
93
- parameters?: unknown[] | undefined;
94
- output?: unknown;
95
- };
96
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
97
- duration: number;
98
- strategy: Strategy;
99
- hookName: H;
100
- plugin: Plugin;
101
- parameters?: unknown[] | undefined;
102
- output?: unknown;
103
- };
104
- /**
105
- * Events emitted during the Kubb code generation lifecycle.
106
- * These events can be listened to for logging, progress tracking, and custom integrations.
107
- *
108
- * @example
109
- * ```typescript
110
- * import type { AsyncEventEmitter } from '@kubb/core'
111
- * import type { KubbEvents } from '@kubb/core'
112
- *
113
- * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
114
- *
115
- * events.on('lifecycle:start', () => {
116
- * console.log('Starting Kubb generation')
117
- * })
118
- *
119
- * events.on('plugin:end', (plugin, { duration }) => {
120
- * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
121
- * })
122
- * ```
123
- */
124
- interface KubbEvents {
125
- /**
126
- * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
127
- */
128
- 'lifecycle:start': [version: string];
129
- /**
130
- * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
131
- */
132
- 'lifecycle:end': [];
133
- /**
134
- * Emitted when configuration loading starts.
135
- */
136
- 'config:start': [];
137
- /**
138
- * Emitted when configuration loading is complete.
139
- */
140
- 'config:end': [configs: Array<Config>];
141
- /**
142
- * Emitted when code generation phase starts.
143
- */
144
- 'generation:start': [config: Config];
145
- /**
146
- * Emitted when code generation phase completes.
147
- */
148
- 'generation:end': [Config: Config];
149
- /**
150
- * Emitted with a summary of the generation results.
151
- * Contains summary lines, title, and success status.
152
- */
153
- 'generation:summary': [Config: Config, {
154
- failedPlugins: Set<{
155
- plugin: Plugin;
156
- error: Error;
157
- }>;
158
- status: 'success' | 'failed';
159
- hrStart: [number, number];
160
- filesCreated: number;
161
- pluginTimings?: Map<string, number>;
162
- }];
163
- /**
164
- * Emitted when code formatting starts (e.g., running Biome or Prettier).
165
- */
166
- 'format:start': [];
167
- /**
168
- * Emitted when code formatting completes.
169
- */
170
- 'format:end': [];
171
- /**
172
- * Emitted when linting starts.
173
- */
174
- 'lint:start': [];
175
- /**
176
- * Emitted when linting completes.
177
- */
178
- 'lint:end': [];
179
- /**
180
- * Emitted when plugin hooks execution starts.
181
- */
182
- 'hooks:start': [];
183
- /**
184
- * Emitted when plugin hooks execution completes.
185
- */
186
- 'hooks:end': [];
187
- /**
188
- * Emitted when a single hook execution starts. (e.g., format or lint).
189
- * The callback should be invoked when the command completes.
190
- */
191
- 'hook:start': [{
192
- id?: string;
193
- command: string;
194
- args?: readonly string[];
195
- }];
196
- /**
197
- * Emitted when a single hook execution completes.
198
- */
199
- 'hook:end': [{
200
- id?: string;
201
- command: string;
202
- args?: readonly string[];
203
- success: boolean;
204
- error: Error | null;
205
- }];
206
- /**
207
- * Emitted when a new version of Kubb is available.
208
- */
209
- 'version:new': [currentVersion: string, latestVersion: string];
210
- /**
211
- * Informational message event.
212
- */
213
- info: [message: string, info?: string];
214
- /**
215
- * Error event. Emitted when an error occurs during code generation.
216
- */
217
- error: [error: Error, meta?: Record<string, unknown>];
218
- /**
219
- * Success message event.
220
- */
221
- success: [message: string, info?: string];
222
- /**
223
- * Warning message event.
224
- */
225
- warn: [message: string, info?: string];
226
- /**
227
- * Debug event for detailed logging.
228
- * Contains timestamp, log messages, and optional filename.
229
- */
230
- debug: [meta: DebugEvent];
231
- /**
232
- * Emitted when file processing starts.
233
- * Contains the list of files to be processed.
234
- */
235
- 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
236
- /**
237
- * Emitted for each file being processed, providing progress updates.
238
- * Contains processed count, total count, percentage, and file details.
239
- */
240
- 'file:processing:update': [{
241
- /** Number of files processed so far */
242
- processed: number;
243
- /** Total number of files to process */
244
- total: number;
245
- /** Processing percentage (0-100) */
246
- percentage: number;
247
- /** Optional source identifier */
248
- source?: string;
249
- /** The file being processed */
250
- file: KubbFile.ResolvedFile;
251
- /**
252
- * Kubb configuration (not present in Fabric).
253
- * Provides access to the current config during file processing.
254
- */
255
- config: Config;
256
- }];
257
- /**
258
- * Emitted when file processing completes.
259
- * Contains the list of processed files.
260
- */
261
- 'files:processing:end': [files: KubbFile.ResolvedFile[]];
262
- /**
263
- * Emitted when a plugin starts executing.
264
- */
265
- 'plugin:start': [plugin: Plugin];
266
- /**
267
- * Emitted when a plugin completes execution.
268
- * Duration in ms
269
- */
270
- 'plugin:end': [plugin: Plugin, meta: {
271
- duration: number;
272
- success: boolean;
273
- error?: Error;
274
- }];
275
- /**
276
- * Emitted when plugin hook progress tracking starts.
277
- * Contains the hook name and list of plugins to execute.
278
- */
279
- 'plugins:hook:progress:start': [meta: ProgressStartMeta];
280
- /**
281
- * Emitted when plugin hook progress tracking ends.
282
- * Contains the hook name that completed.
283
- */
284
- 'plugins:hook:progress:end': [meta: ProgressStopMeta];
285
- /**
286
- * Emitted when a plugin hook starts processing.
287
- * Contains strategy, hook name, plugin, parameters, and output.
288
- */
289
- 'plugins:hook:processing:start': [meta: ExecutingMeta];
290
- /**
291
- * Emitted when a plugin hook completes processing.
292
- * Contains duration, strategy, hook name, plugin, parameters, and output.
293
- */
294
- 'plugins:hook:processing:end': [meta: ExecutedMeta];
295
- }
296
- //#endregion
297
- //#region ../core/src/utils/AsyncEventEmitter.d.ts
298
- declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
299
- #private;
300
- constructor(maxListener?: number);
301
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
302
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
303
- onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
304
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
305
- removeAll(): void;
306
- }
307
- //#endregion
308
- //#region ../core/src/utils/types.d.ts
309
- type PossiblePromise<T> = Promise<T> | T;
310
- //#endregion
311
- //#region ../core/src/types.d.ts
312
- declare global {
313
- namespace Kubb {
314
- interface PluginContext {}
315
- }
316
- }
317
- /**
318
- * Config used in `kubb.config.ts`
319
- *
320
- * @example
321
- * import { defineConfig } from '@kubb/core'
322
- * export default defineConfig({
323
- * ...
324
- * })
325
- */
326
-
327
- type InputPath = {
328
- /**
329
- * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
330
- */
331
- path: string;
332
- };
333
- type InputData = {
334
- /**
335
- * A `string` or `object` that contains your Swagger/OpenAPI data.
336
- */
337
- data: string | unknown;
338
- };
339
- type Input = InputPath | InputData | Array<InputPath>;
340
- type BarrelType = 'all' | 'named' | 'propagate';
341
- /**
342
- * @private
343
- */
344
- type Config<TInput = Input> = {
345
- /**
346
- * The name to display in the CLI output.
347
- */
348
- name?: string;
349
- /**
350
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
351
- * @default process.cwd()
352
- */
353
- root: string;
354
- /**
355
- * You can use either `input.path` or `input.data`, depending on your specific needs.
356
- */
357
- input: TInput;
358
- output: {
359
- /**
360
- * The path where all generated files receives exported.
361
- * This can be an absolute path or a path relative to the specified root option.
362
- */
363
- path: string;
364
- /**
365
- * Clean the output directory before each build.
366
- */
367
- clean?: boolean;
368
- /**
369
- * Save files to the file system.
370
- * @default true
371
- */
372
- write?: boolean;
373
- /**
374
- * Specifies the formatting tool to be used.
375
- * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
376
- * - 'prettier' uses Prettier for code formatting.
377
- * - 'biome' uses Biome for code formatting.
378
- * - 'oxfmt' uses Oxfmt for code formatting.
379
- * - false disables code formatting.
380
- * @default 'prettier'
381
- */
382
- format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
383
- /**
384
- * Specifies the linter that should be used to analyze the code.
385
- * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
386
- * - 'eslint' uses ESLint for linting.
387
- * - 'biome' uses Biome for linting.
388
- * - 'oxlint' uses Oxlint for linting.
389
- * - false disables linting.
390
- * @default 'auto'
391
- */
392
- lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
393
- /**
394
- * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
395
- * @default { '.ts': '.ts'}
396
- */
397
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
398
- /**
399
- * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
400
- * @default 'named'
401
- */
402
- barrelType?: Exclude<BarrelType, 'propagate'> | false;
403
- /**
404
- * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
405
- * - 'simple' adds banner with link to Kubb.
406
- * - 'full' adds source, title, description, and OpenAPI version.
407
- * - false disables banner generation.
408
- * @default 'simple'
409
- */
410
- defaultBanner?: 'simple' | 'full' | false;
411
- /**
412
- * Whether to override existing external files if they already exist.
413
- * When setting the option in the global configuration, all plugins inherit the same behavior by default.
414
- * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
415
- * @default false
416
- */
417
- override?: boolean;
418
- };
419
- /**
420
- * An array of Kubb plugins that used in the generation.
421
- * Each plugin may include additional configurable options(defined in the plugin itself).
422
- * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
423
- */
424
- plugins?: Array<Plugin>;
425
- /**
426
- * Hooks triggered when a specific action occurs in Kubb.
427
- */
428
- hooks?: {
429
- /**
430
- * Hook that triggers at the end of all executions.
431
- * Useful for running Prettier or ESLint to format/lint your code.
432
- */
433
- done?: string | Array<string>;
434
- };
435
- };
436
- type PluginFactoryOptions<
437
- /**
438
- * Name to be used for the plugin, this will also be used for they key.
439
- */
440
- TName extends string = string,
441
- /**
442
- * Options of the plugin.
443
- */
444
- TOptions extends object = object,
445
- /**
446
- * Options of the plugin that can be used later on, see `options` inside your plugin config.
447
- */
448
- TResolvedOptions extends object = TOptions,
449
- /**
450
- * Context that you want to expose to other plugins.
451
- */
452
- TContext = any,
453
- /**
454
- * When calling `resolvePath` you can specify better types.
455
- */
456
- TResolvePathOptions extends object = object> = {
457
- name: TName;
458
- /**
459
- * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
460
- */
461
- key: PluginKey<TName | string>;
462
- options: TOptions;
463
- resolvedOptions: TResolvedOptions;
464
- context: TContext;
465
- resolvePathOptions: TResolvePathOptions;
466
- };
467
- type PluginKey<TName> = [name: TName, identifier?: string | number];
468
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
469
- /**
470
- * Unique name used for the plugin
471
- * @example @kubb/typescript
472
- */
473
- name: TOptions['name'];
474
- /**
475
- * Internal key used when a developer uses more than one of the same plugin
476
- * @private
477
- */
478
- key: TOptions['key'];
479
- /**
480
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
481
- * Can be used to validate dependent plugins.
482
- */
483
- pre?: Array<string>;
484
- /**
485
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
486
- */
487
- post?: Array<string>;
488
- /**
489
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
490
- */
491
- options: TOptions['resolvedOptions'];
492
- install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
493
- /**
494
- * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
495
- */
496
- inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
497
- };
498
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
499
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
500
- /**
501
- * Start of the lifecycle of a plugin.
502
- * @type hookParallel
503
- */
504
- install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
505
- /**
506
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
507
- * Options can als be included.
508
- * @type hookFirst
509
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
510
- */
511
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
512
- /**
513
- * Resolve to a name based on a string.
514
- * Useful when converting to PascalCase or camelCase.
515
- * @type hookFirst
516
- * @example ('pet') => 'Pet'
517
- */
518
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
519
- };
520
- type PluginLifecycleHooks = keyof PluginLifecycle;
521
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
522
- type ResolvePathParams<TOptions = object> = {
523
- pluginKey?: Plugin['key'];
524
- baseName: KubbFile.BaseName;
525
- mode?: KubbFile.Mode;
526
- /**
527
- * Options to be passed to 'resolvePath' 3th parameter
528
- */
529
- options?: TOptions;
530
- };
531
- type ResolveNameParams = {
532
- name: string;
533
- pluginKey?: Plugin['key'];
534
- /**
535
- * Specifies the type of entity being named.
536
- * - 'file' customizes the name of the created file (uses camelCase).
537
- * - 'function' customizes the exported function names (uses camelCase).
538
- * - 'type' customizes TypeScript types (uses PascalCase).
539
- * - 'const' customizes variable names (uses camelCase).
540
- * @default undefined
541
- */
542
- type?: 'file' | 'function' | 'type' | 'const';
543
- };
544
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
545
- fabric: Fabric;
546
- config: Config;
547
- pluginManager: PluginManager;
548
- /**
549
- * Only add when the file does not exist yet
550
- */
551
- addFile: (...file: Array<KubbFile.File>) => Promise<void>;
552
- /**
553
- * merging multiple sources into the same output file
554
- */
555
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
556
- events: AsyncEventEmitter<KubbEvents>;
557
- mode: KubbFile.Mode;
558
- /**
559
- * Current plugin
560
- */
561
- plugin: Plugin<TOptions>;
562
- } & Kubb.PluginContext;
563
- //#endregion
564
- //#region ../core/src/PluginManager.d.ts
565
- type RequiredPluginLifecycle = Required<PluginLifecycle>;
566
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
567
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
568
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
569
- result: Result;
570
- plugin: Plugin;
571
- };
572
- type Options = {
573
- fabric: Fabric;
574
- events: AsyncEventEmitter<KubbEvents>;
575
- /**
576
- * @default Number.POSITIVE_INFINITY
577
- */
578
- concurrency?: number;
579
- };
580
- type GetFileProps<TOptions = object> = {
581
- name: string;
582
- mode?: KubbFile.Mode;
583
- extname: KubbFile.Extname;
584
- pluginKey: Plugin['key'];
585
- options?: TOptions;
586
- };
587
- declare class PluginManager {
588
- #private;
589
- readonly config: Config;
590
- readonly options: Options;
591
- constructor(config: Config, options: Options);
592
- get events(): AsyncEventEmitter<KubbEvents>;
593
- getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
594
- get plugins(): Array<Plugin>;
595
- getFile<TOptions = object>({
596
- name,
597
- mode,
598
- extname,
599
- pluginKey,
600
- options
601
- }: GetFileProps<TOptions>): KubbFile.File<{
602
- pluginKey: Plugin['key'];
603
- }>;
604
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
605
- resolveName: (params: ResolveNameParams) => string;
606
- /**
607
- * Run a specific hookName for plugin x.
608
- */
609
- hookForPlugin<H extends PluginLifecycleHooks>({
610
- pluginKey,
611
- hookName,
612
- parameters
613
- }: {
614
- pluginKey: Plugin['key'];
615
- hookName: H;
616
- parameters: PluginParameter<H>;
617
- }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
618
- /**
619
- * Run a specific hookName for plugin x.
620
- */
621
- hookForPluginSync<H extends PluginLifecycleHooks>({
622
- pluginKey,
623
- hookName,
624
- parameters
625
- }: {
626
- pluginKey: Plugin['key'];
627
- hookName: H;
628
- parameters: PluginParameter<H>;
629
- }): Array<ReturnType<ParseResult<H>>> | null;
630
- /**
631
- * Returns the first non-null result.
632
- */
633
- hookFirst<H extends PluginLifecycleHooks>({
634
- hookName,
635
- parameters,
636
- skipped
637
- }: {
638
- hookName: H;
639
- parameters: PluginParameter<H>;
640
- skipped?: ReadonlySet<Plugin> | null;
641
- }): Promise<SafeParseResult<H>>;
642
- /**
643
- * Returns the first non-null result.
644
- */
645
- hookFirstSync<H extends PluginLifecycleHooks>({
646
- hookName,
647
- parameters,
648
- skipped
649
- }: {
650
- hookName: H;
651
- parameters: PluginParameter<H>;
652
- skipped?: ReadonlySet<Plugin> | null;
653
- }): SafeParseResult<H>;
654
- /**
655
- * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
656
- */
657
- hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
658
- hookName,
659
- parameters
660
- }: {
661
- hookName: H;
662
- parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
663
- }): Promise<Awaited<TOutput>[]>;
664
- /**
665
- * Chains plugins
666
- */
667
- hookSeq<H extends PluginLifecycleHooks>({
668
- hookName,
669
- parameters
670
- }: {
671
- hookName: H;
672
- parameters?: PluginParameter<H>;
673
- }): Promise<void>;
674
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
675
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
676
- }
677
- //#endregion
678
75
  //#region src/utils.d.ts
679
76
  declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1$1.Document;
680
77
  declare function isParameterObject(obj: ParameterObject | SchemaObject$1): obj is ParameterObject;
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@kubb/oas",
3
- "version": "4.20.2",
3
+ "version": "4.20.5",
4
4
  "description": "OpenAPI Specification (OAS) utilities and helpers for Kubb, providing parsing, normalization, and manipulation of OpenAPI/Swagger schemas.",
5
5
  "keywords": [
6
6
  "openapi",
7
7
  "swagger",
8
8
  "oas",
9
+ "openapi-v3",
9
10
  "api-specification",
10
11
  "schema",
12
+ "schema-parser",
13
+ "utilities",
14
+ "helpers",
15
+ "rest-api",
11
16
  "typescript",
12
17
  "codegen",
13
18
  "kubb"
@@ -51,11 +56,11 @@
51
56
  "@redocly/openapi-core": "^2.15.1",
52
57
  "jsonpointer": "^5.0.1",
53
58
  "oas": "^28.9.0",
54
- "oas-normalize": "^15.7.0",
59
+ "oas-normalize": "^15.7.1",
55
60
  "openapi-types": "^12.1.3",
56
- "remeda": "^2.33.4",
61
+ "remeda": "^2.33.5",
57
62
  "swagger2openapi": "^7.0.8",
58
- "@kubb/core": "4.20.2"
63
+ "@kubb/core": "4.20.5"
59
64
  },
60
65
  "devDependencies": {
61
66
  "@stoplight/yaml": "^4.3.0",