@kubb/plugin-oas 4.18.4 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/{SchemaGenerator-CoV4zGpd.js → SchemaGenerator-D8GP-AGi.js} +48 -21
  2. package/dist/SchemaGenerator-D8GP-AGi.js.map +1 -0
  3. package/dist/{SchemaGenerator-tDDCI3wi.cjs → SchemaGenerator-DO3rrt_U.cjs} +49 -22
  4. package/dist/SchemaGenerator-DO3rrt_U.cjs.map +1 -0
  5. package/dist/SchemaMapper-CzH82C7C.cjs.map +1 -1
  6. package/dist/SchemaMapper-D-GETHNf.js.map +1 -1
  7. package/dist/{SchemaMapper-BBUBpcx-.d.ts → SchemaMapper-DI2vHHE0.d.ts} +72 -52
  8. package/dist/{SchemaMapper-CIs2VKvf.d.cts → SchemaMapper-DmB5NyNo.d.cts} +72 -52
  9. package/dist/{createGenerator-Cj-sXgmn.d.cts → createGenerator-BF26dp_h.d.cts} +33 -13
  10. package/dist/{createGenerator-CZi_gpit.d.ts → createGenerator-DhGg_jH6.d.ts} +33 -13
  11. package/dist/generators.d.cts +2 -2
  12. package/dist/generators.d.ts +2 -2
  13. package/dist/getSchemaFactory-CBp1me72.cjs +29 -0
  14. package/dist/getSchemaFactory-CBp1me72.cjs.map +1 -0
  15. package/dist/getSchemaFactory-DsoVRgxV.js +24 -0
  16. package/dist/getSchemaFactory-DsoVRgxV.js.map +1 -0
  17. package/dist/hooks.cjs +3 -3
  18. package/dist/hooks.cjs.map +1 -1
  19. package/dist/hooks.d.cts +4 -4
  20. package/dist/hooks.d.ts +4 -4
  21. package/dist/hooks.js +3 -3
  22. package/dist/hooks.js.map +1 -1
  23. package/dist/index.cjs +5 -4
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +5 -4
  28. package/dist/index.js.map +1 -1
  29. package/dist/mocks.d.cts +1 -1
  30. package/dist/mocks.d.ts +1 -1
  31. package/dist/utils.cjs +26 -3
  32. package/dist/utils.cjs.map +1 -1
  33. package/dist/utils.d.cts +25 -5
  34. package/dist/utils.d.ts +25 -5
  35. package/dist/utils.js +24 -1
  36. package/dist/utils.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/SchemaGenerator.ts +60 -26
  39. package/src/SchemaMapper.ts +3 -3
  40. package/src/hooks/useOperationManager.ts +1 -1
  41. package/src/hooks/useSchemaManager.ts +1 -1
  42. package/src/plugin.ts +3 -1
  43. package/src/types.ts +30 -10
  44. package/src/utils/getSchemas.ts +27 -105
  45. package/dist/SchemaGenerator-CoV4zGpd.js.map +0 -1
  46. package/dist/SchemaGenerator-tDDCI3wi.cjs.map +0 -1
  47. package/dist/getSchemas-BUXPwm-5.js +0 -101
  48. package/dist/getSchemas-BUXPwm-5.js.map +0 -1
  49. package/dist/getSchemas-D3YweIFO.cjs +0 -112
  50. package/dist/getSchemas-D3YweIFO.cjs.map +0 -1
