@kubb/plugin-oas 2.18.4 → 2.18.6

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 (68) hide show
  1. package/dist/{OperationGenerator-X6CTMfhG.d.cts → OperationGenerator-B6_KXF47.d.cts} +12 -11
  2. package/dist/{OperationGenerator-DvnXUUp4.d.ts → OperationGenerator-BL3W1CH2.d.ts} +12 -11
  3. package/dist/{Schema-DFZBfjF2.d.ts → Schema-ByMOp8RL.d.ts} +6 -12
  4. package/dist/{Schema-BWPWyiQO.d.cts → Schema-C9Wxng-Q.d.cts} +6 -12
  5. package/dist/{SchemaGenerator-hK5SHxTI.d.ts → SchemaMapper-DRlWYDvv.d.cts} +2 -74
  6. package/dist/{SchemaGenerator-z_7YrAAB.d.cts → SchemaMapper-DRlWYDvv.d.ts} +2 -74
  7. package/dist/{chunk-UMYKVV7G.js → chunk-37DRAF2Z.js} +49 -2
  8. package/dist/chunk-37DRAF2Z.js.map +1 -0
  9. package/dist/chunk-CTFUZW3D.cjs +682 -0
  10. package/dist/chunk-CTFUZW3D.cjs.map +1 -0
  11. package/dist/{chunk-XML4KQ5H.js → chunk-FL37EDQ2.js} +12 -30
  12. package/dist/{chunk-XML4KQ5H.js.map → chunk-FL37EDQ2.js.map} +1 -1
  13. package/dist/chunk-JWIFGIVZ.js +34 -0
  14. package/dist/chunk-JWIFGIVZ.js.map +1 -0
  15. package/dist/{chunk-YI3FIAD4.cjs → chunk-OUN5NRHC.cjs} +30 -48
  16. package/dist/chunk-OUN5NRHC.cjs.map +1 -0
  17. package/dist/chunk-QLNCBDLM.js +682 -0
  18. package/dist/chunk-QLNCBDLM.js.map +1 -0
  19. package/dist/chunk-R4EI2NRQ.cjs +34 -0
  20. package/dist/chunk-R4EI2NRQ.cjs.map +1 -0
  21. package/dist/{chunk-BDNSPC5Z.cjs → chunk-SSSTH6CP.cjs} +50 -3
  22. package/dist/chunk-SSSTH6CP.cjs.map +1 -0
  23. package/dist/components.cjs +5 -5
  24. package/dist/components.d.cts +5 -4
  25. package/dist/components.d.ts +5 -4
  26. package/dist/components.js +3 -3
  27. package/dist/hooks.cjs +13 -13
  28. package/dist/hooks.cjs.map +1 -1
  29. package/dist/hooks.d.cts +7 -8
  30. package/dist/hooks.d.ts +7 -8
  31. package/dist/hooks.js +3 -3
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.cjs +69 -642
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +72 -6
  36. package/dist/index.d.ts +72 -6
  37. package/dist/index.js +50 -623
  38. package/dist/index.js.map +1 -1
  39. package/dist/{types-n5zV4Q3s.d.cts → types-BMBTfHxe.d.cts} +3 -2
  40. package/dist/{types-n5zV4Q3s.d.ts → types-BMBTfHxe.d.ts} +3 -2
  41. package/dist/utils.cjs +9 -9
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +5 -4
  44. package/dist/utils.d.ts +5 -4
  45. package/dist/utils.js +5 -5
  46. package/dist/utils.js.map +1 -1
  47. package/package.json +10 -9
  48. package/src/OperationGenerator.ts +27 -11
  49. package/src/SchemaGenerator.ts +30 -35
  50. package/src/SchemaMapper.ts +1 -1
  51. package/src/components/Schema.tsx +12 -42
  52. package/src/hooks/useOperationManager.ts +3 -2
  53. package/src/hooks/useSchema.ts +1 -8
  54. package/src/index.ts +1 -0
  55. package/src/plugin.ts +3 -3
  56. package/src/types.ts +3 -1
  57. package/src/utils/getGroupedByTagFiles.ts +4 -3
  58. package/dist/chunk-4OLWDMEK.cjs +0 -61
  59. package/dist/chunk-4OLWDMEK.cjs.map +0 -1
  60. package/dist/chunk-BDNSPC5Z.cjs.map +0 -1
  61. package/dist/chunk-BIJSTJCQ.js +0 -61
  62. package/dist/chunk-BIJSTJCQ.js.map +0 -1
  63. package/dist/chunk-I2JOGJIB.cjs +0 -81
  64. package/dist/chunk-I2JOGJIB.cjs.map +0 -1
  65. package/dist/chunk-UMYKVV7G.js.map +0 -1
  66. package/dist/chunk-XRPYJNPR.js +0 -81
  67. package/dist/chunk-XRPYJNPR.js.map +0 -1
  68. package/dist/chunk-YI3FIAD4.cjs.map +0 -1
