@kubb/plugin-faker 4.4.1 → 4.5.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 (33) hide show
  1. package/dist/{components-DdXRywj6.js → components-B6wjVu4Y.js} +32 -25
  2. package/dist/components-B6wjVu4Y.js.map +1 -0
  3. package/dist/{components-BtFAhtPK.cjs → components-Dq57kUQf.cjs} +32 -25
  4. package/dist/components-Dq57kUQf.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +1 -1
  7. package/dist/components.d.ts +1 -1
  8. package/dist/components.js +1 -1
  9. package/dist/{fakerGenerator-6YTX8ENZ.cjs → fakerGenerator-CYRnwp6R.cjs} +40 -47
  10. package/dist/fakerGenerator-CYRnwp6R.cjs.map +1 -0
  11. package/dist/{fakerGenerator-D3zaPh1_.js → fakerGenerator-CfTiMdtr.js} +41 -48
  12. package/dist/fakerGenerator-CfTiMdtr.js.map +1 -0
  13. package/dist/generators.cjs +2 -2
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +2 -2
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +2 -2
  21. package/dist/{types-Dda1jVMe.d.ts → types-CEWRTyrN.d.ts} +168 -174
  22. package/dist/{types-DRMQqYat.d.cts → types-NHbH6Svj.d.cts} +168 -174
  23. package/package.json +8 -8
  24. package/src/components/Faker.tsx +1 -3
  25. package/src/generators/__snapshots__/enumNames.ts +1 -1
  26. package/src/generators/__snapshots__/enumVarNames.ts +1 -1
  27. package/src/generators/fakerGenerator.tsx +17 -18
  28. package/src/parser.ts +9 -13
  29. package/src/types.ts +2 -1
  30. package/dist/components-BtFAhtPK.cjs.map +0 -1
  31. package/dist/components-DdXRywj6.js.map +0 -1
  32. package/dist/fakerGenerator-6YTX8ENZ.cjs.map +0 -1
  33. package/dist/fakerGenerator-D3zaPh1_.js.map +0 -1
@@ -556,170 +556,6 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
556
556
  valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
557
557
  }
558
558
  //#endregion
