@kubb/plugin-zod 4.18.3 → 4.18.5
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.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/{generators-BP4elkVx.js → generators-BIWiaBYS.js} +11 -2
- package/dist/generators-BIWiaBYS.js.map +1 -0
- package/dist/{generators-CCbjEMCj.cjs → generators-boBB_r4u.cjs} +11 -2
- package/dist/generators-boBB_r4u.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{types-B5e4IaUY.d.cts → types-CM-i8-E1.d.cts} +75 -59
- package/dist/{types-BNtlNlKK.d.ts → types-CaZySLsa.d.ts} +75 -59
- package/package.json +7 -7
- package/src/generators/__snapshots__/createItemUnionWithReadOnly.ts +34 -0
- package/src/generators/__snapshots__/createItemUnionWithReadOnly_wrapOutput.ts +34 -0
- package/src/generators/__snapshots__/unionWithReadOnly.ts +28 -0
- package/src/generators/__snapshots__/updateItemUnionWithReadOnly.ts +34 -0
- package/src/generators/__snapshots__/updateItemUnionWithReadOnly_wrapOutput.ts +34 -0
- package/src/generators/zodGenerator.tsx +21 -1
- package/src/types.ts +26 -13
- package/templates/ToZod.ts +14 -14
- package/dist/generators-BP4elkVx.js.map +0 -1
- package/dist/generators-CCbjEMCj.cjs.map +0 -1
package/dist/components.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as __name, i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-
|
|
1
|
+
import { c as __name, i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-CM-i8-E1.cjs";
|
|
2
2
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
package/dist/components.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-eQyhnF5A.js";
|
|
2
|
-
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-
|
|
2
|
+
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-CaZySLsa.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
5
5
|
|
|
@@ -99,7 +99,16 @@ const zodGenerator = createReactGenerator({
|
|
|
99
99
|
schemas.request,
|
|
100
100
|
schemas.response
|
|
101
101
|
].flat().filter(Boolean);
|
|
102
|
-
const mapOperationSchema = ({ name, schema:
|
|
102
|
+
const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options$1 }) => {
|
|
103
|
+
let schemaObject = schemaOriginal;
|
|
104
|
+
let keysToOmit = keysToOmitOriginal;
|
|
105
|
+
if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
|
|
106
|
+
schemaObject = structuredClone(schemaOriginal);
|
|
107
|
+
delete schemaObject.$ref;
|
|
108
|
+
for (const key of keysToOmitOriginal) delete schemaObject.properties?.[key];
|
|
109
|
+
if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key));
|
|
110
|
+
keysToOmit = void 0;
|
|
111
|
+
}
|
|
103
112
|
const hasProperties = Object.keys(schemaObject || {}).length > 0;
|
|
104
113
|
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
|
|
105
114
|
const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
|
|
@@ -265,4 +274,4 @@ const zodGenerator = createReactGenerator({
|
|
|
265
274
|
|
|
266
275
|
//#endregion
|
|
267
276
|
export { operationsGenerator as n, zodGenerator as t };
|
|
268
|
-
//# sourceMappingURL=generators-
|
|
277
|
+
//# sourceMappingURL=generators-BIWiaBYS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BIWiaBYS.js","names":["options"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, mini },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n events: generator.context.events,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {\n let schemaObject = schemaOriginal\n let keysToOmit = keysToOmitOriginal\n\n if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {\n schemaObject = structuredClone(schemaOriginal)\n\n // Remove $ref so the schema parser generates inline schema instead of a reference\n delete schemaObject.$ref\n\n for (const key of keysToOmitOriginal) {\n delete schemaObject.properties?.[key]\n }\n\n if (Array.isArray(schemaObject.required)) {\n schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))\n }\n\n keysToOmit = undefined\n }\n\n const hasProperties = Object.keys(schemaObject || {}).length > 0\n const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))\n\n const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required\n const optional = !required && !hasDefaults && hasProperties && name.includes('Params')\n\n if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {\n schemaObject.required = Object.entries(schemaObject.properties || {})\n .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))\n .map(([key]) => key)\n }\n\n const tree = [\n ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),\n optional ? { keyword: schemaKeywords.optional } : undefined,\n ].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </Fragment>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, mini },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,gBAAgB,kBAAkB;EAExC,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IAAI,KAAK;GACf,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;;IAElC,oBAAC,KAAK;KAAO,MAAM,CAAC,IAAI;KAAE,MAAM;MAAc;IAC7C,SAAS,oBAAC,KAAK;KAAO;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;MAAI;IACjG,SAAS,YAAY,OACpB,oBAAC,KAAK;KAAO,MAAM,CAAC,QAAQ;KAAE,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,iBAAiB;MAAI;IAE7H,QAAQ,KAAK,QACZ,oBAAC,KAAK;KAA4D,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;OAA/F;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,oBAAC;KACC,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO;KAC9B,eAAe,WAAW,IAAI,gBAAgB;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;KACX;MACN;;IACG;;CAGZ,CAAC"}
|
|
@@ -99,7 +99,16 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
99
99
|
schemas.request,
|
|
100
100
|
schemas.response
|
|
101
101
|
].flat().filter(Boolean);
|
|
102
|
-
const mapOperationSchema = ({ name, schema:
|
|
102
|
+
const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options$1 }) => {
|
|
103
|
+
let schemaObject = schemaOriginal;
|
|
104
|
+
let keysToOmit = keysToOmitOriginal;
|
|
105
|
+
if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
|
|
106
|
+
schemaObject = structuredClone(schemaOriginal);
|
|
107
|
+
delete schemaObject.$ref;
|
|
108
|
+
for (const key of keysToOmitOriginal) delete schemaObject.properties?.[key];
|
|
109
|
+
if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key));
|
|
110
|
+
keysToOmit = void 0;
|
|
111
|
+
}
|
|
103
112
|
const hasProperties = Object.keys(schemaObject || {}).length > 0;
|
|
104
113
|
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
|
|
105
114
|
const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
|
|
@@ -276,4 +285,4 @@ Object.defineProperty(exports, 'zodGenerator', {
|
|
|
276
285
|
return zodGenerator;
|
|
277
286
|
}
|
|
278
287
|
});
|
|
279
|
-
//# sourceMappingURL=generators-
|
|
288
|
+
//# sourceMappingURL=generators-boBB_r4u.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-boBB_r4u.cjs","names":["File","Operations","SchemaGenerator","options","schemaKeywords","pluginTsName","Fragment","File","path","Zod"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, mini },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n events: generator.context.events,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {\n let schemaObject = schemaOriginal\n let keysToOmit = keysToOmitOriginal\n\n if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {\n schemaObject = structuredClone(schemaOriginal)\n\n // Remove $ref so the schema parser generates inline schema instead of a reference\n delete schemaObject.$ref\n\n for (const key of keysToOmitOriginal) {\n delete schemaObject.properties?.[key]\n }\n\n if (Array.isArray(schemaObject.required)) {\n schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))\n }\n\n keysToOmit = undefined\n }\n\n const hasProperties = Object.keys(schemaObject || {}).length > 0\n const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))\n\n const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required\n const optional = !required && !hasDefaults && hasProperties && name.includes('Params')\n\n if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {\n schemaObject.required = Object.entries(schemaObject.properties || {})\n .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))\n .map(([key]) => key)\n }\n\n const tree = [\n ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),\n optional ? { keyword: schemaKeywords.optional } : undefined,\n ].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </Fragment>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, mini },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAQA,MAAa,4EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,wDAAkC;EAExC,MAAM,0CAAc;EACpB,MAAM,EAAE,SAAS,uEAA2C,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAW,CAAC;EAEvE,MAAM,wBAAwB,WAAW,KAAK,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;GAAE,EAAE;EAEvI,MAAM,UAAU,OAAO,QAAQ,sBAAsB,CAClD,KAAK,CAAC,KAAK,EAAE,MAAM,iBAAiB;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;IAAC,CAAC,OAAO,QAAQ;AAEjH,UAAO,wDAACA,wBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;IAC7F,CACD,OAAO,QAAQ;AAElB,SACE,yDAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,8CAAkB;IAAE;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;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;KACX;MACN;;IACG;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
package/dist/generators.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as __name, n as PluginZod, r as ReactGenerator } from "./types-
|
|
1
|
+
import { c as __name, n as PluginZod, r as ReactGenerator } from "./types-CM-i8-E1.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/generators/operationsGenerator.d.ts
|
|
4
4
|
declare const operationsGenerator: ReactGenerator<PluginZod>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-eQyhnF5A.js";
|
|
2
|
-
import { n as PluginZod, r as ReactGenerator } from "./types-
|
|
2
|
+
import { n as PluginZod, r as ReactGenerator } from "./types-CaZySLsa.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/operationsGenerator.d.ts
|
|
5
5
|
declare const operationsGenerator: ReactGenerator<PluginZod>;
|
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_components = require('./components-BKoSLPE6.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-boBB_r4u.cjs');
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_components.__toESM(node_path);
|
|
5
5
|
let _kubb_core = require("@kubb/core");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as UserPluginWithLifeCycle, c as __name, n as PluginZod, t as Options } from "./types-
|
|
1
|
+
import { a as UserPluginWithLifeCycle, c as __name, n as PluginZod, t as Options } from "./types-CM-i8-E1.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginZodName = "plugin-zod";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-eQyhnF5A.js";
|
|
2
|
-
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-
|
|
2
|
+
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-CaZySLsa.js";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
5
|
declare const pluginZodName = "plugin-zod";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-eQyhnF5A.js";
|
|
2
|
-
import { n as operationsGenerator, t as zodGenerator } from "./generators-
|
|
2
|
+
import { n as operationsGenerator, t as zodGenerator } from "./generators-BIWiaBYS.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { PackageManager, definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
@@ -38,7 +38,7 @@ declare class Oas extends BaseOas {
|
|
|
38
38
|
getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
|
|
39
39
|
getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
|
|
40
40
|
getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
|
|
41
|
-
|
|
41
|
+
validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
42
42
|
flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
|
|
43
43
|
}
|
|
44
44
|
//#endregion
|
|
@@ -340,7 +340,7 @@ type Config<TInput = Input> = {
|
|
|
340
340
|
input: TInput;
|
|
341
341
|
output: {
|
|
342
342
|
/**
|
|
343
|
-
* The path where all generated files
|
|
343
|
+
* The path where all generated files receives exported.
|
|
344
344
|
* This can be an absolute path or a path relative to the specified root option.
|
|
345
345
|
*/
|
|
346
346
|
path: string;
|
|
@@ -355,41 +355,39 @@ type Config<TInput = Input> = {
|
|
|
355
355
|
write?: boolean;
|
|
356
356
|
/**
|
|
357
357
|
* Specifies the formatting tool to be used.
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* - '
|
|
362
|
-
* -
|
|
363
|
-
*
|
|
364
|
-
*
|
|
358
|
+
* - 'auto' automatically detects and uses biome or prettier (in that order of preference).
|
|
359
|
+
* - 'prettier' uses Prettier for code formatting.
|
|
360
|
+
* - 'biome' uses Biome for code formatting.
|
|
361
|
+
* - 'oxfmt' uses Oxfmt for code formatting.
|
|
362
|
+
* - false disables code formatting.
|
|
363
|
+
* @default 'prettier'
|
|
365
364
|
*/
|
|
366
365
|
format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
|
|
367
366
|
/**
|
|
368
367
|
* Specifies the linter that should be used to analyze the code.
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* - '
|
|
373
|
-
* -
|
|
374
|
-
*
|
|
375
|
-
* - 'oxlint': Represents the Oxlint tool for linting purposes.
|
|
376
|
-
*
|
|
368
|
+
* - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
|
|
369
|
+
* - 'eslint' uses ESLint for linting.
|
|
370
|
+
* - 'biome' uses Biome for linting.
|
|
371
|
+
* - 'oxlint' uses Oxlint for linting.
|
|
372
|
+
* - false disables linting.
|
|
373
|
+
* @default 'auto'
|
|
377
374
|
*/
|
|
378
375
|
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
|
|
379
376
|
/**
|
|
380
|
-
*
|
|
377
|
+
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
381
378
|
* @default { '.ts': '.ts'}
|
|
382
379
|
*/
|
|
383
380
|
extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
|
|
384
381
|
/**
|
|
385
|
-
*
|
|
382
|
+
* Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
|
|
386
383
|
* @default 'named'
|
|
387
384
|
*/
|
|
388
385
|
barrelType?: Exclude<BarrelType, 'propagate'> | false;
|
|
389
386
|
/**
|
|
390
|
-
*
|
|
391
|
-
* - 'simple'
|
|
392
|
-
* - 'full'
|
|
387
|
+
* Adds a default banner to the start of every generated file indicating it was generated by Kubb.
|
|
388
|
+
* - 'simple' adds banner with link to Kubb.
|
|
389
|
+
* - 'full' adds source, title, description, and OpenAPI version.
|
|
390
|
+
* - false disables banner generation.
|
|
393
391
|
* @default 'simple'
|
|
394
392
|
*/
|
|
395
393
|
defaultBanner?: 'simple' | 'full' | false;
|
|
@@ -402,17 +400,17 @@ type Config<TInput = Input> = {
|
|
|
402
400
|
override?: boolean;
|
|
403
401
|
};
|
|
404
402
|
/**
|
|
405
|
-
* An array of Kubb plugins that
|
|
403
|
+
* An array of Kubb plugins that used in the generation.
|
|
406
404
|
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
407
|
-
* If a plugin depends on another plugin, an error
|
|
405
|
+
* If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
|
|
408
406
|
*/
|
|
409
407
|
plugins?: Array<Plugin>;
|
|
410
408
|
/**
|
|
411
|
-
* Hooks
|
|
409
|
+
* Hooks triggered when a specific action occurs in Kubb.
|
|
412
410
|
*/
|
|
413
411
|
hooks?: {
|
|
414
412
|
/**
|
|
415
|
-
* Hook that
|
|
413
|
+
* Hook that triggers at the end of all executions.
|
|
416
414
|
* Useful for running Prettier or ESLint to format/lint your code.
|
|
417
415
|
*/
|
|
418
416
|
done?: string | Array<string>;
|
|
@@ -441,7 +439,7 @@ TContext = any,
|
|
|
441
439
|
TResolvePathOptions extends object = object> = {
|
|
442
440
|
name: TName;
|
|
443
441
|
/**
|
|
444
|
-
* Same
|
|
442
|
+
* Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
445
443
|
*/
|
|
446
444
|
key: PluginKey<TName | string>;
|
|
447
445
|
options: TOptions;
|
|
@@ -462,12 +460,12 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
462
460
|
*/
|
|
463
461
|
options: TOptions['resolvedOptions'];
|
|
464
462
|
/**
|
|
465
|
-
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin
|
|
463
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
466
464
|
* Can be used to validate dependent plugins.
|
|
467
465
|
*/
|
|
468
466
|
pre?: Array<string>;
|
|
469
467
|
/**
|
|
470
|
-
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin
|
|
468
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
471
469
|
*/
|
|
472
470
|
post?: Array<string>;
|
|
473
471
|
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
@@ -485,12 +483,12 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
485
483
|
*/
|
|
486
484
|
key: TOptions['key'];
|
|
487
485
|
/**
|
|
488
|
-
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin
|
|
486
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
489
487
|
* Can be used to validate dependent plugins.
|
|
490
488
|
*/
|
|
491
489
|
pre?: Array<string>;
|
|
492
490
|
/**
|
|
493
|
-
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin
|
|
491
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
494
492
|
*/
|
|
495
493
|
post?: Array<string>;
|
|
496
494
|
/**
|
|
@@ -540,10 +538,12 @@ type ResolveNameParams = {
|
|
|
540
538
|
name: string;
|
|
541
539
|
pluginKey?: Plugin['key'];
|
|
542
540
|
/**
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
541
|
+
* Specifies the type of entity being named.
|
|
542
|
+
* - 'file' customizes the name of the created file (uses camelCase).
|
|
543
|
+
* - 'function' customizes the exported function names (uses camelCase).
|
|
544
|
+
* - 'type' customizes TypeScript types (uses PascalCase).
|
|
545
|
+
* - 'const' customizes variable names (uses camelCase).
|
|
546
|
+
* @default undefined
|
|
547
547
|
*/
|
|
548
548
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
549
549
|
};
|
|
@@ -598,11 +598,14 @@ type GroupContext = {
|
|
|
598
598
|
};
|
|
599
599
|
type Group = {
|
|
600
600
|
/**
|
|
601
|
-
*
|
|
601
|
+
* Defines the type where to group the files.
|
|
602
|
+
* - 'tag' groups files by OpenAPI tags.
|
|
603
|
+
* - 'path' groups files by OpenAPI paths.
|
|
604
|
+
* @default undefined
|
|
602
605
|
*/
|
|
603
606
|
type: 'tag' | 'path';
|
|
604
607
|
/**
|
|
605
|
-
* Return the name of a group based on the group name, this
|
|
608
|
+
* Return the name of a group based on the group name, this used for the file and name generation
|
|
606
609
|
*/
|
|
607
610
|
name?: (context: GroupContext) => string;
|
|
608
611
|
};
|
|
@@ -674,7 +677,7 @@ declare class PluginManager {
|
|
|
674
677
|
parameters: PluginParameter<H>;
|
|
675
678
|
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
676
679
|
/**
|
|
677
|
-
*
|
|
680
|
+
* Returns the first non-null result.
|
|
678
681
|
*/
|
|
679
682
|
hookFirst<H extends PluginLifecycleHooks>({
|
|
680
683
|
hookName,
|
|
@@ -686,7 +689,7 @@ declare class PluginManager {
|
|
|
686
689
|
skipped?: ReadonlySet<Plugin> | null;
|
|
687
690
|
}): Promise<SafeParseResult<H>>;
|
|
688
691
|
/**
|
|
689
|
-
*
|
|
692
|
+
* Returns the first non-null result.
|
|
690
693
|
*/
|
|
691
694
|
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
692
695
|
hookName,
|
|
@@ -698,15 +701,15 @@ declare class PluginManager {
|
|
|
698
701
|
skipped?: ReadonlySet<Plugin> | null;
|
|
699
702
|
}): SafeParseResult<H>;
|
|
700
703
|
/**
|
|
701
|
-
*
|
|
704
|
+
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
702
705
|
*/
|
|
703
|
-
hookParallel<H extends PluginLifecycleHooks,
|
|
706
|
+
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
704
707
|
hookName,
|
|
705
708
|
parameters
|
|
706
709
|
}: {
|
|
707
710
|
hookName: H;
|
|
708
711
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
709
|
-
}): Promise<Awaited<
|
|
712
|
+
}): Promise<Awaited<TOutput>[]>;
|
|
710
713
|
/**
|
|
711
714
|
* Chains plugins
|
|
712
715
|
*/
|
|
@@ -842,8 +845,8 @@ type SchemaKeywordMapper = {
|
|
|
842
845
|
*/
|
|
843
846
|
path: KubbFile.Path;
|
|
844
847
|
/**
|
|
845
|
-
* When true `File.Import`
|
|
846
|
-
* When false a reference
|
|
848
|
+
* When true `File.Import` is used.
|
|
849
|
+
* When false a reference is used inside the current file.
|
|
847
850
|
*/
|
|
848
851
|
isImportable: boolean;
|
|
849
852
|
};
|
|
@@ -1075,7 +1078,7 @@ type SchemaGeneratorOptions = {
|
|
|
1075
1078
|
*/
|
|
1076
1079
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
1077
1080
|
/**
|
|
1078
|
-
* Receive schema and name(
|
|
1081
|
+
* Receive schema and name(propertyName) and return FakerMeta array
|
|
1079
1082
|
* TODO TODO add docs
|
|
1080
1083
|
* @beta
|
|
1081
1084
|
*/
|
|
@@ -1186,7 +1189,7 @@ type Options = {
|
|
|
1186
1189
|
output?: Output<Oas>;
|
|
1187
1190
|
/**
|
|
1188
1191
|
* Define which contentType should be used.
|
|
1189
|
-
* By default, the first JSON valid mediaType
|
|
1192
|
+
* By default, the first JSON valid mediaType is used
|
|
1190
1193
|
*/
|
|
1191
1194
|
contentType?: contentType;
|
|
1192
1195
|
/**
|
|
@@ -1207,25 +1210,36 @@ type Options = {
|
|
|
1207
1210
|
override?: Array<Override<ResolvedOptions>>;
|
|
1208
1211
|
/**
|
|
1209
1212
|
* Path to Zod
|
|
1210
|
-
* It
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
+
* It used as `import { z } from '${importPath}'`.
|
|
1214
|
+
* Accepts relative and absolute paths.
|
|
1215
|
+
* Path is used as-is; relative paths are based on the generated file location.
|
|
1213
1216
|
* @default 'zod'
|
|
1214
1217
|
*/
|
|
1215
1218
|
importPath?: string;
|
|
1216
1219
|
/**
|
|
1217
|
-
* Choose to use
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
+
* Choose to use date or datetime as JavaScript Date instead of string.
|
|
1221
|
+
* - false falls back to a simple z.string() format.
|
|
1222
|
+
* - 'string' uses z.string().datetime() for datetime validation.
|
|
1223
|
+
* - 'stringOffset' uses z.string().datetime({ offset: true }) for datetime with timezone offset validation.
|
|
1224
|
+
* - 'stringLocal' uses z.string().datetime({ local: true }) for local datetime validation.
|
|
1225
|
+
* - 'date' uses z.date() for JavaScript Date objects.
|
|
1226
|
+
* @default 'string'
|
|
1227
|
+
* @note 'stringOffset' will become the default in Kubb v3.
|
|
1220
1228
|
*/
|
|
1221
1229
|
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
1222
1230
|
/**
|
|
1223
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
1231
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
1232
|
+
* - 'any' allows any value.
|
|
1233
|
+
* - 'unknown' requires type narrowing before use.
|
|
1234
|
+
* - 'void' represents no value.
|
|
1224
1235
|
* @default 'any'
|
|
1225
1236
|
*/
|
|
1226
1237
|
unknownType?: 'any' | 'unknown' | 'void';
|
|
1227
1238
|
/**
|
|
1228
|
-
* Which type to use for empty schema values
|
|
1239
|
+
* Which type to use for empty schema values.
|
|
1240
|
+
* - 'any' allows any value.
|
|
1241
|
+
* - 'unknown' requires type narrowing before use.
|
|
1242
|
+
* - 'void' represents no value.
|
|
1229
1243
|
* @default `unknownType`
|
|
1230
1244
|
*/
|
|
1231
1245
|
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
@@ -1254,7 +1268,7 @@ type Options = {
|
|
|
1254
1268
|
*/
|
|
1255
1269
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
1256
1270
|
/**
|
|
1257
|
-
* Receive schema and baseName(
|
|
1271
|
+
* Receive schema and baseName(propertyName) and return FakerMeta array
|
|
1258
1272
|
* TODO TODO add docs
|
|
1259
1273
|
* @beta
|
|
1260
1274
|
*/
|
|
@@ -1265,14 +1279,16 @@ type Options = {
|
|
|
1265
1279
|
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
1266
1280
|
};
|
|
1267
1281
|
/**
|
|
1268
|
-
* Which version of Zod should be used
|
|
1269
|
-
*
|
|
1282
|
+
* Which version of Zod should be used.
|
|
1283
|
+
* - '3' uses Zod v3.x syntax and features.
|
|
1284
|
+
* - '4' uses Zod v4.x syntax and features.
|
|
1285
|
+
* @default '3'
|
|
1270
1286
|
*/
|
|
1271
1287
|
version?: '3' | '4';
|
|
1272
1288
|
/**
|
|
1273
1289
|
* Use Zod Mini's functional API for better tree-shaking support.
|
|
1274
1290
|
* When enabled, generates functional syntax (e.g., `z.optional(z.string())`) instead of chainable methods (e.g., `z.string().optional()`).
|
|
1275
|
-
* Requires Zod v4 or later. When `mini: true`, `version`
|
|
1291
|
+
* Requires Zod v4 or later. When `mini: true`, `version` is set to '4' and `importPath` will default to 'zod/mini'.
|
|
1276
1292
|
* @default false
|
|
1277
1293
|
*/
|
|
1278
1294
|
mini?: boolean;
|
|
@@ -1313,4 +1329,4 @@ type ResolvedOptions = {
|
|
|
1313
1329
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1314
1330
|
//#endregion
|
|
1315
1331
|
export { UserPluginWithLifeCycle as a, __name as c, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
|
|
1316
|
-
//# sourceMappingURL=types-
|
|
1332
|
+
//# sourceMappingURL=types-CM-i8-E1.d.cts.map
|