@@ -1,9 +1,10 @@
1
- import { KubbFile, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
1
+ import { FileMetaBase, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
2
+ import * as KubbFile from '@kubb/fs/types';
2
3
  import { Operation, Oas, contentType } from '@kubb/oas';
3
- import { f as OperationsByMethod, e as OperationSchemas, E as Exclude, I as Include, g as Override } from './types-n5zV4Q3s.cjs';
4
+ import { g as OperationsByMethod, f as OperationSchemas, E as Exclude, I as Include, b as Override } from './types-BMBTfHxe.cjs';
4
5
 
5
6
  type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
6
- type OperationMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
7
+ type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
7
8
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
8
9
  oas: Oas;
9
10
  exclude: Array<Exclude> | undefined;
@@ -17,7 +18,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
17
18
  plugin: Plugin<TPluginOptions>;
18
19
  mode: KubbFile.Mode;
19
20
  };
20
- declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
21
+ declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
21
22
  #private;
22
23
  get operationsByMethod(): OperationsByMethod;
23
24
  set operationsByMethod(paths: OperationsByMethod);
@@ -26,31 +27,31 @@ declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions ext
26
27
  /**
27
28
  * Operation
28
29
  */
29
- abstract operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
30
+ operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
30
31
  /**
31
32
  * GET
32
33
  */
33
- abstract get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
34
+ get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
34
35
  /**
35
36
  * POST
36
37
  */
37
- abstract post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
38
+ post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
38
39
  /**
39
40
  * PATCH
40
41
  */
41
- abstract patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
42
+ patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
42
43
  /**
43
44
  * PUT
44
45
  */
45
- abstract put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
46
+ put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
46
47
  /**
47
48
  * DELETE
48
49
  */
49
- abstract delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
50
+ delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
50
51
  /**
51
52
  * Combination of GET, POST, PATCH, PUT, DELETE
52
53
  */
53
- abstract all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
54
+ all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
54
55
  }
55
56
 
56
57
  export { type GetOperationGeneratorOptions as G, type OperationMethodResult as O, OperationGenerator as a };
@@ -1,9 +1,10 @@
1
- import { KubbFile, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
1
+ import { FileMetaBase, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
2
+ import * as KubbFile from '@kubb/fs/types';
2
3
  import { Operation, Oas, contentType } from '@kubb/oas';
3
- import { f as OperationsByMethod, e as OperationSchemas, E as Exclude, I as Include, g as Override } from './types-n5zV4Q3s.js';
4
+ import { g as OperationsByMethod, f as OperationSchemas, E as Exclude, I as Include, b as Override } from './types-BMBTfHxe.js';
4
5
 
5
6
  type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
6
- type OperationMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
7
+ type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
7
8
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
8
9
  oas: Oas;
9
10
  exclude: Array<Exclude> | undefined;
@@ -17,7 +18,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
17
18
  plugin: Plugin<TPluginOptions>;
18
19
  mode: KubbFile.Mode;
19
20
  };
20
- declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
21
+ declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
21
22
  #private;
22
23
  get operationsByMethod(): OperationsByMethod;
23
24
  set operationsByMethod(paths: OperationsByMethod);
@@ -26,31 +27,31 @@ declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions ext
26
27
  /**
27
28
  * Operation
28
29
  */
29
- abstract operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
30
+ operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
30
31
  /**
31
32
  * GET
32
33
  */
33
- abstract get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
34
+ get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
34
35
  /**
35
36
  * POST
36
37
  */
37
- abstract post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
38
+ post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
38
39
  /**
39
40
  * PATCH
40
41
  */
41
- abstract patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
42
+ patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
42
43
  /**
43
44
  * PUT
44
45
  */
45
- abstract put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
46
+ put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
46
47
  /**
47
48
  * DELETE
48
49
  */
49
- abstract delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
50
+ delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
50
51
  /**
51
52
  * Combination of GET, POST, PATCH, PUT, DELETE
52
53
  */
53
- abstract all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
54
+ all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
54
55
  }