559
- //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
560
- type ReactGenerator<TOptions extends PluginFactoryOptions> = {
561
- name: string;
562
- type: 'react';
563
- Operations: (props: OperationsProps<TOptions>) => KubbNode;
564
- Operation: (props: OperationProps<TOptions>) => KubbNode;
565
- Schema: (props: SchemaProps$1<TOptions>) => KubbNode;
566
- };
567
- //#endregion
568
- //#region ../plugin-oas/src/generators/types.d.ts
569
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
570
- /**
571
- * @deprecated
572
- */
573
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
574
- options: TOptions['resolvedOptions'];
575
- operations: Array<Operation$1>;
576
- };
577
- type OperationProps<TOptions extends PluginFactoryOptions> = {
578
- /**
579
- * @deprecated
580
- */
581
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
582
- options: TOptions['resolvedOptions'];
583
- operation: Operation$1;
584
- };
585
- type SchemaProps$1<TOptions extends PluginFactoryOptions> = {
586
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
587
- options: TOptions['resolvedOptions'];
588
- schema: {
589
- name: string;
590
- tree: Array<Schema>;
591
- value: SchemaObject$1;
592
- };
593
- };
594
- type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
595
- //#endregion
596
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
597
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
598
- name: string;
599
- type: 'core';
600
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
601
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
602
- schema: (props: SchemaProps$1<TOptions>) => Promise<KubbFile.File[]>;
603
- };
604
- //#endregion
605
- //#region ../plugin-oas/src/types.d.ts
606
- type ResolvePathOptions = {
607
- pluginKey?: Plugin['key'];
608
- group?: {
609
- tag?: string;
610
- path?: string;
611
- };
612
- type?: ResolveNameParams['type'];
613
- };
614
- /**
615
- * `propertyName` is the ref name + resolved with the nameResolver
616
- * @example import { Pet } from './Pet'
617
- *
618
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
619
- *
620
- * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
621
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
622
- */
623
- type Ref = {
624
- propertyName: string;
625
- originalName: string;
626
- path: KubbFile.OptionalPath;
627
- pluginKey?: Plugin['key'];
628
- };
629
- type Refs = Record<string, Ref>;
630
- type OperationSchema = {
631
- /**
632
- * Converted name, contains already `PathParams`, `QueryParams`, ...
633
- */
634
- name: string;
635
- schema: SchemaObject$1;
636
- operation?: Operation$1;
637
- /**
638
- * OperationName in PascalCase, only being used in OperationGenerator
639
- */
640
- operationName: string;
641
- description?: string;
642
- statusCode?: number;
643
- keys?: string[];
644
- keysToOmit?: string[];
645
- withData?: boolean;
646
- };
647
- type OperationSchemas = {
648
- pathParams?: OperationSchema & {
649
- keysToOmit?: never;
650
- };
651
- queryParams?: OperationSchema & {
652
- keysToOmit?: never;
653
- };
654
- headerParams?: OperationSchema & {
655
- keysToOmit?: never;
656
- };
657
- request?: OperationSchema;
658
- response: OperationSchema;
659
- responses: Array<OperationSchema>;
660
- statusCodes?: Array<OperationSchema>;
661
- errors?: Array<OperationSchema>;
662
- };
663
- type ByTag = {
664
- type: 'tag';
665
- pattern: string | RegExp;
666
- };
667
- type ByOperationId = {
668
- type: 'operationId';
669
- pattern: string | RegExp;
670
- };
671
- type ByPath = {
672
- type: 'path';
673
- pattern: string | RegExp;
674
- };
675
- type ByMethod = {
676
- type: 'method';
677
- pattern: HttpMethod | RegExp;
678
- };
679
- type BySchemaName = {
680
- type: 'schemaName';
681
- pattern: string | RegExp;
682
- };
683
- type ByContentType = {
684
- type: 'contentType';
685
- pattern: string | RegExp;
686
- };
687
- type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
688
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
689
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
690
- options: Partial<TOptions>;
691
- };
692
- //#endregion
693
- //#region ../plugin-oas/src/OperationGenerator.d.ts
694
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
695
- fabric: Fabric;
696
- oas: Oas;
697
- exclude: Array<Exclude$1> | undefined;
698
- include: Array<Include> | undefined;
699
- override: Array<Override<TOptions>> | undefined;
700
- contentType: contentType | undefined;
701
- pluginManager: PluginManager;
702
- /**
703
- * Current plugin
704
- */
705
- plugin: Plugin<TPluginOptions>;
706
- mode: KubbFile.Mode;
707
- };
708
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
709
- #private;
710
- getSchemas(operation: Operation$1, {
711
- resolveName
712
- }?: {
713
- resolveName?: (name: string) => string;
714
- }): OperationSchemas;
715
- getOperations(): Promise<Array<{
716
- path: string;
717
- method: HttpMethod;
718
- operation: Operation$1;
719
- }>>;
720
- build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
721
- }
722
- //#endregion
723
559
  //#region ../plugin-oas/src/SchemaMapper.d.ts
