@kubb/plugin-oas 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (77) hide show
  1. package/dist/{OperationGenerator-BqfyX5-8.d.cts → OperationGenerator-B5CoXmjA.d.cts} +22 -20
  2. package/dist/{OperationGenerator-BqfyX5-8.d.ts → OperationGenerator-B5CoXmjA.d.ts} +22 -20
  3. package/dist/{Schema-BgpIlA79.d.cts → Schema-BsgDay0E.d.cts} +1 -12
  4. package/dist/{Schema-ExMIJOhD.d.ts → Schema-Dvt6i_X3.d.ts} +1 -12
  5. package/dist/chunk-2QECZEUD.js +76 -0
  6. package/dist/chunk-2QECZEUD.js.map +1 -0
  7. package/dist/chunk-4OQEPWOG.js +38 -0
  8. package/dist/chunk-4OQEPWOG.js.map +1 -0
  9. package/dist/chunk-7Q5B67MW.cjs +1110 -0
  10. package/dist/chunk-7Q5B67MW.cjs.map +1 -0
  11. package/dist/chunk-7XBQZ7AX.js +1098 -0
  12. package/dist/chunk-7XBQZ7AX.js.map +1 -0
  13. package/dist/{chunk-YSPJF26N.cjs → chunk-CQDZGAA6.cjs} +28 -798
  14. package/dist/chunk-CQDZGAA6.cjs.map +1 -0
  15. package/dist/{chunk-B4WIB7UG.js → chunk-CYF724QJ.js} +11 -773
  16. package/dist/chunk-CYF724QJ.js.map +1 -0
  17. package/dist/{chunk-A2T3ZQOU.js → chunk-D2N6LDLT.js} +15 -13
  18. package/dist/chunk-D2N6LDLT.js.map +1 -0
  19. package/dist/{chunk-6BDSF64V.cjs → chunk-LCPCIS3S.cjs} +19 -17
  20. package/dist/chunk-LCPCIS3S.cjs.map +1 -0
  21. package/dist/chunk-PUFCST25.cjs +84 -0
  22. package/dist/chunk-PUFCST25.cjs.map +1 -0
  23. package/dist/chunk-TYQZ2BD7.cjs +42 -0
  24. package/dist/chunk-TYQZ2BD7.cjs.map +1 -0
  25. package/dist/components.cjs +5 -6
  26. package/dist/components.d.cts +2 -2
  27. package/dist/components.d.ts +2 -2
  28. package/dist/components.js +2 -3
  29. package/dist/generators.cjs +4 -5
  30. package/dist/generators.d.cts +1 -1
  31. package/dist/generators.d.ts +1 -1
  32. package/dist/generators.js +3 -4
  33. package/dist/hooks.cjs +102 -31
  34. package/dist/hooks.cjs.map +1 -1
  35. package/dist/hooks.d.cts +39 -6
  36. package/dist/hooks.d.ts +39 -6
  37. package/dist/hooks.js +92 -20
  38. package/dist/hooks.js.map +1 -1
  39. package/dist/index.cjs +25 -410
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +2 -2
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +5 -400
  44. package/dist/index.js.map +1 -1
  45. package/dist/utils.cjs +12 -12
  46. package/dist/utils.cjs.map +1 -1
  47. package/dist/utils.d.cts +2 -2
  48. package/dist/utils.d.ts +2 -2
  49. package/dist/utils.js +2 -3
  50. package/dist/utils.js.map +1 -1
  51. package/package.json +10 -10
  52. package/src/OperationGenerator.ts +11 -15
  53. package/src/SchemaGenerator.ts +14 -5
  54. package/src/components/Schema.tsx +1 -98
  55. package/src/generator.tsx +22 -14
  56. package/src/generators/jsonGenerator.ts +4 -4
  57. package/src/hooks/index.ts +2 -0
  58. package/src/hooks/useOperationManager.ts +76 -29
  59. package/src/hooks/useSchemaManager.ts +76 -0
  60. package/src/types.ts +5 -0
  61. package/src/utils/getParams.ts +1 -1
  62. package/dist/chunk-2S2QRJPN.cjs +0 -38
  63. package/dist/chunk-2S2QRJPN.cjs.map +0 -1
  64. package/dist/chunk-6BDSF64V.cjs.map +0 -1
  65. package/dist/chunk-A2T3ZQOU.js.map +0 -1
  66. package/dist/chunk-B4WIB7UG.js.map +0 -1
  67. package/dist/chunk-E2Z4IRAI.js +0 -84
  68. package/dist/chunk-E2Z4IRAI.js.map +0 -1
  69. package/dist/chunk-EJHTGW4H.js +0 -6
  70. package/dist/chunk-EJHTGW4H.js.map +0 -1
  71. package/dist/chunk-OSKSFHO2.js +0 -32
  72. package/dist/chunk-OSKSFHO2.js.map +0 -1
  73. package/dist/chunk-SMB4EG6V.cjs +0 -8
  74. package/dist/chunk-SMB4EG6V.cjs.map +0 -1
  75. package/dist/chunk-XELSZPJC.cjs +0 -90
  76. package/dist/chunk-XELSZPJC.cjs.map +0 -1
  77. package/dist/chunk-YSPJF26N.cjs.map +0 -1