55
56
 
56
57
  export { type GetOperationGeneratorOptions as G, type OperationMethodResult as O, OperationGenerator as a };
@@ -2,25 +2,23 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SchemaObject } from '@kubb/oas';
4
4
  import { KubbNode } from '@kubb/react';
5
- import { S as SchemaGeneratorBuildOptions, d as Schema$1, c as SchemaGenerator } from './SchemaGenerator-hK5SHxTI.js';
5
+ import { S as Schema$1 } from './SchemaMapper-DRlWYDvv.js';
6
6
 
7
7
  type SchemaContextProps = {
8
8
  name: string;
9
- object?: SchemaObject;
10
- generator?: SchemaGenerator;
11
- schemas: Schema$1[];
9
+ schema?: SchemaObject;
10
+ tree: Array<Schema$1>;
12
11
  };
13
12
  type Props = {
14
13
  name: string;
15
- object?: SchemaObject;
16
- generator: SchemaGenerator<any, any, any>;
14
+ value?: SchemaObject;
15
+ tree?: Array<Schema$1>;
17
16
  children?: KubbNode;
18
17
  };
19
- declare function Schema({ name, object, generator, children }: Props): KubbNode;
18
+ declare function Schema({ name, value, tree, children }: Props): KubbNode;
20
19
  declare namespace Schema {
21
20
  var File: ({ output, isTypeOnly, children }: FileProps) => ReactNode;
22
21
  var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
23
- var Source: <TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>({ options, extraSchemas, }: SchemaSourceProps<TOptions>) => ReactNode;
24
22
  var Context: react.Context<SchemaContextProps>;
25
23
  }