724
560
  type SchemaKeywordMapper = {
725
561
  object: {
@@ -937,8 +773,96 @@ type Schema = {
937
773
  keyword: string;
938
774
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
939
775
  //#endregion
776
+ //#region ../plugin-oas/src/types.d.ts
777
+ type ResolvePathOptions = {
778
+ pluginKey?: Plugin['key'];
779
+ group?: {
780
+ tag?: string;
781
+ path?: string;
782
+ };
783
+ type?: ResolveNameParams['type'];
784
+ };
785
+ /**
786
+ * `propertyName` is the ref name + resolved with the nameResolver
787
+ * @example import { Pet } from './Pet'
788
+ *
789
+ * `originalName` is the original name used(in PascalCase), only used to remove duplicates
790
+ *
791
+ * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
792
+ * @example import a type(plugin-ts) for a mock file(swagger-faker)
793
+ */
794
+ type Ref = {
795
+ propertyName: string;
796
+ originalName: string;
797
+ path: KubbFile.OptionalPath;
798
+ pluginKey?: Plugin['key'];
799
+ };
800
+ type Refs = Record<string, Ref>;
801
+ type OperationSchema = {
802
+ /**
803
+ * Converted name, contains already `PathParams`, `QueryParams`, ...
804
+ */
805
+ name: string;
806
+ schema: SchemaObject$1;
807
+ operation?: Operation$1;
808
+ /**
809
+ * OperationName in PascalCase, only being used in OperationGenerator
810
+ */
811
+ operationName: string;
812
+ description?: string;
813
+ statusCode?: number;
814
+ keys?: string[];
815
+ keysToOmit?: string[];
816
+ withData?: boolean;
817
+ };
818
+ type OperationSchemas = {
819
+ pathParams?: OperationSchema & {
820
+ keysToOmit?: never;
821
+ };
822
+ queryParams?: OperationSchema & {
823
+ keysToOmit?: never;
824
+ };
825
+ headerParams?: OperationSchema & {
826
+ keysToOmit?: never;
827
+ };
828
+ request?: OperationSchema;
829
+ response: OperationSchema;
830
+ responses: Array<OperationSchema>;
831
+ statusCodes?: Array<OperationSchema>;
832
+ errors?: Array<OperationSchema>;
833
+ };
834
+ type ByTag = {
835
+ type: 'tag';
836
+ pattern: string | RegExp;
837
+ };
838
+ type ByOperationId = {
839
+ type: 'operationId';
840
+ pattern: string | RegExp;
841
+ };
842
+ type ByPath = {
843
+ type: 'path';
844
+ pattern: string | RegExp;
845
+ };
846
+ type ByMethod = {
847
+ type: 'method';
848
+ pattern: HttpMethod | RegExp;
849
+ };
850
+ type BySchemaName = {
851
+ type: 'schemaName';
852
+ pattern: string | RegExp;
853
+ };
854
+ type ByContentType = {
855
+ type: 'contentType';
856
+ pattern: string | RegExp;
857
+ };
858
+ type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
859
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
860
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
861
+ options: Partial<TOptions>;
862
+ };
863
+ //#endregion
940
864
  //#region ../plugin-oas/src/SchemaGenerator.d.ts
941
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
865
+ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
942
866
  fabric: Fabric;
943
867
  oas: Oas;
944
868
  pluginManager: PluginManager;
@@ -971,15 +895,15 @@ type SchemaGeneratorOptions = {
971
895
  * TODO TODO add docs
972
896
  * @beta
973
897
  */
974
- schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema[] | undefined;
898
+ schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
975
899
  };
976
900
  };
977
- type SchemaProps = {
901
+ type SchemaProps$1 = {
978
902
  schemaObject?: SchemaObject$1;
979
903
  name?: string;
980
904
  parentName?: string;
981
905
  };
982
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
906
+ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
983
907
  #private;
984
908
  refs: Refs;
985
909
  /**
@@ -987,16 +911,86 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
987
911
  * Delegates to getBaseTypeFromSchema internally and
988
912
  * optionally adds a union with null.
989
913
  */
990
- parse(props: SchemaProps): Schema[];
991
- deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
992
- find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
914
+ parse(props: SchemaProps$1): Schema[];
993
915
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
994
- static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
995
916
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
996
917
  static combineObjects(tree: Schema[] | undefined): Schema[];
997
918
  build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
998
919
  }
999
920
  //#endregion
921
+ //#region ../plugin-oas/src/generators/createGenerator.d.ts
922
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
923
+ name: string;
924
+ type: 'core';
925
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
926
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
927
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
928
+ };
929
+ //#endregion
930
+ //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
931
+ type ReactGenerator<TOptions extends PluginFactoryOptions> = {
932
+ name: string;
933
+ type: 'react';
934
+ Operations: (props: OperationsProps<TOptions>) => KubbNode;
935
+ Operation: (props: OperationProps<TOptions>) => KubbNode;
936
+ Schema: (props: SchemaProps<TOptions>) => KubbNode;
937
+ };
938
+ //#endregion
939
+ //#region ../plugin-oas/src/generators/types.d.ts
940
+ type OperationsProps<TOptions extends PluginFactoryOptions> = {
941
+ config: Config;
942
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
943
+ plugin: Plugin<TOptions>;
944
+ operations: Array<Operation$1>;
945
+ };
946
+ type OperationProps<TOptions extends PluginFactoryOptions> = {
947
+ config: Config;
948
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
949
+ plugin: Plugin<TOptions>;
950
+ operation: Operation$1;
951
+ };
952
+ type SchemaProps<TOptions extends PluginFactoryOptions> = {
953
+ config: Config;
954
+ generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
955
+ plugin: Plugin<TOptions>;
956
+ schema: {
957
+ name: string;
958
+ tree: Array<Schema>;
959
+ value: SchemaObject$1;
960
+ };
961
+ };
962
+ type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
963
+ //#endregion
964
+ //#region ../plugin-oas/src/OperationGenerator.d.ts
965
+ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
966
+ fabric: Fabric;
967
+ oas: Oas;
968
+ exclude: Array<Exclude$1> | undefined;
969
+ include: Array<Include> | undefined;
970
+ override: Array<Override<TOptions>> | undefined;
971
+ contentType: contentType | undefined;
972
+ pluginManager: PluginManager;
973
+ /**
974
+ * Current plugin
975
+ */
976
+ plugin: Plugin<TPluginOptions>;
977
+ mode: KubbFile.Mode;
978
+ };
979
+ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
980
+ #private;
981
+ getSchemas(operation: Operation$1, {
982
+ resolveName
983
+ }?: {
984
+ resolveName?: (name: string) => string;
985
+ }): OperationSchemas;
986
+ getOperations(): Promise<Array<{
987
+ path: string;
988
+ method: HttpMethod;
989
+ operation: Operation$1;
990
+ }>>;
991
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
992
+ }
993
+ //#endregion
1000
994
  //#region src/types.d.ts