@@ -450,7 +450,7 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
450
450
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
451
451
  static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
452
452
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
453
- build(...generators: Array<Generator<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>>;
453
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
454
454
  /**
455
455
  * Schema
456
456
  */
@@ -470,23 +470,26 @@ type OperationProps<TOptions extends PluginFactoryOptions> = {
470
470
  };
471
471
  type SchemaProps<TOptions extends PluginFactoryOptions> = {
472
472
  instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
473
- name: string;
474
- schema: SchemaObject;
473
+ schema: {
474
+ name: string;
475
+ tree: Array<Schema>;
476
+ value: SchemaObject;
477
+ };
475
478
  options: TOptions['resolvedOptions'];
476
479
  };
477
480
  type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
478
481
  name: string;
479
- operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
480
- operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
481
- schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
482
+ operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
483
+ operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
484
+ schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
482
485
  };
483
486
  type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
484
487
  declare function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions>;
485
488
  type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
486
489
  name: string;
487
- Operations?: (props: OperationsProps<TOptions>) => KubbNode;
488
- Operation?: (props: OperationProps<TOptions>) => KubbNode;
489
- Schema?: (props: SchemaProps<TOptions>) => KubbNode;
490
+ Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode;
491
+ Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode;
492
+ Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode;
490
493
  /**
491
494
  * Combine all react nodes and only render ones(to string or render)
492
495
  */
@@ -497,7 +500,7 @@ declare function createReactGenerator<TOptions extends PluginFactoryOptions>(par
497
500
  /**
498
501
  * @deprecated
499
502
  */
500
- type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
503
+ type GetOperationGeneratorOptions<T = any> = any;
501
504
  type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
502
505
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
503
506
  oas: Oas;
@@ -512,39 +515,38 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
512
515
  plugin: Plugin<TPluginOptions>;
513
516
  mode: KubbFile.Mode;
514
517
  };
515
- declare class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
518
+ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
516
519
  #private;
517
520
  get operationsByMethod(): OperationsByMethod;
518
521
  set operationsByMethod(paths: OperationsByMethod);
