@kubb/plugin-client 4.4.1 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Operations-CmHRmAdn.js → Operations-HWuo-D3O.js} +2 -2
- package/dist/{Operations-CmHRmAdn.js.map → Operations-HWuo-D3O.js.map} +1 -1
- package/dist/{Operations-DXjVfmrY.cjs → Operations-b9-WgfsC.cjs} +36 -8
- package/dist/{Operations-DXjVfmrY.cjs.map → Operations-b9-WgfsC.cjs.map} +1 -1
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-C_ySk_ES.cjs → generators-BZihoaAC.cjs} +69 -60
- package/dist/generators-BZihoaAC.cjs.map +1 -0
- package/dist/{generators-0Sc5zPfx.js → generators-CQvDx6Mq.js} +60 -51
- package/dist/generators-CQvDx6Mq.js.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +4 -4
- package/dist/generators.d.ts +4 -4
- package/dist/generators.js +2 -2
- package/dist/index.cjs +20 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-DJmtgGu4.d.ts → types-BI2oGQis.d.ts} +172 -178
- package/dist/{types-DuPfvza5.d.cts → types-DQTXVaz_.d.cts} +172 -178
- package/package.json +12 -23
- package/src/generators/clientGenerator.tsx +25 -7
- package/src/generators/groupedClientGenerator.tsx +5 -5
- package/src/generators/index.ts +1 -1
- package/src/generators/operationsGenerator.tsx +4 -4
- package/src/plugin.ts +21 -1
- package/src/types.ts +6 -5
- package/{src → templates}/clients/axios.ts +1 -2
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/clients/axios.cjs +0 -40
- package/dist/clients/axios.cjs.map +0 -1
- package/dist/clients/axios.d.cts +0 -39
- package/dist/clients/axios.d.ts +0 -39
- package/dist/clients/axios.js +0 -33
- package/dist/clients/axios.js.map +0 -1
- package/dist/clients/fetch.cjs +0 -48
- package/dist/clients/fetch.cjs.map +0 -1
- package/dist/clients/fetch.d.cts +0 -39
- package/dist/clients/fetch.d.ts +0 -39
- package/dist/clients/fetch.js +0 -43
- package/dist/clients/fetch.js.map +0 -1
- package/dist/generators-0Sc5zPfx.js.map +0 -1
- package/dist/generators-C_ySk_ES.cjs.map +0 -1
- /package/{src → templates}/clients/fetch.ts +0 -0
|
@@ -556,170 +556,6 @@ type FileMetaBase = {
|
|
|
556
556
|
pluginKey?: Plugin['key'];
|
|
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
|
/**
|
|
@@ -1041,7 +1035,6 @@ type Options$1 = {
|
|
|
1041
1035
|
* Path to the client import path that will be used to do the API calls.
|
|
1042
1036
|
* It will be used as `import client from '${client.importPath}'`.
|
|
1043
1037
|
* It allows both relative and absolute path but be aware that we will not change the path.
|
|
1044
|
-
* @default '@kubb/plugin-client/clients/axios'
|
|
1045
1038
|
*/
|
|
1046
1039
|
importPath?: string;
|
|
1047
1040
|
/**
|
|
@@ -1082,8 +1075,8 @@ type Options$1 = {
|
|
|
1082
1075
|
parser?: 'client' | 'zod';
|
|
1083
1076
|
/**
|
|
1084
1077
|
* Which client should be used to do the HTTP calls
|
|
1085
|
-
* - 'axios' will use `@kubb/plugin-client/
|
|
1086
|
-
* - 'fetch' will use `@kubb/plugin-client/
|
|
1078
|
+
* - 'axios' will use `@kubb/plugin-client/templates/axios` to fetch data.
|
|
1079
|
+
* - 'fetch' will use `@kubb/plugin-client/templates/fetch` to fetch data.
|
|
1087
1080
|
* @default 'axios'
|
|
1088
1081
|
*/
|
|
1089
1082
|
client?: 'axios' | 'fetch';
|
|
@@ -1102,9 +1095,10 @@ type ResolvedOptions = {
|
|
|
1102
1095
|
output: Output<Oas>;
|
|
1103
1096
|
group?: Options$1['group'];
|
|
1104
1097
|
baseURL: string | undefined;
|
|
1098
|
+
client: Options$1['client'];
|
|
1105
1099
|
parser: NonNullable<Options$1['parser']>;
|
|
1106
1100
|
urlType: NonNullable<Options$1['urlType']>;
|
|
1107
|
-
importPath:
|
|
1101
|
+
importPath: Options$1['importPath'];
|
|
1108
1102
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
1109
1103
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
1110
1104
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
@@ -1112,5 +1106,5 @@ type ResolvedOptions = {
|
|
|
1112
1106
|
};
|
|
1113
1107
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1114
1108
|
//#endregion
|
|
1115
|
-
export { UserPluginWithLifeCycle as a,
|
|
1116
|
-
//# sourceMappingURL=types-
|
|
1109
|
+
export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options$1 as t };
|
|
1110
|
+
//# sourceMappingURL=types-DQTXVaz_.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -31,14 +31,6 @@
|
|
|
31
31
|
"import": "./dist/index.js",
|
|
32
32
|
"require": "./dist/index.cjs"
|
|
33
33
|
},
|
|
34
|
-
"./clients/axios": {
|
|
35
|
-
"import": "./dist/clients/axios.js",
|
|
36
|
-
"require": "./dist/clients/axios.cjs"
|
|
37
|
-
},
|
|
38
|
-
"./clients/fetch": {
|
|
39
|
-
"import": "./dist/clients/fetch.js",
|
|
40
|
-
"require": "./dist/clients/fetch.cjs"
|
|
41
|
-
},
|
|
42
34
|
"./components": {
|
|
43
35
|
"import": "./dist/components.js",
|
|
44
36
|
"require": "./dist/components.cjs"
|
|
@@ -47,6 +39,7 @@
|
|
|
47
39
|
"import": "./dist/generators.js",
|
|
48
40
|
"require": "./dist/generators.cjs"
|
|
49
41
|
},
|
|
42
|
+
"./templates/*": "./templates/*",
|
|
50
43
|
"./package.json": "./package.json"
|
|
51
44
|
},
|
|
52
45
|
"main": "./dist/index.cjs",
|
|
@@ -59,18 +52,13 @@
|
|
|
59
52
|
],
|
|
60
53
|
"generators": [
|
|
61
54
|
"./dist/generators.d.ts"
|
|
62
|
-
],
|
|
63
|
-
"clients/axios": [
|
|
64
|
-
"./dist/clients/axios.d.ts"
|
|
65
|
-
],
|
|
66
|
-
"clients/fetch": [
|
|
67
|
-
"./dist/clients/fetch.d.ts"
|
|
68
55
|
]
|
|
69
56
|
}
|
|
70
57
|
},
|
|
71
58
|
"files": [
|
|
72
59
|
"src",
|
|
73
60
|
"dist",
|
|
61
|
+
"templates",
|
|
74
62
|
"*.d.ts",
|
|
75
63
|
"*.d.cts",
|
|
76
64
|
"!/**/**.test.**",
|
|
@@ -84,18 +72,19 @@
|
|
|
84
72
|
}
|
|
85
73
|
],
|
|
86
74
|
"dependencies": {
|
|
87
|
-
"@kubb/react-fabric": "0.2.
|
|
88
|
-
"
|
|
89
|
-
"@kubb/
|
|
90
|
-
"@kubb/
|
|
91
|
-
"@kubb/plugin-
|
|
92
|
-
"@kubb/plugin-
|
|
75
|
+
"@kubb/react-fabric": "0.2.14",
|
|
76
|
+
"jiti": "^2.6.1",
|
|
77
|
+
"@kubb/core": "4.5.1",
|
|
78
|
+
"@kubb/oas": "4.5.1",
|
|
79
|
+
"@kubb/plugin-oas": "4.5.1",
|
|
80
|
+
"@kubb/plugin-ts": "4.5.1",
|
|
81
|
+
"@kubb/plugin-zod": "4.5.1"
|
|
93
82
|
},
|
|
94
83
|
"devDependencies": {
|
|
95
|
-
"axios": "^1.13.
|
|
84
|
+
"axios": "^1.13.1"
|
|
96
85
|
},
|
|
97
86
|
"peerDependencies": {
|
|
98
|
-
"@kubb/react-fabric": "0.2.
|
|
87
|
+
"@kubb/react-fabric": "0.2.14",
|
|
99
88
|
"axios": "^1.7.2"
|
|
100
89
|
},
|
|
101
90
|
"peerDependenciesMeta": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { usePluginManager } from '@kubb/core/hooks'
|
|
3
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
4
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
5
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -11,13 +12,15 @@ import type { PluginClient } from '../types'
|
|
|
11
12
|
|
|
12
13
|
export const clientGenerator = createReactGenerator<PluginClient>({
|
|
13
14
|
name: 'client',
|
|
14
|
-
Operation({
|
|
15
|
+
Operation({ config, plugin, operation, generator }) {
|
|
15
16
|
const pluginManager = usePluginManager()
|
|
16
17
|
const {
|
|
18
|
+
options,
|
|
17
19
|
options: { output, urlType },
|
|
18
|
-
} =
|
|
20
|
+
} = plugin
|
|
21
|
+
|
|
19
22
|
const oas = useOas()
|
|
20
|
-
const { getSchemas, getName, getFile } = useOperationManager()
|
|
23
|
+
const { getSchemas, getName, getFile } = useOperationManager(generator)
|
|
21
24
|
|
|
22
25
|
const client = {
|
|
23
26
|
name: getName(operation, { type: 'function' }),
|
|
@@ -47,8 +50,23 @@ export const clientGenerator = createReactGenerator<PluginClient>({
|
|
|
47
50
|
banner={getBanner({ oas, output, config: pluginManager.config })}
|
|
48
51
|
footer={getFooter({ oas, output })}
|
|
49
52
|
>
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
{options.importPath ? (
|
|
54
|
+
<>
|
|
55
|
+
<File.Import name={'fetch'} path={options.importPath} />
|
|
56
|
+
<File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />
|
|
57
|
+
</>
|
|
58
|
+
) : (
|
|
59
|
+
<>
|
|
60
|
+
<File.Import name={'fetch'} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} />
|
|
61
|
+
<File.Import
|
|
62
|
+
name={['RequestConfig', 'ResponseErrorConfig']}
|
|
63
|
+
root={client.file.path}
|
|
64
|
+
path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')}
|
|
65
|
+
isTypeOnly
|
|
66
|
+
/>
|
|
67
|
+
</>
|
|
68
|
+
)}
|
|
69
|
+
|
|
52
70
|
{options.parser === 'zod' && (
|
|
53
71
|
<File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={client.file.path} path={zod.file.path} />
|
|
54
72
|
)}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePluginManager } from '@kubb/core/hooks'
|
|
2
2
|
import { camelCase } from '@kubb/core/transformers'
|
|
3
3
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
-
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
4
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
5
5
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
6
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
7
7
|
import { File, Function } from '@kubb/react-fabric'
|
|
@@ -9,12 +9,12 @@ import type { PluginClient } from '../types'
|
|
|
9
9
|
|
|
10
10
|
export const groupedClientGenerator = createReactGenerator<PluginClient>({
|
|
11
11
|
name: 'groupedClient',
|
|
12
|
-
Operations({ operations }) {
|
|
13
|
-
const { options, key: pluginKey } =
|
|
12
|
+
Operations({ operations, generator, plugin }) {
|
|
13
|
+
const { options, key: pluginKey } = plugin
|
|
14
14
|
const pluginManager = usePluginManager()
|
|
15
15
|
|
|
16
16
|
const oas = useOas()
|
|
17
|
-
const { getName, getFile, getGroup } = useOperationManager()
|
|
17
|
+
const { getName, getFile, getGroup } = useOperationManager(generator)
|
|
18
18
|
|
|
19
19
|
const controllers = operations.reduce(
|
|
20
20
|
(acc, operation) => {
|
package/src/generators/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
1
|
+
import { usePluginManager } from '@kubb/core/hooks'
|
|
2
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
3
|
import { useOas } from '@kubb/plugin-oas/hooks'
|
|
4
4
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
5
|
import { File } from '@kubb/react-fabric'
|
|
@@ -8,11 +8,11 @@ import type { PluginClient } from '../types'
|
|
|
8
8
|
|
|
9
9
|
export const operationsGenerator = createReactGenerator<PluginClient>({
|
|
10
10
|
name: 'client',
|
|
11
|
-
Operations({ operations }) {
|
|
11
|
+
Operations({ operations, plugin }) {
|
|
12
12
|
const {
|
|
13
13
|
key: pluginKey,
|
|
14
14
|
options: { output },
|
|
15
|
-
} =
|
|
15
|
+
} = plugin
|
|
16
16
|
const pluginManager = usePluginManager()
|
|
17
17
|
|
|
18
18
|
const oas = useOas()
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'
|
|
3
3
|
import { camelCase } from '@kubb/core/transformers'
|
|
4
|
+
import { resolveModuleSource } from '@kubb/core/utils'
|
|
4
5
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
5
6
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
6
7
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
@@ -29,13 +30,14 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
29
30
|
generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),
|
|
30
31
|
parser = 'client',
|
|
31
32
|
client = 'axios',
|
|
32
|
-
importPath
|
|
33
|
+
importPath,
|
|
33
34
|
contentType,
|
|
34
35
|
} = options
|
|
35
36
|
|
|
36
37
|
return {
|
|
37
38
|
name: pluginClientName,
|
|
38
39
|
options: {
|
|
40
|
+
client,
|
|
39
41
|
output,
|
|
40
42
|
group,
|
|
41
43
|
parser,
|
|
@@ -99,6 +101,24 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
99
101
|
const mode = getMode(path.resolve(root, output.path))
|
|
100
102
|
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
101
103
|
|
|
104
|
+
// pre add bundled fetcher
|
|
105
|
+
const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')
|
|
106
|
+
|
|
107
|
+
if (!this.plugin.options.importPath && !containsFetcher) {
|
|
108
|
+
await this.addFile({
|
|
109
|
+
baseName: 'fetcher.ts',
|
|
110
|
+
path: path.resolve(root, '.kubb/fetcher.ts'),
|
|
111
|
+
sources: [
|
|
112
|
+
{
|
|
113
|
+
name: 'fetcher',
|
|
114
|
+
value: resolveModuleSource(
|
|
115
|
+
this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',
|
|
116
|
+
).source,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
102
122
|
const operationGenerator = new OperationGenerator(
|
|
103
123
|
baseURL
|
|
104
124
|
? {
|