@kubb/plugin-zod 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/{components-DUJ6Xkpc.js → components-BtBB23cQ.js} +85 -75
- package/dist/components-BtBB23cQ.js.map +1 -0
- package/dist/{components-BiOh-7_I.cjs → components-DIUzzW4k.cjs} +82 -72
- package/dist/components-DIUzzW4k.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +3 -3
- package/dist/components.d.ts +3 -3
- package/dist/components.js +1 -1
- package/dist/{generators-B2hD7k6l.cjs → generators-BOldMlBb.cjs} +119 -123
- package/dist/generators-BOldMlBb.cjs.map +1 -0
- package/dist/{generators-CwEOtNXG.js → generators-DpdxKqO8.js} +120 -125
- package/dist/generators-DpdxKqO8.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 +12 -2
- 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 +11 -2
- package/dist/index.js.map +1 -1
- package/dist/{types-CS916VXJ.d.ts → types-CQSK_Scm.d.cts} +133 -139
- package/dist/{types-Cd7g28dR.d.cts → types-DcQBOr_-.d.ts} +133 -139
- package/package.json +10 -18
- package/src/components/Zod.tsx +7 -13
- package/src/generators/__snapshots__/createPet.ts +2 -2
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +2 -2
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput.ts +7 -9
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput_entire_.ts +7 -10
- package/src/generators/__snapshots__/createPet_wrapOutput.ts +7 -9
- package/src/generators/__snapshots__/discriminator.ts +20 -28
- package/src/generators/__snapshots__/getPets.ts +4 -4
- package/src/generators/__snapshots__/getPets_wrapOutput.ts +8 -10
- package/src/generators/__snapshots__/petArray.ts +1 -5
- package/src/generators/__snapshots__/queryAllDefaulted.ts +3 -3
- package/src/generators/__snapshots__/queryAllDefaulted_wrapOutput.ts +2 -2
- package/src/generators/__snapshots__/showPetById.ts +3 -3
- package/src/generators/__snapshots__/showPetById_wrapOutput.ts +8 -10
- package/src/generators/index.ts +1 -1
- package/src/generators/operationsGenerator.tsx +5 -5
- package/src/generators/zodGenerator.tsx +35 -25
- package/src/parser.ts +37 -36
- package/src/plugin.ts +15 -0
- package/dist/components-BiOh-7_I.cjs.map +0 -1
- package/dist/components-DUJ6Xkpc.js.map +0 -1
- package/dist/generators-B2hD7k6l.cjs.map +0 -1
- package/dist/generators-CwEOtNXG.js.map +0 -1
- package/dist/utils.cjs +0 -0
- package/dist/utils.d.cts +0 -28
- package/dist/utils.d.ts +0 -28
- package/dist/utils.js +0 -1
- package/src/utils/index.ts +0 -1
- /package/{src/utils → templates}/ToZod.ts +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
1
2
|
import * as OasTypes from "oas/types";
|
|
2
3
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
3
4
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -5,7 +6,6 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
6
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
7
|
import BaseOas from "oas";
|
|
7
8
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -556,54 +556,6 @@ type FileMetaBase = {
|
|
|
556
556
|
pluginKey?: Plugin['key'];
|
|
557
557
|
};
|
|
558
558
|
//#endregion
|
|
559
|
-
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
560
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
561
|
-
name: string;
|
|
562
|
-
type: 'core';
|
|
563
|
-
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
564
|
-
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
565
|
-
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
566
|
-
};
|
|
567
|
-
//#endregion
|
|
568
|
-
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
569
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
570
|
-
name: string;
|
|
571
|
-
type: 'react';
|
|
572
|
-
Operations: (props: OperationsProps<TOptions>) => KubbNode;
|
|
573
|
-
Operation: (props: OperationProps<TOptions>) => KubbNode;
|
|
574
|
-
Schema: (props: SchemaProps<TOptions>) => KubbNode;
|
|
575
|
-
};
|
|
576
|
-
//#endregion
|
|
577
|
-
//#region ../plugin-oas/src/OperationGenerator.d.ts
|
|
578
|
-
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
579
|
-
fabric: Fabric;
|
|
580
|
-
oas: Oas;
|
|
581
|
-
exclude: Array<Exclude$1> | undefined;
|
|
582
|
-
include: Array<Include> | undefined;
|
|
583
|
-
override: Array<Override<TOptions>> | undefined;
|
|
584
|
-
contentType: contentType | undefined;
|
|
585
|
-
pluginManager: PluginManager;
|
|
586
|
-
/**
|
|
587
|
-
* Current plugin
|
|
588
|
-
*/
|
|
589
|
-
plugin: Plugin<TPluginOptions>;
|
|
590
|
-
mode: KubbFile.Mode;
|
|
591
|
-
};
|
|
592
|
-
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
593
|
-
#private;
|
|
594
|
-
getSchemas(operation: Operation$1, {
|
|
595
|
-
resolveName
|
|
596
|
-
}?: {
|
|
597
|
-
resolveName?: (name: string) => string;
|
|
598
|
-
}): OperationSchemas;
|
|
599
|
-
getOperations(): Promise<Array<{
|
|
600
|
-
path: string;
|
|
601
|
-
method: HttpMethod;
|
|
602
|
-
operation: Operation$1;
|
|
603
|
-
}>>;
|
|
604
|
-
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
605
|
-
}
|
|
606
|
-
//#endregion
|
|
607
559
|
//#region ../plugin-oas/src/SchemaMapper.d.ts
|
|
608
560
|
type SchemaKeywordMapper = {
|
|
609
561
|
object: {
|
|
@@ -821,94 +773,6 @@ type Schema = {
|
|
|
821
773
|
keyword: string;
|
|
822
774
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
823
775
|
//#endregion
|
|
824
|
-
//#region ../plugin-oas/src/SchemaGenerator.d.ts
|
|
825
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
826
|
-
fabric: Fabric;
|
|
827
|
-
oas: Oas;
|
|
828
|
-
pluginManager: PluginManager;
|
|
829
|
-
/**
|
|
830
|
-
* Current plugin
|
|
831
|
-
*/
|
|
832
|
-
plugin: Plugin<TPluginOptions>;
|
|
833
|
-
mode: KubbFile.Mode;
|
|
834
|
-
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
835
|
-
override: Array<Override<TOptions>> | undefined;
|
|
836
|
-
contentType?: contentType;
|
|
837
|
-
output?: string;
|
|
838
|
-
};
|
|
839
|
-
type SchemaGeneratorOptions = {
|
|
840
|
-
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
841
|
-
unknownType: 'any' | 'unknown' | 'void';
|
|
842
|
-
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
843
|
-
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
844
|
-
enumSuffix?: string;
|
|
845
|
-
usedEnumNames?: Record<string, number>;
|
|
846
|
-
mapper?: Record<string, string>;
|
|
847
|
-
typed?: boolean;
|
|
848
|
-
transformers: {
|
|
849
|
-
/**
|
|
850
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
851
|
-
*/
|
|
852
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
853
|
-
/**
|
|
854
|
-
* Receive schema and name(propertName) and return FakerMeta array
|
|
855
|
-
* TODO TODO add docs
|
|
856
|
-
* @beta
|
|
857
|
-
*/
|
|
858
|
-
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
859
|
-
};
|
|
860
|
-
};
|
|
861
|
-
type SchemaProps$1 = {
|
|
862
|
-
schemaObject?: SchemaObject$1;
|
|
863
|
-
name?: string;
|
|
864
|
-
parentName?: string;
|
|
865
|
-
};
|
|
866
|
-
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
867
|
-
#private;
|
|
868
|
-
refs: Refs;
|
|
869
|
-
/**
|
|
870
|
-
* Creates a type node from a given schema.
|
|
871
|
-
* Delegates to getBaseTypeFromSchema internally and
|
|
872
|
-
* optionally adds a union with null.
|
|
873
|
-
*/
|
|
874
|
-
parse(props: SchemaProps$1): Schema[];
|
|
875
|
-
deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
876
|
-
find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
877
|
-
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
878
|
-
static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
879
|
-
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
880
|
-
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
881
|
-
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
882
|
-
}
|
|
883
|
-
//#endregion
|
|
884
|
-
//#region ../plugin-oas/src/generators/types.d.ts
|
|
885
|
-
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
886
|
-
/**
|
|
887
|
-
* @deprecated
|
|
888
|
-
*/
|
|
889
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
890
|
-
options: TOptions['resolvedOptions'];
|
|
891
|
-
operations: Array<Operation$1>;
|
|
892
|
-
};
|
|
893
|
-
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
894
|
-
/**
|
|
895
|
-
* @deprecated
|
|
896
|
-
*/
|
|
897
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
898
|
-
options: TOptions['resolvedOptions'];
|
|
899
|
-
operation: Operation$1;
|
|
900
|
-
};
|
|
901
|
-
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
902
|
-
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
903
|
-
options: TOptions['resolvedOptions'];
|
|
904
|
-
schema: {
|
|
905
|
-
name: string;
|
|
906
|
-
tree: Array<Schema>;
|
|
907
|
-
value: SchemaObject$1;
|
|
908
|
-
};
|
|
909
|
-
};
|
|
910
|
-
type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
|
|
911
|
-
//#endregion
|
|
912
776
|
//#region ../plugin-oas/src/types.d.ts
|
|
913
777
|
type ResolvePathOptions = {
|
|
914
778
|
pluginKey?: Plugin['key'];
|
|
@@ -997,6 +861,136 @@ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaN
|
|
|
997
861
|
options: Partial<TOptions>;
|
|
998
862
|
};
|
|
999
863
|
//#endregion
|
|
864
|
+
//#region ../plugin-oas/src/SchemaGenerator.d.ts
|
|
865
|
+
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
866
|
+
fabric: Fabric;
|
|
867
|
+
oas: Oas;
|
|
868
|
+
pluginManager: PluginManager;
|
|
869
|
+
/**
|
|
870
|
+
* Current plugin
|
|
871
|
+
*/
|
|
872
|
+
plugin: Plugin<TPluginOptions>;
|
|
873
|
+
mode: KubbFile.Mode;
|
|
874
|
+
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
875
|
+
override: Array<Override<TOptions>> | undefined;
|
|
876
|
+
contentType?: contentType;
|
|
877
|
+
output?: string;
|
|
878
|
+
};
|
|
879
|
+
type SchemaGeneratorOptions = {
|
|
880
|
+
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
881
|
+
unknownType: 'any' | 'unknown' | 'void';
|
|
882
|
+
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
883
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
884
|
+
enumSuffix?: string;
|
|
885
|
+
usedEnumNames?: Record<string, number>;
|
|
886
|
+
mapper?: Record<string, string>;
|
|
887
|
+
typed?: boolean;
|
|
888
|
+
transformers: {
|
|
889
|
+
/**
|
|
890
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
891
|
+
*/
|
|
892
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
893
|
+
/**
|
|
894
|
+
* Receive schema and name(propertName) and return FakerMeta array
|
|
895
|
+
* TODO TODO add docs
|
|
896
|
+
* @beta
|
|
897
|
+
*/
|
|
898
|
+
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
899
|
+
};
|
|
900
|
+
};
|
|
901
|
+
type SchemaProps$1 = {
|
|
902
|
+
schemaObject?: SchemaObject$1;
|
|
903
|
+
name?: string;
|
|
904
|
+
parentName?: string;
|
|
905
|
+
};
|
|
906
|
+
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
|
|
907
|
+
#private;
|
|
908
|
+
refs: Refs;
|
|
909
|
+
/**
|
|
910
|
+
* Creates a type node from a given schema.
|
|
911
|
+
* Delegates to getBaseTypeFromSchema internally and
|
|
912
|
+
* optionally adds a union with null.
|
|
913
|
+
*/
|
|
914
|
+
parse(props: SchemaProps$1): Schema[];
|
|
915
|
+
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
916
|
+
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
917
|
+
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
918
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
919
|
+
}
|
|
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
|
/**
|
|
@@ -1123,5 +1117,5 @@ type ResolvedOptions = {
|
|
|
1123
1117
|
};
|
|
1124
1118
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1125
1119
|
//#endregion
|
|
1126
|
-
export { UserPluginWithLifeCycle as a,
|
|
1127
|
-
//# sourceMappingURL=types-
|
|
1120
|
+
export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options$1 as t };
|
|
1121
|
+
//# sourceMappingURL=types-DcQBOr_-.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "Zod schema generator plugin for Kubb, creating type-safe validation schemas from OpenAPI specifications for runtime data validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -37,10 +37,7 @@
|
|
|
37
37
|
"import": "./dist/generators.js",
|
|
38
38
|
"require": "./dist/generators.cjs"
|
|
39
39
|
},
|
|
40
|
-
"./
|
|
41
|
-
"import": "./dist/utils.js",
|
|
42
|
-
"require": "./dist/utils.cjs"
|
|
43
|
-
},
|
|
40
|
+
"./templates/*": "./templates/*",
|
|
44
41
|
"./package.json": "./package.json"
|
|
45
42
|
},
|
|
46
43
|
"main": "./dist/index.cjs",
|
|
@@ -53,17 +50,12 @@
|
|
|
53
50
|
],
|
|
54
51
|
"generators": [
|
|
55
52
|
"./dist/generators.d.ts"
|
|
56
|
-
],
|
|
57
|
-
"utils": [
|
|
58
|
-
"./dist/utils.d.ts"
|
|
59
|
-
],
|
|
60
|
-
"utils/v4": [
|
|
61
|
-
"./dist/utils/v4.d.ts"
|
|
62
53
|
]
|
|
63
54
|
}
|
|
64
55
|
},
|
|
65
56
|
"files": [
|
|
66
57
|
"src",
|
|
58
|
+
"templates",
|
|
67
59
|
"dist",
|
|
68
60
|
"!/**/**.test.**",
|
|
69
61
|
"!/**/__tests__/**"
|
|
@@ -76,20 +68,20 @@
|
|
|
76
68
|
}
|
|
77
69
|
],
|
|
78
70
|
"dependencies": {
|
|
79
|
-
"@kubb/react-fabric": "0.2.
|
|
80
|
-
"@kubb/core": "4.
|
|
81
|
-
"@kubb/oas": "4.
|
|
82
|
-
"@kubb/plugin-oas": "4.
|
|
83
|
-
"@kubb/plugin-ts": "4.
|
|
71
|
+
"@kubb/react-fabric": "0.2.14",
|
|
72
|
+
"@kubb/core": "4.5.1",
|
|
73
|
+
"@kubb/oas": "4.5.1",
|
|
74
|
+
"@kubb/plugin-oas": "4.5.1",
|
|
75
|
+
"@kubb/plugin-ts": "4.5.1"
|
|
84
76
|
},
|
|
85
77
|
"devDependencies": {
|
|
86
78
|
"@asteasolutions/zod-to-openapi": "^8.1.0",
|
|
87
79
|
"@hono/zod-openapi": "0.19.2",
|
|
88
80
|
"zod": "^3.25.76",
|
|
89
|
-
"@kubb/plugin-oas": "4.
|
|
81
|
+
"@kubb/plugin-oas": "4.5.1"
|
|
90
82
|
},
|
|
91
83
|
"peerDependencies": {
|
|
92
|
-
"@kubb/react-fabric": "0.2.
|
|
84
|
+
"@kubb/react-fabric": "0.2.14"
|
|
93
85
|
},
|
|
94
86
|
"engines": {
|
|
95
87
|
"node": ">=20"
|
package/src/components/Zod.tsx
CHANGED
|
@@ -11,7 +11,7 @@ type Props = {
|
|
|
11
11
|
typeName?: string
|
|
12
12
|
inferTypeName?: string
|
|
13
13
|
tree: Array<Schema>
|
|
14
|
-
|
|
14
|
+
schema: SchemaObject
|
|
15
15
|
description?: string
|
|
16
16
|
coercion: PluginZod['resolvedOptions']['coercion']
|
|
17
17
|
mapper: PluginZod['resolvedOptions']['mapper']
|
|
@@ -25,7 +25,7 @@ export function Zod({
|
|
|
25
25
|
name,
|
|
26
26
|
typeName,
|
|
27
27
|
tree,
|
|
28
|
-
|
|
28
|
+
schema,
|
|
29
29
|
inferTypeName,
|
|
30
30
|
mapper,
|
|
31
31
|
coercion,
|
|
@@ -35,7 +35,7 @@ export function Zod({
|
|
|
35
35
|
version,
|
|
36
36
|
emptySchemaType,
|
|
37
37
|
}: Props): KubbNode {
|
|
38
|
-
const hasTuple = !!SchemaGenerator.
|
|
38
|
+
const hasTuple = !!SchemaGenerator.find(tree, schemaKeywords.tuple)
|
|
39
39
|
|
|
40
40
|
const schemas = parserZod.sort(tree).filter((item) => {
|
|
41
41
|
if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
|
|
@@ -49,10 +49,7 @@ export function Zod({
|
|
|
49
49
|
.map((schema, index) => {
|
|
50
50
|
const siblings = schemas.filter((_, i) => i !== index)
|
|
51
51
|
|
|
52
|
-
return parserZod.parse(
|
|
53
|
-
{ parent: undefined, current: schema, siblings },
|
|
54
|
-
{ name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version },
|
|
55
|
-
)
|
|
52
|
+
return parserZod.parse({ schema, parent: undefined, current: schema, siblings, name }, { mapper, coercion, wrapOutput, version })
|
|
56
53
|
})
|
|
57
54
|
.filter(Boolean)
|
|
58
55
|
.join('')
|
|
@@ -71,28 +68,25 @@ export function Zod({
|
|
|
71
68
|
} else {
|
|
72
69
|
suffix = '.unwrap()'
|
|
73
70
|
}
|
|
74
|
-
} else {
|
|
75
|
-
if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref) && version === '3') {
|
|
76
|
-
suffix = '.schema'
|
|
77
|
-
}
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
const emptyValue = parserZod.parse(
|
|
81
74
|
{
|
|
75
|
+
schema,
|
|
82
76
|
parent: undefined,
|
|
83
77
|
current: {
|
|
84
78
|
keyword: schemaKeywords[emptySchemaType],
|
|
85
79
|
},
|
|
86
80
|
siblings: [],
|
|
87
81
|
},
|
|
88
|
-
{
|
|
82
|
+
{ mapper, coercion, wrapOutput, version },
|
|
89
83
|
)
|
|
90
84
|
|
|
91
85
|
const baseSchemaOutput =
|
|
92
86
|
[output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `'${key}': true`).join(',')} })` : undefined].filter(Boolean).join('') ||
|
|
93
87
|
emptyValue ||
|
|
94
88
|
''
|
|
95
|
-
const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema
|
|
89
|
+
const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema }) || baseSchemaOutput : baseSchemaOutput
|
|
96
90
|
const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ${version === '4' ? 'z.ZodType' : 'ToZod'}<${typeName}>` : wrappedSchemaOutput
|
|
97
91
|
|
|
98
92
|
return (
|
|
@@ -12,11 +12,11 @@ export const createPets201 = z.unknown()
|
|
|
12
12
|
/**
|
|
13
13
|
* @description unexpected error
|
|
14
14
|
*/
|
|
15
|
-
export const createPetsError =
|
|
15
|
+
export const createPetsError = error
|
|
16
16
|
|
|
17
17
|
export const createPetsMutationRequest = z.object({
|
|
18
18
|
name: z.string(),
|
|
19
19
|
tag: z.string(),
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
export const createPetsMutationResponse =
|
|
22
|
+
export const createPetsMutationResponse = createPets201
|
|
@@ -12,11 +12,11 @@ export const createPets201 = z.unknown()
|
|
|
12
12
|
/**
|
|
13
13
|
* @description unexpected error
|
|
14
14
|
*/
|
|
15
|
-
export const createPetsError =
|
|
15
|
+
export const createPetsError = error
|
|
16
16
|
|
|
17
17
|
export const createPetsMutationRequest = z.object({
|
|
18
18
|
name: z.string(),
|
|
19
19
|
tag: z.string(),
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
export const createPetsMutationResponse =
|
|
22
|
+
export const createPetsMutationResponse = createPets201
|
|
@@ -12,18 +12,16 @@ export const createPets201 = z.unknown()
|
|
|
12
12
|
/**
|
|
13
13
|
* @description unexpected error
|
|
14
14
|
*/
|
|
15
|
-
export const createPetsError =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
})
|
|
15
|
+
export const createPetsError = error.openapi({
|
|
16
|
+
examples: [
|
|
17
|
+
{ sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
|
|
18
|
+
{ other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
|
|
19
|
+
],
|
|
20
|
+
})
|
|
23
21
|
|
|
24
22
|
export const createPetsMutationRequest = z.object({
|
|
25
23
|
name: z.string().openapi({ example: 'Baxter' }),
|
|
26
24
|
tag: z.string(),
|
|
27
25
|
})
|
|
28
26
|
|
|
29
|
-
export const createPetsMutationResponse =
|
|
27
|
+
export const createPetsMutationResponse = createPets201
|
|
@@ -12,19 +12,16 @@ export const createPets201 = z.unknown()
|
|
|
12
12
|
/**
|
|
13
13
|
* @description unexpected error
|
|
14
14
|
*/
|
|
15
|
-
export const createPetsError = extendApi(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
)
|
|
15
|
+
export const createPetsError = extendApi(error, {
|
|
16
|
+
examples: [
|
|
17
|
+
{ sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
|
|
18
|
+
{ other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
|
|
19
|
+
],
|
|
20
|
+
})
|
|
24
21
|
|
|
25
22
|
export const createPetsMutationRequest = z.object({
|
|
26
23
|
name: extendApi(z.string(), { example: 'Baxter' }),
|
|
27
24
|
tag: z.string(),
|
|
28
25
|
})
|
|
29
26
|
|
|
30
|
-
export const createPetsMutationResponse =
|
|
27
|
+
export const createPetsMutationResponse = createPets201
|
|
@@ -12,18 +12,16 @@ export const createPets201 = z.unknown()
|
|
|
12
12
|
/**
|
|
13
13
|
* @description unexpected error
|
|
14
14
|
*/
|
|
15
|
-
export const createPetsError =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
})
|
|
15
|
+
export const createPetsError = error.openapi({
|
|
16
|
+
examples: [
|
|
17
|
+
{ sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
|
|
18
|
+
{ other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
|
|
19
|
+
],
|
|
20
|
+
})
|
|
23
21
|
|
|
24
22
|
export const createPetsMutationRequest = z.object({
|
|
25
23
|
name: z.string().openapi({ example: 'Baxter' }),
|
|
26
24
|
tag: z.string(),
|
|
27
25
|
})
|
|
28
26
|
|
|
29
|
-
export const createPetsMutationResponse =
|
|
27
|
+
export const createPetsMutationResponse = createPets201
|
|
@@ -5,32 +5,24 @@
|
|
|
5
5
|
import { z } from 'zod'
|
|
6
6
|
|
|
7
7
|
export const advanced = z.union([
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
z.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
),
|
|
29
|
-
z
|
|
30
|
-
.lazy(() => sliderValueSpecificationDto)
|
|
31
|
-
.and(
|
|
32
|
-
z.object({
|
|
33
|
-
type: z.literal('slider'),
|
|
34
|
-
}),
|
|
35
|
-
),
|
|
8
|
+
enumerationValueSpecificationDto.and(
|
|
9
|
+
z.object({
|
|
10
|
+
type: z.literal('enum'),
|
|
11
|
+
}),
|
|
12
|
+
),
|
|
13
|
+
rangeValueSpecificationDto.and(
|
|
14
|
+
z.object({
|
|
15
|
+
type: z.literal('range'),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
regexValueSpecificationDto.and(
|
|
19
|
+
z.object({
|
|
20
|
+
type: z.literal('regex'),
|
|
21
|
+
}),
|
|
22
|
+
),
|
|
23
|
+
sliderValueSpecificationDto.and(
|
|
24
|
+
z.object({
|
|
25
|
+
type: z.literal('slider'),
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
36
28
|
])
|
|
@@ -6,17 +6,17 @@ import { z } from 'zod'
|
|
|
6
6
|
|
|
7
7
|
export const listPetsQueryParams = z.object({
|
|
8
8
|
limit: z.optional(z.string().describe('How many items to return at one time (max 100)')),
|
|
9
|
-
offset: z.
|
|
9
|
+
offset: z.coerce.number().int().default(0),
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @description A paged array of pets
|
|
14
14
|
*/
|
|
15
|
-
export const listPets200 =
|
|
15
|
+
export const listPets200 = pets
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @description unexpected error
|
|
19
19
|
*/
|
|
20
|
-
export const listPetsError =
|
|
20
|
+
export const listPetsError = error
|
|
21
21
|
|
|
22
|
-
export const listPetsQueryResponse =
|
|
22
|
+
export const listPetsQueryResponse = listPets200
|
|
@@ -12,18 +12,16 @@ export const listPetsQueryParams = z.object({
|
|
|
12
12
|
/**
|
|
13
13
|
* @description A paged array of pets
|
|
14
14
|
*/
|
|
15
|
-
export const listPets200 =
|
|
15
|
+
export const listPets200 = pets
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @description unexpected error
|
|
19
19
|
*/
|
|
20
|
-
export const listPetsError =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
],
|
|
27
|
-
})
|
|
20
|
+
export const listPetsError = error.openapi({
|
|
21
|
+
examples: [
|
|
22
|
+
{ sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
|
|
23
|
+
{ other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
28
26
|
|
|
29
|
-
export const listPetsQueryResponse =
|
|
27
|
+
export const listPetsQueryResponse = listPets200
|
|
@@ -7,8 +7,4 @@ import { z } from 'zod'
|
|
|
7
7
|
/**
|
|
8
8
|
* @description List of Pet object
|
|
9
9
|
*/
|
|
10
|
-
export const petArray = z
|
|
11
|
-
.array(z.lazy(() => pet))
|
|
12
|
-
.min(1)
|
|
13
|
-
.max(3)
|
|
14
|
-
.describe('List of Pet object')
|
|
10
|
+
export const petArray = z.array(pet).min(1).max(3).describe('List of Pet object')
|