519
- getSchemas(operation: Operation, { forStatusCode, resolveName, }?: {
520
- forStatusCode?: string | number;
522
+ getSchemas(operation: Operation, { resolveName, }?: {
521
523
  resolveName?: (name: string) => string;
522
524
  }): OperationSchemas;
523
- build(...generators: Array<Generator<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>>;
525
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
524
526
  /**
525
527
  * Operation
526
528
  */
527
- operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
529
+ operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
528
530
  /**
529
531
  * GET
530
532
  */
531
- get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
533
+ get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
532
534
  /**
533
535
  * POST
534
536
  */
535
- post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
537
+ post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
536
538
  /**
537
539
  * PATCH
538
540
  */
539
- patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
541
+ patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
540
542
  /**
541
543
  * PUT
542
544
  */
543
- put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
545
+ put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
544
546
  /**
545
547
  * DELETE
546
548
  */
547
- delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
549
+ delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
548
550
  /**
549
551
  * Combination of GET, POST, PATCH, PUT, DELETE
550
552
  */
@@ -450,7 +450,7 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
450
450
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][];
451
451
  static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
452
452
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
453
- build(...generators: Array<Generator<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>>;
453
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
454
454
  /**
455
455
  * Schema
456
456
  */
@@ -470,23 +470,26 @@ type OperationProps<TOptions extends PluginFactoryOptions> = {
470
470
  };
471
471
  type SchemaProps<TOptions extends PluginFactoryOptions> = {
472
472
  instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
473
- name: string;
474
- schema: SchemaObject;
473
+ schema: {
474
+ name: string;
475
+ tree: Array<Schema>;
476
+ value: SchemaObject;
477
+ };
475
478
  options: TOptions['resolvedOptions'];
476
479
  };
477
480
  type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
478
481
  name: string;
479
- operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
480
- operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
481
- schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
482
+ operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
483
+ operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
484
+ schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
482
485
  };
483
486
  type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
484
487
  declare function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions>;
485
488
  type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
486
489
  name: string;
487
- Operations?: (props: OperationsProps<TOptions>) => KubbNode;
488
- Operation?: (props: OperationProps<TOptions>) => KubbNode;
489
- Schema?: (props: SchemaProps<TOptions>) => KubbNode;
490
+ Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode;
491
+ Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode;
492
+ Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode;
490
493
  /**
491
494
  * Combine all react nodes and only render ones(to string or render)
492
495
  */
@@ -497,7 +500,7 @@ declare function createReactGenerator<TOptions extends PluginFactoryOptions>(par
497
500
  /**
498
501
  * @deprecated
499
502
  */
500
- type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
503
+ type GetOperationGeneratorOptions<T = any> = any;
501
504
  type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
502
505
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
503
506
  oas: Oas;
@@ -512,39 +515,38 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
512
515
  plugin: Plugin<TPluginOptions>;
513
516
  mode: KubbFile.Mode;
514
517
  };
515
- declare class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
518
+ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
516
519
  #private;
517
520
  get operationsByMethod(): OperationsByMethod;
518
521
  set operationsByMethod(paths: OperationsByMethod);
519
- getSchemas(operation: Operation, { forStatusCode, resolveName, }?: {
520
- forStatusCode?: string | number;
522
+ getSchemas(operation: Operation, { resolveName, }?: {
521
523
  resolveName?: (name: string) => string;
522
524
  }): OperationSchemas;
523
- build(...generators: Array<Generator<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>>;
525
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
524
526
  /**
525
527
  * Operation
526
528
  */
527
- operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
529
+ operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
528
530
  /**
529
531
  * GET
530
532
  */
531
- get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
533
+ get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
532
534
  /**
533
535
  * POST
534
536
  */
535
- post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
537
+ post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
536
538
  /**
537
539
  * PATCH
538
540
  */
539
- patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
541
+ patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
540
542
  /**
541
543
  * PUT
542
544
  */
543
- put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
545
+ put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
544
546
  /**
545
547
  * DELETE
546
548
  */
547
- delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
549
+ delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta>;
548
550
  /**
549
551
  * Combination of GET, POST, PATCH, PUT, DELETE
550
552
  */
@@ -1,8 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
2
  import { SchemaObject } from '@kubb/oas';
4
3
  import { KubbNode } from '@kubb/react/types';
5
- import { g as Schema$1 } from './OperationGenerator-BqfyX5-8.cjs';
4
+ import { g as Schema$1 } from './OperationGenerator-B5CoXmjA.cjs';
6
5
 
7
6
  type SchemaContextProps = {
8
7
  name: string;
@@ -17,17 +16,7 @@ type Props = {
17
16
  };
18
17
  declare function Schema({ name, value, tree, children }: Props): KubbNode;
19
18
  declare namespace Schema {
20
- var File: ({ isTypeOnly, children }: FileProps) => ReactNode;
21
- var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
22
19
  var Context: react.Context<SchemaContextProps>;
23
20
  }
24
- type FileProps = {
25
- isTypeOnly?: boolean;
26
- output: string | undefined;
27
- children?: KubbNode;
28
- };
29
- type SchemaImportsProps = {
30
- isTypeOnly?: boolean;
31
- };
32
21
 
33
22
  export { Schema as S, type SchemaContextProps as a };
@@ -1,8 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
2
  import { SchemaObject } from '@kubb/oas';
4
3
  import { KubbNode } from '@kubb/react/types';
5
- import { g as Schema$1 } from './OperationGenerator-BqfyX5-8.js';
4
+ import { g as Schema$1 } from './OperationGenerator-B5CoXmjA.js';
6
5
 
7
6
  type SchemaContextProps = {
8
7
  name: string;
@@ -17,17 +16,7 @@ type Props = {
17
16
  };
18
17
  declare function Schema({ name, value, tree, children }: Props): KubbNode;
19
18
  declare namespace Schema {
20
- var File: ({ isTypeOnly, children }: FileProps) => ReactNode;
21
- var Imports: ({ isTypeOnly }: SchemaImportsProps) => ReactNode;
22
19
  var Context: react.Context<SchemaContextProps>;
23
20
  }
24
- type FileProps = {
25
- isTypeOnly?: boolean;
26
- output: string | undefined;
27
- children?: KubbNode;
28
- };
29
- type SchemaImportsProps = {
30
- isTypeOnly?: boolean;
31
- };
32
21
 
33
22
  export { Schema as S, type SchemaContextProps as a };
@@ -0,0 +1,76 @@
1
+ import { init_esm_shims } from './chunk-4OQEPWOG.js';
2
+ import { resolve } from 'node:path';
3
+ import { URLPath } from '@kubb/core/utils';
4
+ import { parse } from '@kubb/oas/parser';
5
+ import { Oas, isOpenApiV3_1Document } from '@kubb/oas';
6
+ import yaml from '@stoplight/yaml';
7
+
8
+ // src/utils/getSchemas.ts
9
+ init_esm_shims();
10
+ function getSchemas({ oas, contentType, includes = ["schemas", "requestBodies", "responses"] }) {
11
+ const components = oas.getDefinition().components;
12
+ let schemas = {};
13
+ if (includes.includes("schemas")) {
14
+ schemas = {
15
+ ...schemas,
16
+ ...components?.schemas || {}
17
+ };
18
+ }
19
+ const requestBodies = components?.requestBodies || {};
20
+ if (includes.includes("responses")) {
21
+ const responses = components?.responses || {};
22
+ Object.entries(responses).forEach(([name, response]) => {
23
+ if (response.content && !schemas[name]) {
24
+ const firstContentType = Object.keys(response.content)[0] || "application/json";
25
+ schemas[name] = response.content?.[contentType || firstContentType]?.schema;
26
+ }
27
+ });
28
+ }
29
+ if (includes.includes("requestBodies")) {
30
+ Object.entries(requestBodies).forEach(([name, request]) => {
31
+ if (request.content && !schemas[name]) {
32
+ const firstContentType = Object.keys(request.content)[0] || "application/json";
33
+ schemas[name] = request.content?.[contentType || firstContentType]?.schema;
34
+ }
35
+ });
36
+ }
37
+ return schemas;
38
+ }
39
+
40
+ // src/utils/parseFromConfig.ts
41
+ init_esm_shims();
42
+ function parseFromConfig(config, options = {}, oasClass = Oas) {
43
+ if ("data" in config.input) {
44
+ if (typeof config.input.data === "object") {
45
+ const api2 = JSON.parse(JSON.stringify(config.input.data));
46
+ return parse(api2, options, oasClass);
47
+ }
48
+ try {
49
+ const api2 = yaml.parse(config.input.data);
50
+ return parse(api2, options, oasClass);
51
+ } catch (e) {
52
+ }
53
+ const api = JSON.parse(JSON.stringify(config.input.data));
54
+ return parse(api, options, oasClass);
55
+ }
56
+ if (new URLPath(config.input.path).isURL) {
57
+ return parse(config.input.path, options, oasClass);
58
+ }
59
+ return parse(resolve(config.root, config.input.path), options, oasClass);
60
+ }
61
+
62
+ // src/utils/getSchemaFactory.ts
63
+ init_esm_shims();
64
+ function getSchemaFactory(oas) {
65
+ return (schema) => {
66
+ const version = isOpenApiV3_1Document(oas.api) ? "3.1" : "3.0";
67
+ return {
68
+ schema,
69
+ version
70
+ };
71
+ };
72
+ }
73
+
74
+ export { getSchemaFactory, getSchemas, parseFromConfig };
75
+ //# sourceMappingURL=chunk-2QECZEUD.js.map
76
+ //# sourceMappingURL=chunk-2QECZEUD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/getSchemas.ts","../src/utils/parseFromConfig.ts","../src/utils/getSchemaFactory.ts"],"names":["api"],"mappings":";;;;;;;;AAAA,cAAA,EAAA,CAAA;AAUO,SAAS,UAAA,CAAW,EAAE,GAAA,EAAK,WAAa,EAAA,QAAA,GAAW,CAAC,SAAW,EAAA,eAAA,EAAiB,WAAW,CAAA,EAA6D,EAAA;AAC7J,EAAM,MAAA,UAAA,GAAa,GAAI,CAAA,aAAA,EAAgB,CAAA,UAAA,CAAA;AAEvC,EAAA,IAAI,UAAiD,EAAC,CAAA;AAEtD,EAAI,IAAA,QAAA,CAAS,QAAS,CAAA,SAAS,CAAG,EAAA;AAChC,IAAU,OAAA,GAAA;AAAA,MACR,GAAG,OAAA;AAAA,MACH,GAAK,UAAY,EAAA,OAAA,IAAqD,EAAC;AAAA,KACzE,CAAA;AAAA,GACF;AAEA,EAAM,MAAA,aAAA,GAAgB,UAAY,EAAA,aAAA,IAAiB,EAAC,CA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,GAAA,qBAAA,CAAsB,GAAI,CAAA,GAAG,IAAI,KAAQ,GAAA,KAAA,CAAA;AAEzD,IAAO,OAAA;AAAA,MACL,MAAA;AAAA,MACA,OAAA;AAAA,KACF,CAAA;AAAA,GACF,CAAA;AACF","file":"chunk-2QECZEUD.js","sourcesContent":["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 { resolve } from 'node:path'\n\nimport { URLPath } from '@kubb/core/utils'\n\nimport { type FormatOptions, parse } from '@kubb/oas/parser'\n\nimport type { Config } from '@kubb/core'\nimport { Oas, type OasTypes } from '@kubb/oas'\nimport yaml from '@stoplight/yaml'\n\nexport function parseFromConfig(config: Config, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {\n if ('data' in config.input) {\n if (typeof config.input.data === 'object') {\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n return parse(api, options, oasClass)\n }\n\n try {\n const api: string = yaml.parse(config.input.data as string) as string\n\n return parse(api, options, oasClass)\n } catch (e) {\n /* empty */\n }\n\n const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument\n\n return parse(api, options, oasClass)\n }\n\n if (new URLPath(config.input.path).isURL) {\n return parse(config.input.path, options, oasClass)\n }\n\n return parse(resolve(config.root, config.input.path), options, oasClass)\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"]}
@@ -0,0 +1,38 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+
30
+ // ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.5__@swc+core@1.7.22_jiti@1.21.6__vgec2xea2cg5zleragji3g6qgq/node_modules/tsup/assets/esm_shims.js
31
+ var init_esm_shims = __esm({
32
+ "../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.5__@swc+core@1.7.22_jiti@1.21.6__vgec2xea2cg5zleragji3g6qgq/node_modules/tsup/assets/esm_shims.js"() {
33
+ }
34
+ });
35
+
36
+ export { __commonJS, __toESM, init_esm_shims };
37
+ //# sourceMappingURL=chunk-4OQEPWOG.js.map
38
+ //# sourceMappingURL=chunk-4OQEPWOG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.5__@swc+core@1.7.22_jiti@1.21.6__vgec2xea2cg5zleragji3g6qgq/node_modules/tsup/assets/esm_shims.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,yLAAA,GAAA;AAAA,GAAA;AAAA,CAAA","file":"chunk-4OQEPWOG.js","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"]}