@kubb/plugin-zod 3.16.3 → 3.16.4
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/{generators-DcUZYcq0.js → generators-C3ALr3ph.js} +3 -3
- package/dist/generators-C3ALr3ph.js.map +1 -0
- package/dist/{generators-B13NknOz.cjs → generators-D3uH7-vO.cjs} +3 -3
- package/dist/generators-D3uH7-vO.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/utils/v4.cjs +0 -0
- package/dist/utils/v4.d.cts +38 -0
- package/dist/utils/v4.d.ts +38 -0
- package/dist/utils/v4.js +1 -0
- package/package.json +17 -10
- package/src/generators/zodGenerator.tsx +2 -2
- package/src/plugin.ts +2 -3
- package/src/utils/v4/ToZod.ts +61 -0
- package/src/utils/v4/index.ts +1 -0
- package/dist/generators-B13NknOz.cjs.map +0 -1
- package/dist/generators-DcUZYcq0.js.map +0 -1
|
@@ -76,7 +76,7 @@ const zodGenerator = createReactGenerator({
|
|
|
76
76
|
}),
|
|
77
77
|
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
78
78
|
isTypeOnly: true,
|
|
79
|
-
path: "@kubb/plugin-zod/utils",
|
|
79
|
+
path: plugin.options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
|
|
80
80
|
name: ["ToZod"]
|
|
81
81
|
}),
|
|
82
82
|
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
@@ -168,7 +168,7 @@ const zodGenerator = createReactGenerator({
|
|
|
168
168
|
}),
|
|
169
169
|
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
170
170
|
isTypeOnly: true,
|
|
171
|
-
path: "@kubb/plugin-zod/utils",
|
|
171
|
+
path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
|
|
172
172
|
name: ["ToZod"]
|
|
173
173
|
}),
|
|
174
174
|
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
@@ -251,4 +251,4 @@ const operationsGenerator = createReactGenerator({
|
|
|
251
251
|
|
|
252
252
|
//#endregion
|
|
253
253
|
export { operationsGenerator, zodGenerator };
|
|
254
|
-
//# sourceMappingURL=generators-
|
|
254
|
+
//# sourceMappingURL=generators-C3ALr3ph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-C3ALr3ph.js","names":["options","i: number"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={plugin.options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,EAAE;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,YAAY,GAAG;EAE1E,MAAM,EAAE,QAAQ,eAAe,MAAM,GAAG,QAAmB;EAC3D,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,UAAU,GAAG,qBAAqB;EAC/D,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAI,gBAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;EACnB;EAED,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;EAAS,EAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,qBAAqB,CAAC,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGA,WAA8B,EAAEC,MAAc;GAElI,MAAM,WAAW,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O;EAAW,EAAC;EAEvE,MAAM,wBAAwB,WAAW,IAAI,CAAC,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,WAAY,EAAC;EAAE,GAAE;EAEvI,MAAM,UAAU,OAAO,QAAQ,sBAAsB,CAClD,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,KAAK;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;GAAC,EAAC,OAAO,QAAQ;AAEjH,8BAAQ,KAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;EAC9F,EAAC,CACD,OAAO,QAAQ;AAElB,8BACG;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;GAAQ,EAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;GAAQ,EAAC;cAEjC,6BACA;IAAiB;IAAM,YAAY;KAAyB;IACxD;CAEV;AACF,EAAC"}
|
|
@@ -76,7 +76,7 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
76
76
|
}),
|
|
77
77
|
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
78
78
|
isTypeOnly: true,
|
|
79
|
-
path: "@kubb/plugin-zod/utils",
|
|
79
|
+
path: plugin.options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
|
|
80
80
|
name: ["ToZod"]
|
|
81
81
|
}),
|
|
82
82
|
imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
@@ -168,7 +168,7 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
168
168
|
}),
|
|
169
169
|
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
170
170
|
isTypeOnly: true,
|
|
171
|
-
path: "@kubb/plugin-zod/utils",
|
|
171
|
+
path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
|
|
172
172
|
name: ["ToZod"]
|
|
173
173
|
}),
|
|
174
174
|
imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
@@ -262,4 +262,4 @@ Object.defineProperty(exports, 'zodGenerator', {
|
|
|
262
262
|
return zodGenerator;
|
|
263
263
|
}
|
|
264
264
|
});
|
|
265
|
-
//# sourceMappingURL=generators-
|
|
265
|
+
//# sourceMappingURL=generators-D3uH7-vO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-D3uH7-vO.cjs","names":["SchemaGenerator","options","i: number","schemaKeywords","pluginTsName","Oas","File","Zod","File","Operations"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={plugin.options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,EAAE;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,YAAY,GAAG;EAE1E,MAAM,EAAE,QAAQ,eAAe,MAAM,6BAAsB;EAC3D,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,UAAU,qDAAwB;EAC/D,MAAM,+DAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,kCAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;EACnB;EAED,MAAM,mBAAmB;GAAC,QAA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Q,EACN,KAAK,WACL,SAAS,EAAE,QAAQ,EACpB,EACF,6BAAsB;EACvB,MAAM,2CAAc;EACpB,MAAM,EAAE,SAAS,oBAAoB,qDAAwB;EAE7D,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;EAAW,EAAC;EAEvE,MAAM,wBAAwB,WAAW,IAAI,CAAC,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,WAAY,EAAC;EAAE,GAAE;EAEvI,MAAM,UAAU,OAAO,QAAQ,sBAAsB,CAClD,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,KAAK;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;GAAC,EAAC,OAAO,QAAQ;AAEjH,4DAAQC,kBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;EAC9F,EAAC,CACD,OAAO,QAAQ;AAElB,4DACGA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;GAAQ,EAAC;GAChE,+CAAkB;IAAE;IAAK;GAAQ,EAAC;cAEjC,2DACAC;IAAiB;IAAM,YAAY;KAAyB;IACxD;CAEV;AACF,EAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('./components-GvkeO2ig.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-D3uH7-vO.cjs');
|
|
3
3
|
|
|
4
4
|
exports.operationsGenerator = require_generators.operationsGenerator;
|
|
5
5
|
exports.zodGenerator = require_generators.zodGenerator;
|
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_components = require('./components-GvkeO2ig.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-D3uH7-vO.cjs');
|
|
3
3
|
const node_path = require_components.__toESM(require("node:path"));
|
|
4
4
|
const __kubb_core = require_components.__toESM(require("@kubb/core"));
|
|
5
5
|
const __kubb_core_transformers = require_components.__toESM(require("@kubb/core/transformers"));
|
|
@@ -12,7 +12,7 @@ const pluginZod = (0, __kubb_core.createPlugin)((options) => {
|
|
|
12
12
|
const { output = {
|
|
13
13
|
path: "zod",
|
|
14
14
|
barrelType: "named"
|
|
15
|
-
}, group, exclude = [], include, override = [], transformers = {}, dateType = "string", unknownType = "any", emptySchemaType = unknownType, typed = false, mapper = {}, operations = false, version = "3", importPath = version === "4" ? "zod/v4" : "zod", coercion = false, inferred = false, generators = [require_generators.zodGenerator, operations ? require_generators.operationsGenerator : void 0].filter(Boolean), wrapOutput = void 0, contentType } = options;
|
|
15
|
+
}, group, exclude = [], include, override = [], transformers = {}, dateType = "string", unknownType = "any", emptySchemaType = unknownType, typed = false, mapper = {}, operations = false, version = new __kubb_core.PackageManager().isValidSync("zod", ">=4") ? "4" : "3", importPath = version === "4" ? "zod/v4" : "zod", coercion = false, inferred = false, generators = [require_generators.zodGenerator, operations ? require_generators.operationsGenerator : void 0].filter(Boolean), wrapOutput = void 0, contentType } = options;
|
|
16
16
|
return {
|
|
17
17
|
name: pluginZodName,
|
|
18
18
|
options: {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","groupName: Group['name']","PluginManager","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","groupName: Group['name']","PluginManager","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, FileManager, type Group, PackageManager, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n emptySchemaType = unknownType,\n typed = false,\n mapper = {},\n operations = false,\n version = new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n importPath = version === '4' ? 'zod/v4' : 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n wrapOutput = undefined,\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n emptySchemaType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,0CAAoC,CAAC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAO,YAAY;CAAS,GAC7C,OACA,UAAU,CAAE,GACZ,SACA,WAAW,CAAE,GACb,eAAe,CAAE,GACjB,WAAW,UACX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Q,SAAS;GAClB,EAAC;AAEF,OAAI,SAAS,QACX,wDAA0B,aAAa;AAGzC,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;EACR;EACD,MAAM,aAAa;GACjB,MAAM,CAAC,cAA8C,GAAGG,0BAAc,mBAAyC,KAAK,SAAS,CAACN,+BAAc,EAAC;GAE7I,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;GAChD,MAAM,OAAOG,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAOC,wBAAY,QAAQD,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GAEjE,MAAM,kBAAkB,IAAII,kCAAgB,KAAK,OAAO,SAAS;IAC/D;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;GAChB;GAED,MAAM,cAAc,MAAM,gBAAgB,MAAM,GAAG,WAAW;GAC9D,MAAM,KAAK,QAAQ,GAAG,YAAY;GAElC,MAAM,qBAAqB,IAAIC,qCAAmB,KAAK,OAAO,SAAS;IACrE;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;GACD;GAED,MAAM,iBAAiB,MAAM,mBAAmB,MAAM,GAAG,WAAW;GACpE,MAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,MAAM,KAAK,YAAY,eAAe;IACxD,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,IACxB;IACD,QAAQ,KAAK;GACd,EAAC;GAEF,MAAM,KAAK,QAAQ,GAAG,YAAY;EACnC;CACF;AACF,EAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./components-CJ6RN1R2.js";
|
|
2
|
-
import { operationsGenerator, zodGenerator } from "./generators-
|
|
2
|
+
import { operationsGenerator, zodGenerator } from "./generators-C3ALr3ph.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
4
|
+
import { FileManager, PackageManager, PluginManager, createPlugin } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
6
6
|
import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
7
7
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
@@ -12,7 +12,7 @@ const pluginZod = createPlugin((options) => {
|
|
|
12
12
|
const { output = {
|
|
13
13
|
path: "zod",
|
|
14
14
|
barrelType: "named"
|
|
15
|
-
}, group, exclude = [], include, override = [], transformers: transformers$1 = {}, dateType = "string", unknownType = "any", emptySchemaType = unknownType, typed = false, mapper = {}, operations = false, version = "3", importPath = version === "4" ? "zod/v4" : "zod", coercion = false, inferred = false, generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean), wrapOutput = void 0, contentType } = options;
|
|
15
|
+
}, group, exclude = [], include, override = [], transformers: transformers$1 = {}, dateType = "string", unknownType = "any", emptySchemaType = unknownType, typed = false, mapper = {}, operations = false, version = new PackageManager().isValidSync("zod", ">=4") ? "4" : "3", importPath = version === "4" ? "zod/v4" : "zod", coercion = false, inferred = false, generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean), wrapOutput = void 0, contentType } = options;
|
|
16
16
|
return {
|
|
17
17
|
name: pluginZodName,
|
|
18
18
|
options: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']","transformers"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']","transformers"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, FileManager, type Group, PackageManager, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n emptySchemaType = unknownType,\n typed = false,\n mapper = {},\n operations = false,\n version = new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n importPath = version === '4' ? 'zod/v4' : 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n wrapOutput = undefined,\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n emptySchemaType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,aAAwB,CAAC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAO,YAAY;CAAS,GAC7C,OACA,UAAU,CAAE,GACZ,SACA,WAAW,CAAE,GACb,+BAAe,CAAE,GACjB,WAAW,UACX,cAAc,OACd,kBAAkB,aAClB,QAAQ,OACR,SAAS,CAAE,GACX,aAAa,OACb,UAAU,IAAI,iBAAiB,YAAY,OAAO,MAAM,GAAG,MAAM,KAC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O;EACR;EACD,MAAM,aAAa;GACjB,MAAM,CAAC,cAA8C,GAAG,cAAc,mBAAyC,KAAK,SAAS,CAAC,aAAc,EAAC;GAE7I,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;GAChD,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GAEjE,MAAM,kBAAkB,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;GAChB;GAED,MAAM,cAAc,MAAM,gBAAgB,MAAM,GAAG,WAAW;GAC9D,MAAM,KAAK,QAAQ,GAAG,YAAY;GAElC,MAAM,qBAAqB,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;GACD;GAED,MAAM,iBAAiB,MAAM,mBAAmB,MAAM,GAAG,WAAW;GACpE,MAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,MAAM,KAAK,YAAY,eAAe;IACxD,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,IACxB;IACD,QAAQ,KAAK;GACd,EAAC;GAEF,MAAM,KAAK,QAAQ,GAAG,YAAY;EACnC;CACF;AACF,EAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/v4/ToZod.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
7
|
+
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
8
|
+
*/
|
|
9
|
+
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
10
|
+
type nonoptional<T> = T extends undefined ? never : T;
|
|
11
|
+
type nonnullable<T> = T extends null ? never : T;
|
|
12
|
+
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
13
|
+
type zodKey<T> = isAny<T> extends true ? 'any' : equals<T, boolean> extends true ? 'boolean' : [undefined] extends [T] ? 'optional' : [null] extends [T] ? 'nullable' : T extends any[] ? 'array' : equals<T, string> extends true ? 'string' : equals<T, bigint> extends true ? 'bigint' : equals<T, number> extends true ? 'number' : equals<T, Date> extends true ? 'date' : T extends {
|
|
14
|
+
slice: any;
|
|
15
|
+
stream: any;
|
|
16
|
+
text: any;
|
|
17
|
+
} ? 'blob' : T extends {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} ? 'object' : 'rest';
|
|
20
|
+
type ToZod<T> = {
|
|
21
|
+
any: z.ZodAny;
|
|
22
|
+
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
23
|
+
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
24
|
+
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
25
|
+
string: z.ZodString;
|
|
26
|
+
file: z.ZodFile;
|
|
27
|
+
blob: z.ZodType<Blob, T>;
|
|
28
|
+
bigint: z.ZodBigInt;
|
|
29
|
+
number: z.ZodNumber;
|
|
30
|
+
boolean: z.ZodBoolean;
|
|
31
|
+
date: z.ZodDate;
|
|
32
|
+
object: z.ZodObject<ZodShape<T>, 'passthrough'>;
|
|
33
|
+
rest: z.ZodType<T>;
|
|
34
|
+
}[zodKey<T>];
|
|
35
|
+
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
36
|
+
//#endregion
|
|
37
|
+
export { type ToZod, type ZodShape };
|
|
38
|
+
//# sourceMappingURL=v4.d.cts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/v4/ToZod.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
7
|
+
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
8
|
+
*/
|
|
9
|
+
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
10
|
+
type nonoptional<T> = T extends undefined ? never : T;
|
|
11
|
+
type nonnullable<T> = T extends null ? never : T;
|
|
12
|
+
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
13
|
+
type zodKey<T> = isAny<T> extends true ? 'any' : equals<T, boolean> extends true ? 'boolean' : [undefined] extends [T] ? 'optional' : [null] extends [T] ? 'nullable' : T extends any[] ? 'array' : equals<T, string> extends true ? 'string' : equals<T, bigint> extends true ? 'bigint' : equals<T, number> extends true ? 'number' : equals<T, Date> extends true ? 'date' : T extends {
|
|
14
|
+
slice: any;
|
|
15
|
+
stream: any;
|
|
16
|
+
text: any;
|
|
17
|
+
} ? 'blob' : T extends {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} ? 'object' : 'rest';
|
|
20
|
+
type ToZod<T> = {
|
|
21
|
+
any: z.ZodAny;
|
|
22
|
+
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
23
|
+
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
24
|
+
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
25
|
+
string: z.ZodString;
|
|
26
|
+
file: z.ZodFile;
|
|
27
|
+
blob: z.ZodType<Blob, T>;
|
|
28
|
+
bigint: z.ZodBigInt;
|
|
29
|
+
number: z.ZodNumber;
|
|
30
|
+
boolean: z.ZodBoolean;
|
|
31
|
+
date: z.ZodDate;
|
|
32
|
+
object: z.ZodObject<ZodShape<T>, 'passthrough'>;
|
|
33
|
+
rest: z.ZodType<T>;
|
|
34
|
+
}[zodKey<T>];
|
|
35
|
+
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
36
|
+
//#endregion
|
|
37
|
+
export { type ToZod, type ZodShape };
|
|
38
|
+
//# sourceMappingURL=v4.d.ts.map
|
package/dist/utils/v4.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.4",
|
|
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",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"import": "./dist/utils.js",
|
|
42
42
|
"require": "./dist/utils.cjs"
|
|
43
43
|
},
|
|
44
|
+
"./utils/v4": {
|
|
45
|
+
"import": "./dist/utils/v4.js",
|
|
46
|
+
"require": "./dist/utils/v4.cjs"
|
|
47
|
+
},
|
|
44
48
|
"./package.json": "./package.json"
|
|
45
49
|
},
|
|
46
50
|
"main": "./dist/index.cjs",
|
|
@@ -56,6 +60,9 @@
|
|
|
56
60
|
],
|
|
57
61
|
"utils": [
|
|
58
62
|
"./dist/utils.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"utils/v4": [
|
|
65
|
+
"./dist/utils/v4.d.ts"
|
|
59
66
|
]
|
|
60
67
|
}
|
|
61
68
|
},
|
|
@@ -66,20 +73,20 @@
|
|
|
66
73
|
"!/**/__tests__/**"
|
|
67
74
|
],
|
|
68
75
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "3.16.
|
|
70
|
-
"@kubb/oas": "3.16.
|
|
71
|
-
"@kubb/parser-ts": "3.16.
|
|
72
|
-
"@kubb/plugin-oas": "3.16.
|
|
73
|
-
"@kubb/plugin-ts": "3.16.
|
|
74
|
-
"@kubb/react": "3.16.
|
|
76
|
+
"@kubb/core": "3.16.4",
|
|
77
|
+
"@kubb/oas": "3.16.4",
|
|
78
|
+
"@kubb/parser-ts": "3.16.4",
|
|
79
|
+
"@kubb/plugin-oas": "3.16.4",
|
|
80
|
+
"@kubb/plugin-ts": "3.16.4",
|
|
81
|
+
"@kubb/react": "3.16.4"
|
|
75
82
|
},
|
|
76
83
|
"devDependencies": {
|
|
77
84
|
"@asteasolutions/zod-to-openapi": "^7.3.4",
|
|
78
85
|
"@hono/zod-openapi": "0.19.2",
|
|
79
86
|
"tsdown": "^0.14.1",
|
|
80
|
-
"zod": "
|
|
81
|
-
"@kubb/config-ts": "3.16.
|
|
82
|
-
"@kubb/plugin-oas": "3.16.
|
|
87
|
+
"zod": "^3.25.67",
|
|
88
|
+
"@kubb/config-ts": "3.16.4",
|
|
89
|
+
"@kubb/plugin-oas": "3.16.4"
|
|
83
90
|
},
|
|
84
91
|
"peerDependencies": {
|
|
85
92
|
"@kubb/react": "^3.0.0"
|
|
@@ -63,7 +63,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
63
63
|
return (
|
|
64
64
|
<Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>
|
|
65
65
|
{typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
|
|
66
|
-
{typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}
|
|
66
|
+
{typed && <File.Import isTypeOnly path={plugin.options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}
|
|
67
67
|
{imports.map((imp) => (
|
|
68
68
|
<File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />
|
|
69
69
|
))}
|
|
@@ -133,7 +133,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
133
133
|
>
|
|
134
134
|
<File.Import name={['z']} path={importPath} />
|
|
135
135
|
{typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
|
|
136
|
-
{typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}
|
|
136
|
+
{typed && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}
|
|
137
137
|
{imports.map((imp) => (
|
|
138
138
|
<File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />
|
|
139
139
|
))}
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import type
|
|
3
|
-
import { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'
|
|
2
|
+
import { createPlugin, FileManager, type Group, PackageManager, type Plugin, PluginManager } from '@kubb/core'
|
|
4
3
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
4
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
6
5
|
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
@@ -25,7 +24,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
25
24
|
typed = false,
|
|
26
25
|
mapper = {},
|
|
27
26
|
operations = false,
|
|
28
|
-
version = '3',
|
|
27
|
+
version = new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',
|
|
29
28
|
importPath = version === '4' ? 'zod/v4' : 'zod',
|
|
30
29
|
coercion = false,
|
|
31
30
|
inferred = false,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { z } from 'zod/v4'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
5
|
+
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false
|
|
9
|
+
type nonoptional<T> = T extends undefined ? never : T
|
|
10
|
+
type nonnullable<T> = T extends null ? never : T
|
|
11
|
+
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false
|
|
12
|
+
|
|
13
|
+
type zodKey<T> = isAny<T> extends true
|
|
14
|
+
? 'any'
|
|
15
|
+
: equals<T, boolean> extends true
|
|
16
|
+
? 'boolean'
|
|
17
|
+
: [undefined] extends [T]
|
|
18
|
+
? 'optional'
|
|
19
|
+
: [null] extends [T]
|
|
20
|
+
? 'nullable'
|
|
21
|
+
: T extends any[]
|
|
22
|
+
? 'array'
|
|
23
|
+
: equals<T, string> extends true
|
|
24
|
+
? 'string'
|
|
25
|
+
: equals<T, bigint> extends true
|
|
26
|
+
? 'bigint'
|
|
27
|
+
: equals<T, number> extends true
|
|
28
|
+
? 'number'
|
|
29
|
+
: equals<T, Date> extends true
|
|
30
|
+
? 'date'
|
|
31
|
+
: T extends { slice: any; stream: any; text: any }
|
|
32
|
+
? 'blob'
|
|
33
|
+
: T extends { [key: string]: any }
|
|
34
|
+
? 'object'
|
|
35
|
+
: 'rest'
|
|
36
|
+
|
|
37
|
+
type ToZod<T> = {
|
|
38
|
+
any: z.ZodAny
|
|
39
|
+
// @ts-expect-error Excessive stack depth comparing types
|
|
40
|
+
optional: z.ZodOptional<ToZod<nonoptional<T>>>
|
|
41
|
+
// @ts-expect-error Excessive stack depth comparing types
|
|
42
|
+
nullable: z.ZodNullable<ToZod<nonnullable<T>>>
|
|
43
|
+
// @ts-expect-error Excessive stack depth comparing types
|
|
44
|
+
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never
|
|
45
|
+
string: z.ZodString
|
|
46
|
+
file: z.ZodFile
|
|
47
|
+
blob: z.ZodType<Blob, T>
|
|
48
|
+
bigint: z.ZodBigInt
|
|
49
|
+
number: z.ZodNumber
|
|
50
|
+
boolean: z.ZodBoolean
|
|
51
|
+
date: z.ZodDate
|
|
52
|
+
// @ts-expect-error Excessive stack depth comparing types
|
|
53
|
+
object: z.ZodObject<ZodShape<T>, 'passthrough'>
|
|
54
|
+
rest: z.ZodType<T>
|
|
55
|
+
}[zodKey<T>]
|
|
56
|
+
|
|
57
|
+
type ZodShape<T> = {
|
|
58
|
+
[key in keyof T]-?: ToZod<T[key]>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { ToZod, ZodShape }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ToZod, ZodShape } from './ToZod.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-B13NknOz.cjs","names":["SchemaGenerator","options","i: number","schemaKeywords","pluginTsName","Oas","File","Zod","File","Operations"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,EAAE;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,YAAY,GAAG;EAE1E,MAAM,EAAE,QAAQ,eAAe,MAAM,6BAAsB;EAC3D,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,UAAU,qDAAwB;EAC/D,MAAM,+DAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,kCAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;EACnB;EAED,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;EAAS,EAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,qBAAqB,CAAC,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGC,WAA8B,EAAEC,MAAc;GAElI,MAAM,WAAW,MAAM,QAAQ,cAAc,SAAS,GAAG,CAAC,CAAC,aAAa,SAAS,SAAS,CAAC,CAAC,cAAc;GAC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,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,KAAK;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;GAAC,EAAC,OAAO,QAAQ;AAEjH,4DAAQC,kBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;EAC9F,EAAC,CACD,OAAO,QAAQ;AAElB,4DACGA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;GAAQ,EAAC;GAChE,+CAAkB;IAAE;IAAK;GAAQ,EAAC;cAEjC,2DACAC;IAAiB;IAAM,YAAY;KAAyB;IACxD;CAEV;AACF,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-DcUZYcq0.js","names":["options","i: number"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,EAAE;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,YAAY,GAAG;EAE1E,MAAM,EAAE,QAAQ,eAAe,MAAM,GAAG,QAAmB;EAC3D,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,UAAU,GAAG,qBAAqB;EAC/D,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAI,gBAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;EACnB;EAED,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;G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