@@ -307,7 +307,7 @@ type Config<TInput = Input> = {
307
307
  input: TInput;
308
308
  output: {
309
309
  /**
310
- * The path where all generated files will be exported.
310
+ * The path where all generated files receives exported.
311
311
  * This can be an absolute path or a path relative to the specified root option.
312
312
  */
313
313
  path: string;
@@ -322,41 +322,39 @@ type Config<TInput = Input> = {
322
322
  write?: boolean;
323
323
  /**
324
324
  * Specifies the formatting tool to be used.
325
- * @default prettier
326
- *
327
- * Possible values:
328
- * - 'auto': Automatically detects and uses biome or prettier (in that order of preference).
329
- * - 'prettier': Uses Prettier for code formatting.
330
- * - 'biome': Uses Biome for code formatting.
331
- *
325
+ * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
326
+ * - 'prettier' uses Prettier for code formatting.
327
+ * - 'biome' uses Biome for code formatting.
328
+ * - 'oxfmt' uses Oxfmt for code formatting.
329
+ * - false disables code formatting.
330
+ * @default 'prettier'
332
331
  */
333
332
  format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
334
333
  /**
335
334
  * Specifies the linter that should be used to analyze the code.
336
- * The accepted values indicate different linting tools.
337
- *
338
- * Possible values:
339
- * - 'auto': Automatically detects and uses biome, oxlint, or eslint (in that order of preference).
340
- * - 'eslint': Represents the use of ESLint, a widely used JavaScript linter.
341
- * - 'biome': Represents the Biome linter, a modern tool for code scanning.
342
- * - 'oxlint': Represents the Oxlint tool for linting purposes.
343
- *
335
+ * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
336
+ * - 'eslint' uses ESLint for linting.
337
+ * - 'biome' uses Biome for linting.
338
+ * - 'oxlint' uses Oxlint for linting.
339
+ * - false disables linting.
340
+ * @default 'auto'
344
341
  */
345
342
  lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
346
343
  /**
347
- * Override the extension to the generated imports and exports, by default each plugin will add an extension
344
+ * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
348
345
  * @default { '.ts': '.ts'}
349
346
  */
350
347
  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
351
348
  /**
352
- * Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
349
+ * 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`).
353
350
  * @default 'named'
354
351
  */
355
352
  barrelType?: Exclude<BarrelType, 'propagate'> | false;
356
353
  /**
357
- * Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
358
- * - 'simple': will only add banner with link to Kubb
359
- * - 'full': will add source, title, description and the OpenAPI version used
354
+ * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
355
+ * - 'simple' adds banner with link to Kubb.
356
+ * - 'full' adds source, title, description, and OpenAPI version.
357
+ * - false disables banner generation.
360
358
  * @default 'simple'
361
359
  */
362
360
  defaultBanner?: 'simple' | 'full' | false;
@@ -369,17 +367,17 @@ type Config<TInput = Input> = {
369
367
  override?: boolean;
370
368
  };
371
369
  /**
372
- * An array of Kubb plugins that will be used in the generation.
370
+ * An array of Kubb plugins that used in the generation.
373
371
  * Each plugin may include additional configurable options(defined in the plugin itself).
374
- * If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
372
+ * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
375
373
  */
376
374
  plugins?: Array<Plugin>;
377
375
  /**
378
- * Hooks that will be called when a specific action is triggered in Kubb.
376
+ * Hooks triggered when a specific action occurs in Kubb.
379
377
  */
380
378
  hooks?: {
381
379
  /**
382
- * Hook that will be triggered at the end of all executions.
380
+ * Hook that triggers at the end of all executions.
383
381
  * Useful for running Prettier or ESLint to format/lint your code.
384
382
  */
385
383
  done?: string | Array<string>;
@@ -408,7 +406,7 @@ TContext = any,
408
406
  TResolvePathOptions extends object = object> = {
409
407
  name: TName;
410
408
  /**
411
- * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
409
+ * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
412
410
  */
413
411
  key: PluginKey<TName | string>;
414
412
  options: TOptions;
@@ -429,12 +427,12 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
429
427
  */
430
428
  options: TOptions['resolvedOptions'];
431
429
  /**
432
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
430
+ * 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.
433
431
  * Can be used to validate dependent plugins.
434
432
  */
435
433
  pre?: Array<string>;
436
434
  /**
437
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
435
+ * 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.
438
436
  */
439
437
  post?: Array<string>;
440
438
  inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
@@ -452,12 +450,12 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
452
450
  */
453
451
  key: TOptions['key'];
454
452
  /**
455
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
453
+ * 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.
456
454
  * Can be used to validate dependent plugins.
457
455
  */
458
456
  pre?: Array<string>;
459
457
  /**
460
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
458
+ * 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.
461
459
  */
462
460
  post?: Array<string>;
463
461
  /**
@@ -507,10 +505,12 @@ type ResolveNameParams = {
507
505
  name: string;
508
506
  pluginKey?: Plugin['key'];
509
507
  /**
510
- * `file` will be used to customize the name of the created file(use of camelCase)
511
- * `function` can be used to customize the exported functions(use of camelCase)
512
- * `type` is a special type for TypeScript(use of PascalCase)
513
- * `const` can be used for variables(use of camelCase)
508
+ * Specifies the type of entity being named.
509
+ * - 'file' customizes the name of the created file (uses camelCase).
510
+ * - 'function' customizes the exported function names (uses camelCase).
511
+ * - 'type' customizes TypeScript types (uses PascalCase).
512
+ * - 'const' customizes variable names (uses camelCase).
513
+ * @default undefined
514
514
  */
515
515
  type?: 'file' | 'function' | 'type' | 'const';
516
516
  };
@@ -565,11 +565,14 @@ type GroupContext = {
565
565
  };
566
566
  type Group = {
567
567
  /**
568
- * Define a type where to group the files on
568
+ * Defines the type where to group the files.
569
+ * - 'tag' groups files by OpenAPI tags.
570
+ * - 'path' groups files by OpenAPI paths.
571
+ * @default undefined
569
572
  */
570
573
  type: 'tag' | 'path';
571
574
  /**
572
- * Return the name of a group based on the group name, this will be used for the file and name generation
575
+ * Return the name of a group based on the group name, this used for the file and name generation
573
576
  */
574
577
  name?: (context: GroupContext) => string;
575
578
  };
@@ -582,7 +585,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
582
585
  result: Result;
583
586
  plugin: Plugin;
584
587
  };
585
- type Options$1 = {
588
+ type Options = {
586
589
  fabric: Fabric;
587
590
  events: AsyncEventEmitter<KubbEvents>;
588
591
  /**
@@ -600,8 +603,8 @@ type GetFileProps<TOptions = object> = {
600
603
  declare class PluginManager {
601
604
  #private;
602
605
  readonly config: Config;
603
- readonly options: Options$1;
604
- constructor(config: Config, options: Options$1);
606
+ readonly options: Options;
607
+ constructor(config: Config, options: Options);
605
608
  get events(): AsyncEventEmitter<KubbEvents>;
606
609
  getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
607
610
  get plugins(): Array<Plugin>;
@@ -641,7 +644,7 @@ declare class PluginManager {
641
644
  parameters: PluginParameter<H>;
642
645
  }): Array<ReturnType<ParseResult<H>>> | null;
643
646
  /**
644
- * First non-null result stops and will return it's value.
647
+ * Returns the first non-null result.
645
648
  */
646
649
  hookFirst<H extends PluginLifecycleHooks>({
647
650
  hookName,
@@ -653,7 +656,7 @@ declare class PluginManager {
653
656
  skipped?: ReadonlySet<Plugin> | null;
654
657
  }): Promise<SafeParseResult<H>>;
655
658
  /**
656
- * First non-null result stops and will return it's value.
659
+ * Returns the first non-null result.
657
660
  */
658
661
  hookFirstSync<H extends PluginLifecycleHooks>({
659
662
  hookName,
@@ -665,15 +668,15 @@ declare class PluginManager {
665
668
  skipped?: ReadonlySet<Plugin> | null;
666
669
  }): SafeParseResult<H>;
667
670
  /**
668
- * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
671
+ * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
669
672
  */
670
- hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
673
+ hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
671
674
  hookName,
672
675
  parameters
673
676
  }: {
674
677
  hookName: H;
675
678
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
676
- }): Promise<Awaited<TOuput>[]>;
679
+ }): Promise<Awaited<TOutput>[]>;
677
680
  /**
678
681
  * Chains plugins
679
682
  */
@@ -705,16 +708,21 @@ type Operation$1 = Operation;
705
708
  type DiscriminatorObject$1 = DiscriminatorObject;
706
709
  //#endregion
707
710
  //#region ../oas/src/Oas.d.ts
708
- type Options = {
711
+ type OasOptions = {
709
712
  contentType?: contentType;
710
713
  discriminator?: 'strict' | 'inherit';
714
+ /**
715
+ * Resolve name collisions when schemas from different components share the same name (case-insensitive).
716
+ * @default false
717
+ */
718
+ collisionDetection?: boolean;
711
719
  };
712
720
  declare class Oas extends BaseOas {
713
721
  #private;
714
722
  document: Document;
715
723
  constructor(document: Document);
716
- setOptions(options: Options): void;
717
- get options(): Options;
724
+ setOptions(options: OasOptions): void;
725
+ get options(): OasOptions;
718
726
  get<T = unknown>($ref: string): T | null;
719
727
  getKey($ref: string): string | undefined;
720
728
  set($ref: string, value: unknown): false | undefined;
@@ -723,8 +731,20 @@ declare class Oas extends BaseOas {
723
731
  getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
724
732
  getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
725
733
  getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
726
- valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
734
+ validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
727
735
  flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
736
+ /**
737
+ * Get schemas from OpenAPI components (schemas, responses, requestBodies).
738
+ * Returns schemas in dependency order along with name mapping for collision resolution.
739
+ */
740
+ getSchemas(options?: {
741
+ contentType?: contentType;
742
+ includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
743
+ collisionDetection?: boolean;
744
+ }): {
745
+ schemas: Record<string, SchemaObject$1>;
746
+ nameMapping: Map<string, string>;
747
+ };
728
748
  }
729
749
  //#endregion
730
750
  //#region ../oas/src/utils.d.ts
@@ -846,8 +866,8 @@ type SchemaKeywordMapper = {
846
866
  */
847
867
  path: KubbFile.Path;
848
868
  /**
849
- * When true `File.Import` will be used.
850
- * When false a reference will be used inside the current file.
869
+ * When true `File.Import` is used.
870
+ * When false a reference is used inside the current file.
851
871
  */
852
872
  isImportable: boolean;
853
873
  };
@@ -1007,11 +1027,11 @@ type SchemaTree = {
1007
1027
  current: Schema;
1008
1028
  siblings: Schema[];
1009
1029
  /**
1010
- * this will be equal to the key of a property(object)
1030
+ * this is equal to the key of a property(object)
1011
1031
  */
1012
1032
  name?: string;
1013
1033
  };
1014
1034
  declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
1015
1035
  //#endregion
1016
1036
  export { __name as A, Plugin as C, AsyncEventEmitter as D, UserPluginWithLifeCycle as E, KubbEvents as O, Output as S, ResolveNameParams as T, contentType as _, SchemaMapper as a, Config as b, schemaKeywords as c, HttpMethod as d, OasTypes as f, SchemaObject$1 as g, Operation$1 as h, SchemaKeywordMapper as i, BaseGenerator as k, isOptional as l, OpenAPIV3_1 as m, SchemaKeyword as n, SchemaTree as o, OpenAPIV3 as p, SchemaKeywordBase as r, isKeyword as s, Schema as t, Oas as u, FileMetaBase as v, PluginFactoryOptions as w, Group as x, PluginManager as y };
1017
- //# sourceMappingURL=SchemaMapper-CIs2VKvf.d.cts.map
1037
+ //# sourceMappingURL=SchemaMapper-DmB5NyNo.d.cts.map
@@ -1,4 +1,4 @@
1
- import { A as __name, C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-CIs2VKvf.cjs";
1
+ import { A as __name, C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-DmB5NyNo.cjs";
2
2
  import { KubbFile } from "@kubb/fabric-core/types";
3
3
  import { Fabric } from "@kubb/react-fabric";
4
4
  import { KubbNode } from "@kubb/react-fabric/types";
@@ -74,35 +74,55 @@ type Options = {
74
74
  /**
75
75
  * Which server to use from the array of `servers.url[serverIndex]`
76
76
  * @example
77
- * - `0` will return `http://petstore.swagger.io/api`
78
- * - `1` will return `http://localhost:3000`
77
+ * - `0` returns `http://petstore.swagger.io/api`
78
+ * - `1` returns `http://localhost:3000`
79
79
  */
80
80
  serverIndex?: number;
81
81
  /**
82
82
  * Define which contentType should be used.
83
- * By default, the first JSON valid mediaType will be used
83
+ * By default, uses the first valid JSON media type.
84
84
  */
85
85
  contentType?: contentType;
86
86
  /**
87
87
  * Defines how the discriminator value should be interpreted during processing.
88
- *
88
+ * - 'strict' uses the oneOf schemas as defined, without modification.
89
+ * - 'inherit' replaces the oneOf schema with the schema referenced by discriminator.mapping[key].
89
90
  * @default 'strict'
90
- *
91
- * @example
92
- * - `inherit`: Replaces the `oneOf` schema with the schema referenced by `discriminator.mapping[key]`.
93
- * - `strict`: Uses the `oneOf` schemas as defined, without modification.
94
- *
95
91
  * @see https://github.com/kubb-labs/kubb/issues/1736
96
92
  */
97
93
  discriminator?: 'strict' | 'inherit';
98
94
  /**
99
- * Override some behaviour of the Oas class instance, see '@kubb/oas'
95
+ * Override some behavior of the Oas class instance, see '@kubb/oas'
100
96
  */
101
97
  oasClass?: typeof Oas;
102
98
  /**
103
99
  * Define some generators next to the JSON generation
104
100
  */
105
101
  generators?: Array<Generator<PluginOas>>;
102
+ /**
103
+ * Resolve name collisions when schemas from different components share the same name (case-insensitive).
104
+ *
105
+ * When enabled, Kubb automatically detects and resolves collisions using intelligent suffixes:
106
+ * - Cross-component collisions: Adds semantic suffixes based on the component type (Schema/Response/Request)
107
+ * - Same-component collisions: Adds numeric suffixes (2, 3, ...) for case-insensitive duplicates
108
+ *
109
+ * When disabled (legacy behavior), collisions may result in duplicate files or overwrite issues.
110
+ *
111
+ * **Cross-component collision example:**
112
+ * If you have "Order" in both schemas and requestBodies:
113
+ * - With `collisionDetection: true`: Generates `OrderSchema.ts`, `OrderRequest.ts`
114
+ * - With `collisionDetection: false`: May generate duplicate `Order.ts` files
115
+ *
116
+ * **Same-component collision example:**
117
+ * If you have "Variant" and "variant" in schemas:
118
+ * - With `collisionDetection: true`: Generates `Variant.ts`, `Variant2.ts`
119
+ * - With `collisionDetection: false`: May overwrite or create duplicates
120
+ *
121
+ * @default false
122
+ * @see https://github.com/kubb-labs/kubb/issues/1999
123
+ * @note this will be the default in Kubb v5
124
+ */
125
+ collisionDetection?: boolean;
106
126
  };
107
127
  /**
108
128
  * `propertyName` is the ref name + resolved with the nameResolver
@@ -262,7 +282,7 @@ type SchemaGeneratorOptions = {
262
282
  */
263
283
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
264
284
  /**
265
- * Receive schema and name(propertName) and return FakerMeta array
285
+ * Receive schema and name(propertyName) and return FakerMeta array
266
286
  * TODO TODO add docs
267
287
  * @beta
268
288
  */
@@ -355,4 +375,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
355
375
  declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
356
376
  //#endregion
357
377
  export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, FunctionParamsAST as w, Refs as x, PluginOas as y };
358
- //# sourceMappingURL=createGenerator-Cj-sXgmn.d.cts.map
378
+ //# sourceMappingURL=createGenerator-BF26dp_h.d.cts.map
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-iVr_oF3V.js";
2
- import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-BBUBpcx-.js";
2
+ import { C as Plugin, D as AsyncEventEmitter, O as KubbEvents, S as Output, T as ResolveNameParams, _ as contentType, b as Config, d as HttpMethod, g as SchemaObject, h as Operation, i as SchemaKeywordMapper, k as BaseGenerator, t as Schema, u as Oas, v as FileMetaBase, w as PluginFactoryOptions, x as Group, y as PluginManager } from "./SchemaMapper-DI2vHHE0.js";
3
3
  import { Fabric } from "@kubb/react-fabric";
4
4
  import { KubbFile } from "@kubb/fabric-core/types";
5
5
  import { KubbNode } from "@kubb/react-fabric/types";
@@ -75,35 +75,55 @@ type Options = {
75
75
  /**
76
76
  * Which server to use from the array of `servers.url[serverIndex]`
77
77
  * @example
78
- * - `0` will return `http://petstore.swagger.io/api`
79
- * - `1` will return `http://localhost:3000`
78
+ * - `0` returns `http://petstore.swagger.io/api`
79
+ * - `1` returns `http://localhost:3000`
80
80
  */
81
81
  serverIndex?: number;
82
82
  /**
83
83
  * Define which contentType should be used.
84
- * By default, the first JSON valid mediaType will be used
84
+ * By default, uses the first valid JSON media type.
85
85
  */
86
86
  contentType?: contentType;
87
87
  /**
88
88
  * Defines how the discriminator value should be interpreted during processing.
89
- *
89
+ * - 'strict' uses the oneOf schemas as defined, without modification.
90
+ * - 'inherit' replaces the oneOf schema with the schema referenced by discriminator.mapping[key].
90
91
  * @default 'strict'
91
- *
92
- * @example
93
- * - `inherit`: Replaces the `oneOf` schema with the schema referenced by `discriminator.mapping[key]`.
94
- * - `strict`: Uses the `oneOf` schemas as defined, without modification.
95
- *
96
92
  * @see https://github.com/kubb-labs/kubb/issues/1736
97
93
  */
98
94
  discriminator?: 'strict' | 'inherit';
99
95
  /**
100
- * Override some behaviour of the Oas class instance, see '@kubb/oas'
96
+ * Override some behavior of the Oas class instance, see '@kubb/oas'
101
97
  */
102
98
  oasClass?: typeof Oas;
103
99
  /**
104
100
  * Define some generators next to the JSON generation
105
101
  */
106
102
  generators?: Array<Generator<PluginOas>>;
103
+ /**
104
+ * Resolve name collisions when schemas from different components share the same name (case-insensitive).
105
+ *
106
+ * When enabled, Kubb automatically detects and resolves collisions using intelligent suffixes:
107
+ * - Cross-component collisions: Adds semantic suffixes based on the component type (Schema/Response/Request)
108
+ * - Same-component collisions: Adds numeric suffixes (2, 3, ...) for case-insensitive duplicates
109
+ *
110
+ * When disabled (legacy behavior), collisions may result in duplicate files or overwrite issues.
111
+ *
112
+ * **Cross-component collision example:**
113
+ * If you have "Order" in both schemas and requestBodies:
114
+ * - With `collisionDetection: true`: Generates `OrderSchema.ts`, `OrderRequest.ts`
115
+ * - With `collisionDetection: false`: May generate duplicate `Order.ts` files
116
+ *
117
+ * **Same-component collision example:**
118
+ * If you have "Variant" and "variant" in schemas:
119
+ * - With `collisionDetection: true`: Generates `Variant.ts`, `Variant2.ts`
120
+ * - With `collisionDetection: false`: May overwrite or create duplicates
121
+ *
122
+ * @default false
123
+ * @see https://github.com/kubb-labs/kubb/issues/1999
124
+ * @note this will be the default in Kubb v5
125
+ */
126
+ collisionDetection?: boolean;
107
127
  };
108
128
  /**
109
129
  * `propertyName` is the ref name + resolved with the nameResolver
@@ -263,7 +283,7 @@ type SchemaGeneratorOptions = {
263
283
  */
264
284
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
265
285
  /**
266
- * Receive schema and name(propertName) and return FakerMeta array
286
+ * Receive schema and name(propertyName) and return FakerMeta array
267
287
  * TODO TODO add docs
268
288
  * @beta
269
289
  */
@@ -356,4 +376,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
356
376
  declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
357
377
  //#endregion
358
378
  export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, FunctionParamsAST as w, Refs as x, PluginOas as y };
359
- //# sourceMappingURL=createGenerator-CZi_gpit.d.ts.map
379
+ //# sourceMappingURL=createGenerator-DhGg_jH6.d.ts.map
@@ -1,5 +1,5 @@
1
- import { A as __name } from "./SchemaMapper-CIs2VKvf.cjs";
2
- import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-Cj-sXgmn.cjs";
1
+ import { A as __name } from "./SchemaMapper-DmB5NyNo.cjs";
2
+ import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BF26dp_h.cjs";
3
3
 
4
4
  //#region src/generators/jsonGenerator.d.ts
5
5
  declare const jsonGenerator: CoreGenerator<PluginOas>;
@@ -1,6 +1,6 @@
1
1
  import { t as __name } from "./chunk-iVr_oF3V.js";
2
- import "./SchemaMapper-BBUBpcx-.js";
3
- import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-CZi_gpit.js";
2
+ import "./SchemaMapper-DI2vHHE0.js";
3
+ import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-DhGg_jH6.js";
4
4
 
5
5
  //#region src/generators/jsonGenerator.d.ts
6
6
  declare const jsonGenerator: CoreGenerator<PluginOas>;
@@ -0,0 +1,29 @@
1
+ const require_chunk = require('./chunk-C1_xRkKa.cjs');
2
+ let _kubb_oas = require("@kubb/oas");
3
+
4
+ //#region src/utils/getSchemaFactory.ts
5
+ /**
6
+ * Creates a factory function that generates a versioned OpenAPI schema result.
7
+ *
8
+ * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').
9
+ *
10
+ * @returns A function that takes an optional schema and returns a versioned schema result.
11
+ */
12
+ function getSchemaFactory(oas) {
13
+ return (schema) => {
14
+ const version = (0, _kubb_oas.isOpenApiV3_1Document)(oas.api) ? "3.1" : "3.0";
15
+ return {
16
+ schemaObject: oas.dereferenceWithRef(schema),
17
+ version
18
+ };
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ Object.defineProperty(exports, 'getSchemaFactory', {
24
+ enumerable: true,
25
+ get: function () {
26
+ return getSchemaFactory;
27
+ }
28
+ });
29
+ //# sourceMappingURL=getSchemaFactory-CBp1me72.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemaFactory-CBp1me72.cjs","names":[],"sources":["../src/utils/getSchemaFactory.ts"],"sourcesContent":["import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\nimport { isOpenApiV3_1Document } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.0'\n }\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.1'\n }\n\n/**\n * Creates a factory function that generates a versioned OpenAPI schema result.\n *\n * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').\n *\n * @returns A function that takes an optional schema and returns a versioned schema result.\n */\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef> {\n return (schema: SchemaObject | null) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schemaObject: oas.dereferenceWithRef(schema),\n version,\n } as SchemaResult<TWithRef>\n }\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgB,iBAAmD,KAAmE;AACpI,SAAQ,WAAgC;EACtC,MAAM,+CAAgC,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD"}
@@ -0,0 +1,24 @@
1
+ import { t as __name } from "./chunk-iVr_oF3V.js";
2
+ import { isOpenApiV3_1Document } from "@kubb/oas";
3
+
4
+ //#region src/utils/getSchemaFactory.ts
5
+ /**
6
+ * Creates a factory function that generates a versioned OpenAPI schema result.
7
+ *
8
+ * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').
9
+ *
10
+ * @returns A function that takes an optional schema and returns a versioned schema result.
11
+ */
12
+ function getSchemaFactory(oas) {
13
+ return (schema) => {
14
+ const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
15
+ return {
16
+ schemaObject: oas.dereferenceWithRef(schema),
17
+ version
18
+ };
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ export { getSchemaFactory as t };
24
+ //# sourceMappingURL=getSchemaFactory-DsoVRgxV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSchemaFactory-DsoVRgxV.js","names":[],"sources":["../src/utils/getSchemaFactory.ts"],"sourcesContent":["import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\nimport { isOpenApiV3_1Document } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.0'\n }\n | {\n schemaObject:\n | ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n })\n | null\n version: '3.1'\n }\n\n/**\n * Creates a factory function that generates a versioned OpenAPI schema result.\n *\n * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').\n *\n * @returns A function that takes an optional schema and returns a versioned schema result.\n */\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef> {\n return (schema: SchemaObject | null) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schemaObject: oas.dereferenceWithRef(schema),\n version,\n } as SchemaResult<TWithRef>\n }\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgB,iBAAmD,KAAmE;AACpI,SAAQ,WAAgC;EACtC,MAAM,UAAU,sBAAsB,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD"}
package/dist/hooks.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-C1_xRkKa.cjs');
2
- const require_SchemaGenerator = require('./SchemaGenerator-tDDCI3wi.cjs');
2
+ const require_SchemaGenerator = require('./SchemaGenerator-DO3rrt_U.cjs');
3
3
  const require_SchemaMapper = require('./SchemaMapper-CzH82C7C.cjs');
4
4
  let _kubb_react_fabric = require("@kubb/react-fabric");
5
5
  let _kubb_core_hooks = require("@kubb/core/hooks");
@@ -13,7 +13,7 @@ function useOas() {
13
13
  //#endregion
14
14
  //#region src/hooks/useOperationManager.ts
15
15
  /**
16
- * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
16
+ * `useOperationManager` returns helper functions to get the operation file and operation name.
17
17
  */
18
18
  function useOperationManager(generator) {
19
19
  const plugin = (0, _kubb_core_hooks.usePlugin)();
@@ -135,7 +135,7 @@ function useOperationManager(generator) {
135
135
  //#endregion
136
136
  //#region src/hooks/useSchemaManager.ts
137
137
  /**
138
- * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
138
+ * `useSchemaManager` returns helper functions to get the schema file and schema name.
139
139
  */
140
140
  function useSchemaManager() {
141
141
  const plugin = (0, _kubb_core_hooks.usePlugin)();
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.cjs","names":["SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAgB,SAAc;CAC5B,MAAM,EAAE,yCAA+B;AAEvC,QAAO,KAAK;;;;;;;;ACyDd,SAAgB,oBACd,WAC2B;CAC3B,MAAM,0CAAoB;CAC1B,MAAM,wDAAkC;CAExC,MAAM,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,YAAY,OAAO,KAAK,WAAW;AAC/H,SAAO,cAAc,YAAY;GAC/B,M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A,wCAAgB,WAAW,MAAMC,oCAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
1
+ {"version":3,"file":"hooks.cjs","names":["SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useOas(): Oas {\n const { meta } = useApp<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` returns helper functions to get the operation file and operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` returns helper functions to get the schema file and schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAgB,SAAc;CAC5B,MAAM,EAAE,yCAA+B;AAEvC,QAAO,KAAK;;;;;;;;ACyDd,SAAgB,oBACd,WAC2B;CAC3B,MAAM,0CAAoB;CAC1B,MAAM,wDAAkC;CAExC,MAAM,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,YAAY,OAAO,KAAK,WAAW;AAC/H,SAAO,cAAc,YAAY;GAC/B,MAAM,GAAG,OAAO,GAAG,UAAU,gBAAgB,CAAC,GAAG;GACjD;GACA;GACD,CAAC;;CAGJ,MAAM,YAAmD,cAAc;AACrE,SAAO;GACL,KAAK,UAAU,SAAS,CAAC,GAAG,EAAE,EAAE;GAChC,MAAM,UAAU;GACjB;;CAGH,MAAM,cAAuD,WAAW,WAAW;AACjF,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,6BA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