26
24
  type FileProps = {
@@ -31,9 +29,5 @@ type FileProps = {
31
29
  type SchemaImportsProps = {
32
30
  isTypeOnly?: boolean;
33
31
  };
34
- type SchemaSourceProps<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions> = {
35
- extraSchemas?: Schema$1[];
36
- options?: TOptions;
37
- };
38
32
 
39
33
  export { Schema as S, type SchemaContextProps as a };
@@ -2,25 +2,23 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SchemaObject } from '@kubb/oas';
4
4
  import { KubbNode } from '@kubb/react';
5
- import { S as SchemaGeneratorBuildOptions, d as Schema$1, c as SchemaGenerator } from './SchemaGenerator-z_7YrAAB.cjs';
5
+ import { S as Schema$1 } from './SchemaMapper-DRlWYDvv.cjs';
6
6
 
7
7
  type SchemaContextProps = {
8
8
  name: string;
9
- object?: SchemaObject;
10
- generator?: SchemaGenerator;
11
- schemas: Schema$1[];
9
+ schema?: SchemaObject;
10
+ tree: Array<Schema$1>;
12
11
  };
13
12
  type Props = {
14
13
  name: string;
15
- object?: SchemaObject;
16
- generator: SchemaGenerator<any, any, any>;
14
+ value?: SchemaObject;
15
+ tree?: Array<Schema$1>;
17
16
  children?: KubbNode;
18
17
  };
19
- declare function Schema({ name, object, generator, children }: Props): KubbNode;
18
+ declare function Schema({ name, value, tree, children }: Props): KubbNode;
20
19
  declare namespace Schema {
21
20
  var File: ({ output, isTypeOnly, children }: FileProps) => ReactNode;
22
21
  var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
23
- var Source: <TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>({ options, extraSchemas, }: SchemaSourceProps<TOptions>) => ReactNode;
24
22
  var Context: react.Context<SchemaContextProps>;
25
23
  }
26
24
  type FileProps = {
@@ -31,9 +29,5 @@ type FileProps = {
31
29
  type SchemaImportsProps = {
32
30
  isTypeOnly?: boolean;
33
31
  };
34
- type SchemaSourceProps<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions> = {
35
- extraSchemas?: Schema$1[];
36
- options?: TOptions;
37
- };
38
32
 
39
33
  export { Schema as S, type SchemaContextProps as a };
@@ -1,6 +1,4 @@
1
- import { KubbFile, ResolveNameParams, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
2
- import { SchemaObject, Oas, contentType } from '@kubb/oas';
3
- import { d as OperationSchema, b as Refs, g as Override } from './types-n5zV4Q3s.js';
1
+ import * as KubbFile from '@kubb/fs/types';
4
2
 
5
3
  type SchemaKeywordMapper = {
6
4
  object: {
@@ -243,74 +241,4 @@ type Schema = {
243
241
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
244
242
  declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
245
243
 
246
- type SchemaMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
247
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
248
- oas: Oas;
249
- pluginManager: PluginManager;
250
- /**
251
- * Current plugin
252
- */
253
- plugin: Plugin<TPluginOptions>;
254
- mode: KubbFile.Mode;
255
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
256
- override: Array<Override<TOptions>> | undefined;
257
- contentType?: contentType;
258
- output?: string;
259
- };
260
- type SchemaGeneratorOptions = {
261
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
262
- unknownType: 'any' | 'unknown';
263
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
264
- enumSuffix?: string;
265
- usedEnumNames?: Record<string, number>;
266
- mapper?: Record<string, string>;
267
- typed?: boolean;
268
- transformers: {
269
- /**
270
- * Customize the names based on the type that is provided by the plugin.
271
- */
272
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
273
- /**
274
- * Receive schema and name(propertName) and return FakerMeta array
275
- * TODO TODO add docs
276
- * @beta
277
- */
278
- schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema[] | undefined;
279
- };
280
- };
281
- type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
282
- type SchemaProps = {
283
- schema?: SchemaObject;
284
- name?: string;
285
- parentName?: string;
286
- };
287
- declare abstract class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
288
- #private;
289
- refs: Refs;
290
- /**
291
- * Creates a type node from a given schema.
292
- * Delegates to getBaseTypeFromSchema internally and
293
- * optionally adds a union with null.
294
- */
295
- buildSchemas(props: SchemaProps): Schema[];
296
- deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
297
- find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
298
- static deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
299
- static findInObject<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
300
- static find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
301
- build(): Promise<Array<KubbFile.File<TFileMeta>>>;
302
- /**
303
- * Schema
304
- */
305
- abstract schema(name: string, object: SchemaObject): SchemaMethodResult<TFileMeta>;
306
- /**
307
- * Returns the source, in the future it will return a React component
308
- */
309
- abstract getSource<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>(name: string, schemas: Schema[], options?: TOptions): string[];
310
- /**
311
- * @deprecated only used for testing
312
- */
313
- abstract buildSource(name: string, object: SchemaObject | undefined, options?: SchemaGeneratorBuildOptions): string[];
314
- }
315
-
316
- export { type SchemaGeneratorBuildOptions as S, type SchemaGeneratorOptions as a, type SchemaMethodResult as b, SchemaGenerator as c, type Schema as d, type SchemaKeyword as e, type SchemaKeywordBase as f, type SchemaKeywordMapper as g, type SchemaMapper as h, isKeyword as i, schemaKeywords as s };
244
+ export { type Schema as S, type SchemaKeywordMapper as a, type SchemaKeyword as b, type SchemaKeywordBase as c, type SchemaMapper as d, isKeyword as i, schemaKeywords as s };
@@ -1,6 +1,4 @@
1
- import { KubbFile, ResolveNameParams, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
2
- import { SchemaObject, Oas, contentType } from '@kubb/oas';
3
- import { d as OperationSchema, b as Refs, g as Override } from './types-n5zV4Q3s.cjs';
1
+ import * as KubbFile from '@kubb/fs/types';
4
2
 
5
3
  type SchemaKeywordMapper = {
6
4
  object: {
@@ -243,74 +241,4 @@ type Schema = {
243
241
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
244
242
  declare function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]>;
245
243
 
246
- type SchemaMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
247
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
248
- oas: Oas;
249
- pluginManager: PluginManager;
250
- /**
251
- * Current plugin
252
- */
253
- plugin: Plugin<TPluginOptions>;
254
- mode: KubbFile.Mode;
255
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
256
- override: Array<Override<TOptions>> | undefined;
257
- contentType?: contentType;
258
- output?: string;
259
- };
260
- type SchemaGeneratorOptions = {
261
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
262
- unknownType: 'any' | 'unknown';
263
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
264
- enumSuffix?: string;
265
- usedEnumNames?: Record<string, number>;
266
- mapper?: Record<string, string>;
267
- typed?: boolean;
268
- transformers: {
269
- /**
270
- * Customize the names based on the type that is provided by the plugin.
271
- */
272
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
273
- /**
274
- * Receive schema and name(propertName) and return FakerMeta array
275
- * TODO TODO add docs
276
- * @beta
277
- */
278
- schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema[] | undefined;
279
- };
280
- };
281
- type SchemaGeneratorBuildOptions = Omit<OperationSchema, 'name' | 'schema'>;
282
- type SchemaProps = {
283
- schema?: SchemaObject;
284
- name?: string;
285
- parentName?: string;
286
- };
287
- declare abstract class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
288
- #private;
289
- refs: Refs;
290
- /**
291
- * Creates a type node from a given schema.
292
- * Delegates to getBaseTypeFromSchema internally and
293
- * optionally adds a union with null.
294
- */
295
- buildSchemas(props: SchemaProps): Schema[];
296
- deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
297
- find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
298
- static deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
299
- static findInObject<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
300
- static find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
301
- build(): Promise<Array<KubbFile.File<TFileMeta>>>;
302
- /**
303
- * Schema
304
- */
305
- abstract schema(name: string, object: SchemaObject): SchemaMethodResult<TFileMeta>;
306
- /**
307
- * Returns the source, in the future it will return a React component
308
- */
309
- abstract getSource<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>(name: string, schemas: Schema[], options?: TOptions): string[];
310
- /**
311
- * @deprecated only used for testing
312
- */
313
- abstract buildSource(name: string, object: SchemaObject | undefined, options?: SchemaGeneratorBuildOptions): string[];
314
- }
315
-
316
- export { type SchemaGeneratorBuildOptions as S, type SchemaGeneratorOptions as a, type SchemaMethodResult as b, SchemaGenerator as c, type Schema as d, type SchemaKeyword as e, type SchemaKeywordBase as f, type SchemaKeywordMapper as g, type SchemaMapper as h, isKeyword as i, schemaKeywords as s };
244
+ export { type Schema as S, type SchemaKeywordMapper as a, type SchemaKeyword as b, type SchemaKeywordBase as c, type SchemaMapper as d, isKeyword as i, schemaKeywords as s };
@@ -56,6 +56,51 @@ var init_esm_shims = __esm({
56
56
  }
57
57
  });
58
58
 
59
+ // src/utils/getSchemas.ts
60
+ init_esm_shims();
61
+ function getSchemas({ oas, contentType, includes = ["schemas", "requestBodies", "responses"] }) {
62
+ const components = oas.getDefinition().components;
63
+ let schemas = {};
64
+ if (includes.includes("schemas")) {
65
+ schemas = {
66
+ ...schemas,
67
+ ...components?.schemas || {}
68
+ };
69
+ }
70
+ const requestBodies = components?.requestBodies || {};
71
+ if (includes.includes("responses")) {
72
+ const responses = components?.responses || {};
73
+ Object.entries(responses).forEach(([name, response]) => {
74
+ if (response.content && !schemas[name]) {
75
+ const firstContentType = Object.keys(response.content)[0] || "application/json";
76
+ schemas[name] = response.content?.[contentType || firstContentType]?.schema;
77
+ }
78
+ });
79
+ }
80
+ if (includes.includes("requestBodies")) {
81
+ Object.entries(requestBodies).forEach(([name, request]) => {
82
+ if (request.content && !schemas[name]) {
83
+ const firstContentType = Object.keys(request.content)[0] || "application/json";
84
+ schemas[name] = request.content?.[contentType || firstContentType]?.schema;
85
+ }
86
+ });
87
+ }
88
+ return schemas;
89
+ }
90
+
91
+ // src/utils/getSchemaFactory.ts
92
+ init_esm_shims();
93
+ import { isOpenApiV3_1Document } from "@kubb/oas";
94
+ function getSchemaFactory(oas) {
95
+ return (schema) => {
96
+ const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
97
+ return {
98
+ schema,
99
+ version
100
+ };
101
+ };
102
+ }
103
+
59
104
  export {
60
105
  __commonJS,
61
106
  __toESM,
@@ -63,6 +108,8 @@ export {
63
108
  __privateAdd,
64
109
  __privateSet,
65
110
  __privateMethod,
66
- init_esm_shims
111
+ init_esm_shims,
112
+ getSchemas,
113
+ getSchemaFactory
67
114
  };
68
- //# sourceMappingURL=chunk-UMYKVV7G.js.map
115
+ //# sourceMappingURL=chunk-37DRAF2Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.4_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._vnyhfq7fulozpuwbvh64t7gkvm/node_modules/tsup/assets/esm_shims.js","../src/utils/getSchemas.ts","../src/utils/getSchemaFactory.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import type { Oas, OasTypes, contentType } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\nexport type GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\n\n let schemas: Record<string, OasTypes.SchemaObject> = {}\n\n if (includes.includes('schemas')) {\n schemas = {\n ...schemas,\n ...((components?.schemas as Record<string, OasTypes.SchemaObject>) || {}),\n }\n }\n\n const requestBodies = components?.requestBodies || {}\n if (includes.includes('responses')) {\n const responses = components?.responses || {}\n\n Object.entries(responses).forEach(([name, response]: [string, OasTypes.ResponseObject]) => {\n if (response.content && !schemas[name]) {\n const firstContentType = Object.keys(response.content)[0] || 'application/json'\n schemas[name] = response.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n if (includes.includes('requestBodies')) {\n Object.entries(requestBodies).forEach(([name, request]: [string, OasTypes.RequestBodyObject]) => {\n if (request.content && !schemas[name]) {\n const firstContentType = Object.keys(request.content)[0] || 'application/json'\n schemas[name] = request.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n return schemas\n}\n","import { isOpenApiV3_1Document } from '@kubb/oas'\n\nimport type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } 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 schema?: (TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.0'\n }\n | {\n schema?: (TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.1'\n }\n\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema?: SchemaObject) => SchemaResult<TWithRef> {\n return (schema?: SchemaObject) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schema,\n version,\n } as SchemaResult<TWithRef>\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAUO,SAAS,WAAW,EAAE,KAAK,aAAa,WAAW,CAAC,WAAW,iBAAiB,WAAW,EAAE,GAA2D;AAC7J,QAAM,aAAa,IAAI,cAAc,EAAE;AAEvC,MAAI,UAAiD,CAAC;AAEtD,MAAI,SAAS,SAAS,SAAS,GAAG;AAChC,cAAU;AAAA,MACR,GAAG;AAAA,MACH,GAAK,YAAY,WAAqD,CAAC;AAAA,IACzE;AAAA,EACF;AAEA,QAAM,gBAAgB,YAAY,iBAAiB,CAAC;AACpD,MAAI,SAAS,SAAS,WAAW,GAAG;AAClC,UAAM,YAAY,YAAY,aAAa,CAAC;AAE5C,WAAO,QAAQ,SAAS,EAAE,QAAQ,CAAC,CAAC,MAAM,QAAQ,MAAyC;AACzF,UAAI,SAAS,WAAW,CAAC,QAAQ,IAAI,GAAG;AACtC,cAAM,mBAAmB,OAAO,KAAK,SAAS,OAAO,EAAE,CAAC,KAAK;AAC7D,gBAAQ,IAAI,IAAI,SAAS,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACvE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI,SAAS,SAAS,eAAe,GAAG;AACtC,WAAO,QAAQ,aAAa,EAAE,QAAQ,CAAC,CAAC,MAAM,OAAO,MAA4C;AAC/F,UAAI,QAAQ,WAAW,CAAC,QAAQ,IAAI,GAAG;AACrC,cAAM,mBAAmB,OAAO,KAAK,QAAQ,OAAO,EAAE,CAAC,KAAK;AAC5D,gBAAQ,IAAI,IAAI,QAAQ,UAAU,eAAe,gBAAgB,GAAG;AAAA,MACtE;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AC5CA;AAAA,SAAS,6BAA6B;AAuB/B,SAAS,iBAAmD,KAA6D;AAC9H,SAAO,CAAC,WAA0B;AAChC,UAAM,UAAU,sBAAsB,IAAI,GAAG,IAAI,QAAQ;AAEzD,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}