1001
995
  type Options$1 = {
1002
996
  /**
@@ -1100,5 +1094,5 @@ type ResolvedOptions = {
1100
1094
  };
1101
1095
  type PluginFaker = PluginFactoryOptions<'plugin-faker', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1102
1096
  //#endregion
1103
- export { UserPluginWithLifeCycle as a, ReactGenerator as i, PluginFaker as n, Schema as r, Options$1 as t };
1104
- //# sourceMappingURL=types-DRMQqYat.d.cts.map
1097
+ export { UserPluginWithLifeCycle as a, Schema as i, PluginFaker as n, ReactGenerator as r, Options$1 as t };
1098
+ //# sourceMappingURL=types-NHbH6Svj.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-faker",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "description": "Faker.js data generator plugin for Kubb, creating realistic mock data from OpenAPI specifications for development and testing.",
5
5
  "keywords": [
6
6
  "faker",
@@ -68,17 +68,17 @@
68
68
  }
69
69
  ],
70
70
  "dependencies": {
71
- "@kubb/react-fabric": "0.2.10",
72
- "@kubb/core": "4.4.1",
73
- "@kubb/oas": "4.4.1",
74
- "@kubb/plugin-oas": "4.4.1",
75
- "@kubb/plugin-ts": "4.4.1"
71
+ "@kubb/react-fabric": "0.2.14",
72
+ "@kubb/core": "4.5.0",
73
+ "@kubb/oas": "4.5.0",
74
+ "@kubb/plugin-oas": "4.5.0",
75
+ "@kubb/plugin-ts": "4.5.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@kubb/plugin-oas": "4.4.1"
78
+ "@kubb/plugin-oas": "4.5.0"
79
79
  },
80
80
  "peerDependencies": {
81
- "@kubb/react-fabric": "0.2.10"
81
+ "@kubb/react-fabric": "0.2.14"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=20"
@@ -22,11 +22,9 @@ export function Faker({ tree, description, name, typeName, seed, regexGenerator,
22
22
  tree
23
23
  .map((schema, _index, siblings) =>
24
24
  parserFaker.parse(
25
- { parent: undefined, current: schema, siblings },
25
+ { name, schema, parent: undefined, current: schema, siblings },
26
26
  {
27
- name,
28
27
  typeName,
29
- seed,
30
28
  regexGenerator,
31
29
  mapper,
32
30
  canOverride,
@@ -5,5 +5,5 @@
5
5
  import { faker } from '@faker-js/faker'
6
6
 
7
7
  export function enumNamesType() {
8
- return faker.helpers.arrayElement<any>([0, 1])
8
+ return faker.helpers.arrayElement<EnumNamesType>([0, 1])
9
9
  }
@@ -5,5 +5,5 @@
5
5
  import { faker } from '@faker-js/faker'
6
6
 
7
7
  export function enumVarNamesType() {
8
- return faker.helpers.arrayElement<any>([0, 1])
8
+ return faker.helpers.arrayElement<EnumVarNamesType>([0, 1])
9
9
  }
@@ -1,30 +1,31 @@
1
- import { useMode, usePlugin, usePluginManager } from '@kubb/core/hooks'
2
- import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
3
- import { Oas } from '@kubb/plugin-oas/components'
1
+ import { useMode, usePluginManager } from '@kubb/core/hooks'
2
+ import { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
3
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
4
4
  import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
5
5
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
- import { File } from '@kubb/react-fabric'
7
+ import { File, Fragment } from '@kubb/react-fabric'
8
8
  import { Faker } from '../components'
9
9
  import type { PluginFaker } from '../types'
10
10
 
11
11
  export const fakerGenerator = createReactGenerator<PluginFaker>({
12
12
  name: 'faker',
13
- Operation({ operation, options, instance }) {
14
- const { dateParser, regexGenerator, seed, mapper } = options
15
-
16
- const plugin = usePlugin<PluginFaker>()
13
+ Operation({ operation, generator, plugin }) {
14
+ const {
15
+ options,
16
+ options: { dateParser, regexGenerator, seed, mapper },
17
+ } = plugin
17
18
  const mode = useMode()
18
19
  const pluginManager = usePluginManager()
19
20
 
20
21
  const oas = useOas()
21
- const { getSchemas, getFile, getGroup } = useOperationManager()
22
+ const { getSchemas, getFile, getGroup } = useOperationManager(generator)
22
23
  const schemaManager = useSchemaManager()
23
24
 
24
25
  const file = getFile(operation)
25
26
  const schemas = getSchemas(operation)
26
27
  const schemaGenerator = new SchemaGenerator(options, {
27
- fabric: instance.context.fabric,
28
+ fabric: generator.context.fabric,
28
29
  oas,
29
30
  plugin,
30
31
  pluginManager,
@@ -36,7 +37,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
36
37
  .flat()
37
38
  .filter(Boolean)
38
39
 
39
- const mapOperationSchema = ({ name, schema: schemaObject, description, ...options }: OperationSchemaType, i: number) => {
40
+ const mapOperationSchema = ({ name, schema: schemaObject, description, ...options }: OperationSchemaType) => {
40
41
  const tree = schemaGenerator.parse({ schemaObject, name })
41
42
  const imports = schemaManager.getImports(tree)
42
43
  const group = options.operation ? getGroup(options.operation) : undefined
@@ -61,7 +62,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
61
62
  )
62
63
 
63
64
  return (
64
- <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>
65
+ <Fragment>
65
66
  {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
66
67
  {imports.map((imp) => (
67
68
  <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />
@@ -77,7 +78,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
77
78
  seed={seed}
78
79
  canOverride={canOverride}
79
80
  />
80
- </Oas.Schema>
81
+ </Fragment>
81
82
  )
82
83
  }
83
84
 
@@ -96,13 +97,11 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
96
97
  </File>
97
98
  )
98
99
  },
99
- Schema({ schema, options }) {
100
- const { dateParser, regexGenerator, seed, mapper } = options
101
-
100
+ Schema({ schema, plugin }) {
102
101
  const { getName, getFile, getImports } = useSchemaManager()
103
102
  const {
104
- options: { output },
105
- } = usePlugin<PluginFaker>()
103
+ options: { output, dateParser, regexGenerator, seed, mapper },
104
+ } = plugin
106
105
  const pluginManager = usePluginManager()
107
106
  const oas = useOas()
108
107
  const imports = getImports(schema.tree)
package/src/parser.ts CHANGED
@@ -179,18 +179,14 @@ export function joinItems(items: string[]): string {
179
179
  }
180
180
 
181
181
  type ParserOptions = {
182
- name: string
183
182
  typeName?: string
184
- description?: string
185
-
186
- seed?: number | number[]
187
183
  regexGenerator?: 'faker' | 'randexp'
188
184
  canOverride?: boolean
189
185
  dateParser?: Options['dateParser']
190
186
  mapper?: Record<string, string>
191
187
  }
192
188
 
193
- export function parse({ current, parent, name, siblings }: SchemaTree, options: ParserOptions): string | null | undefined {
189
+ export function parse({ schema, current, parent, name, siblings }: SchemaTree, options: ParserOptions): string | null | undefined {
194
190
  const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper]
195
191
 
196
192
  if (!value) {
@@ -203,22 +199,22 @@ export function parse({ current, parent, name, siblings }: SchemaTree, options:
203
199
  }
204
200
 
205
201
  return fakerKeywordMapper.union(
206
- current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
202
+ current.args.map((it) => parse({ schema, parent: current, name, current: it, siblings }, { ...options, canOverride: false })).filter(Boolean),
207
203
  )
208
204
  }
209
205
 
210
206
  if (isKeyword(current, schemaKeywords.and)) {
211
207
  return fakerKeywordMapper.and(
212
- current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
208
+ current.args.map((it) => parse({ schema, parent: current, current: it, siblings }, { ...options, canOverride: false })).filter(Boolean),
213
209
  )
214
210
  }
215
211
 
216
212
  if (isKeyword(current, schemaKeywords.array)) {
217
213
  return fakerKeywordMapper.array(
218
214
  current.args.items
219
- .map((schema) =>
215
+ .map((it) =>
220
216
  parse(
221
- { parent: current, current: schema, siblings },
217
+ { schema, parent: current, current: it, siblings },
222
218
  {
223
219
  ...options,
224
220
  typeName: `NonNullable<${options.typeName}>[number]`,
@@ -295,9 +291,9 @@ export function parse({ current, parent, name, siblings }: SchemaTree, options:
295
291
  return `"${name}": ${joinItems(
296
292
  schemas
297
293
  .sort(schemaKeywordSorter)
298
- .map((schema) =>
294
+ .map((it) =>
299
295
  parse(
300
- { name, parent: current, current: schema, siblings: schemas },
296
+ { schema, name, parent: current, current: it, siblings: schemas },
301
297
  {
302
298
  ...options,
303
299
  typeName: `NonNullable<${options.typeName}>[${JSON.stringify(name)}]`,
@@ -316,11 +312,11 @@ export function parse({ current, parent, name, siblings }: SchemaTree, options:
316
312
  if (isKeyword(current, schemaKeywords.tuple)) {
317
313
  if (Array.isArray(current.args.items)) {
318
314
  return fakerKeywordMapper.tuple(
319
- current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
315
+ current.args.items.map((it) => parse({ schema, parent: current, current: it, siblings }, { ...options, canOverride: false })).filter(Boolean),
320
316
  )
321
317
  }
322
318
 
323
- return parse({ parent: current, current: current.args.items, siblings }, { ...options, canOverride: false })
319
+ return parse({ schema, parent: current, current: current.args.items, siblings }, { ...options, canOverride: false })
324
320
  }
325
321
 
326
322
  if (isKeyword(current, schemaKeywords.const)) {
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
 
3
3
  import type { contentType, Oas, SchemaObject } from '@kubb/oas'
4
- import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
4
+ import type { Exclude, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
5
+ import type { Generator } from '@kubb/plugin-oas/generators'
5
6
 
6
7
  export type Options = {
7
8
  /**