@kubb/plugin-zod 4.5.0 → 4.5.2
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-T3e_E7Uy.cjs → generators-BOldMlBb.cjs} +5 -4
- package/dist/generators-BOldMlBb.cjs.map +1 -0
- package/dist/{generators-9upbJt-4.js → generators-DpdxKqO8.js} +5 -4
- package/dist/generators-DpdxKqO8.js.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 +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-DcQBOr_-.d.ts → types-Cb64GFh2.d.ts} +45 -38
- package/dist/{types-CQSK_Scm.d.cts → types-CdCimOAr.d.cts} +45 -38
- package/package.json +8 -8
- package/src/generators/__snapshots__/getPets.ts +1 -1
- package/src/generators/__snapshots__/queryAllDefaulted.ts +2 -2
- package/src/generators/zodGenerator.tsx +11 -4
- package/src/plugin.ts +6 -8
- package/dist/generators-9upbJt-4.js.map +0 -1
- package/dist/generators-T3e_E7Uy.cjs.map +0 -1
package/dist/components.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-
|
|
1
|
+
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-CdCimOAr.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,4 +1,4 @@
|
|
|
1
|
-
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-
|
|
1
|
+
import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-Cb64GFh2.js";
|
|
2
2
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
4
4
|
|
|
@@ -107,9 +107,10 @@ const zodGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
107
107
|
schemas.response
|
|
108
108
|
].flat().filter(Boolean);
|
|
109
109
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const optional = !required && !
|
|
110
|
+
const hasProperties = Object.keys(schemaObject || {}).length > 0;
|
|
111
|
+
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
|
|
112
|
+
const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
|
|
113
|
+
if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) schemaObject.required = Object.entries(schemaObject.properties || {}).filter(([_key, value]) => value && Object.hasOwn(value, "default")).map(([key]) => key);
|
|
113
114
|
const tree = [...schemaGenerator.parse({
|
|
114
115
|
schemaObject,
|
|
115
116
|
name
|
|
@@ -279,4 +280,4 @@ Object.defineProperty(exports, 'zodGenerator', {
|
|
|
279
280
|
return zodGenerator;
|
|
280
281
|
}
|
|
281
282
|
});
|
|
282
|
-
//# sourceMappingURL=generators-
|
|
283
|
+
//# sourceMappingURL=generators-BOldMlBb.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BOldMlBb.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 },\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 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) => {\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 = [...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 <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 />\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 },\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 />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,MAAa,6EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,yDAAkC;EAExC,MAAM,2CAAc;EACpB,MAAM,EAAE,SAAS,wEAA2C,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,yDAACA,yBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;IAC7F,CACD,OAAO,QAAQ;AAElB,SACE,0DAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;;IAElC,yDAACA,y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kB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;;IAElC,yDAACA,yBAAK;KAAO,MAAM,CAAC,IAAI;KAAE,MAAM;MAAc;IAC7C,SAAS,yDAACA,yBAAK;KAAO;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;MAAI;IACjG,SAAS,YAAY,OACpB,yDAACA,yBAAK;KAAO,MAAM,CAAC,QAAQ;KAAE,MAAM,IAAI,KAAK;KAAM,MAAMC,kBAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,iBAAiB;MAAI;IAE7H,QAAQ,KAAK,QACZ,yDAACD,yBAAK;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,yDAACE;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;MACjB;;IACG;;CAGZ,CAAC"}
|
|
@@ -98,9 +98,10 @@ const zodGenerator = createReactGenerator({
|
|
|
98
98
|
schemas.response
|
|
99
99
|
].flat().filter(Boolean);
|
|
100
100
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const optional = !required && !
|
|
101
|
+
const hasProperties = Object.keys(schemaObject || {}).length > 0;
|
|
102
|
+
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
|
|
103
|
+
const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
|
|
104
|
+
if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) schemaObject.required = Object.entries(schemaObject.properties || {}).filter(([_key, value]) => value && Object.hasOwn(value, "default")).map(([key]) => key);
|
|
104
105
|
const tree = [...schemaGenerator.parse({
|
|
105
106
|
schemaObject,
|
|
106
107
|
name
|
|
@@ -259,4 +260,4 @@ const zodGenerator = createReactGenerator({
|
|
|
259
260
|
|
|
260
261
|
//#endregion
|
|
261
262
|
export { operationsGenerator as n, zodGenerator as t };
|
|
262
|
-
//# sourceMappingURL=generators-
|
|
263
|
+
//# sourceMappingURL=generators-DpdxKqO8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DpdxKqO8.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 },\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 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) => {\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 = [...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 <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 />\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 },\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 />\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,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAW,CAAC;EAEvE,M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AAC,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;MACjB;;IACG;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('./components-DIUzzW4k.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-BOldMlBb.cjs');
|
|
3
3
|
|
|
4
4
|
exports.operationsGenerator = require_generators.operationsGenerator;
|
|
5
5
|
exports.zodGenerator = require_generators.zodGenerator;
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_components = require('./components-DIUzzW4k.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-BOldMlBb.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");
|
|
@@ -15,7 +15,7 @@ __kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
|
|
|
15
15
|
|
|
16
16
|
//#region src/plugin.ts
|
|
17
17
|
const pluginZodName = "plugin-zod";
|
|
18
|
-
const pluginZod = (0, __kubb_core.
|
|
18
|
+
const pluginZod = (0, __kubb_core.definePlugin)((options) => {
|
|
19
19
|
const { output = {
|
|
20
20
|
path: "zod",
|
|
21
21
|
barrelType: "named"
|
|
@@ -39,7 +39,8 @@ const pluginZod = (0, __kubb_core.createPlugin)((options) => {
|
|
|
39
39
|
inferred,
|
|
40
40
|
group,
|
|
41
41
|
wrapOutput,
|
|
42
|
-
version
|
|
42
|
+
version,
|
|
43
|
+
usedEnumNames: {}
|
|
43
44
|
},
|
|
44
45
|
pre: [__kubb_plugin_oas.pluginOasName, typed ? __kubb_plugin_ts.pluginTsName : void 0].filter(Boolean),
|
|
45
46
|
resolvePath(baseName, pathMode, options$1) {
|
|
@@ -68,11 +69,10 @@ const pluginZod = (0, __kubb_core.createPlugin)((options) => {
|
|
|
68
69
|
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
69
70
|
return resolvedName;
|
|
70
71
|
},
|
|
71
|
-
async
|
|
72
|
-
const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
|
|
73
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
72
|
+
async install() {
|
|
74
73
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
75
74
|
const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
75
|
+
const oas = await this.getOas();
|
|
76
76
|
if (this.plugin.options.typed && this.plugin.options.version === "3") await this.addFile({
|
|
77
77
|
baseName: "ToZod.ts",
|
|
78
78
|
path: node_path.default.resolve(root, ".kubb/ToZod.ts"),
|
|
@@ -105,7 +105,7 @@ const pluginZod = (0, __kubb_core.createPlugin)((options) => {
|
|
|
105
105
|
mode
|
|
106
106
|
}).build(...generators);
|
|
107
107
|
await this.addFile(...operationFiles);
|
|
108
|
-
const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.
|
|
108
|
+
const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
109
109
|
type: output.barrelType ?? "named",
|
|
110
110
|
root,
|
|
111
111
|
output,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","path","options","groupName: Group['name']","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","path","options","groupName: Group['name']","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\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 = definePlugin<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 usedEnumNames: {},\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n if (this.plugin.options.typed && this.plugin.options.version === '3') {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'ToZod.ts',\n path: path.resolve(root, '.kubb/ToZod.ts'),\n sources: [\n {\n name: 'ToZod',\n value: resolveModuleSource('@kubb/plugin-zod/templates/ToZod').source,\n },\n ],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\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 fabric: this.fabric,\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 getBarrelFiles(this.fabric.files, {\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":";;;;;;;;;;;;;;;;A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AW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-
|
|
1
|
+
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-CdCimOAr.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginZodName = "plugin-zod";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-
|
|
1
|
+
import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-Cb64GFh2.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginZodName = "plugin-zod";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./components-BtBB23cQ.js";
|
|
2
|
-
import { n as operationsGenerator, t as zodGenerator } from "./generators-
|
|
2
|
+
import { n as operationsGenerator, t as zodGenerator } from "./generators-DpdxKqO8.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { PackageManager,
|
|
4
|
+
import { PackageManager, definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
6
6
|
import { resolveModuleSource } from "@kubb/core/utils";
|
|
7
7
|
import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
@@ -9,7 +9,7 @@ import { pluginTsName } from "@kubb/plugin-ts";
|
|
|
9
9
|
|
|
10
10
|
//#region src/plugin.ts
|
|
11
11
|
const pluginZodName = "plugin-zod";
|
|
12
|
-
const pluginZod =
|
|
12
|
+
const pluginZod = definePlugin((options) => {
|
|
13
13
|
const { output = {
|
|
14
14
|
path: "zod",
|
|
15
15
|
barrelType: "named"
|
|
@@ -33,7 +33,8 @@ const pluginZod = createPlugin((options) => {
|
|
|
33
33
|
inferred,
|
|
34
34
|
group,
|
|
35
35
|
wrapOutput,
|
|
36
|
-
version
|
|
36
|
+
version,
|
|
37
|
+
usedEnumNames: {}
|
|
37
38
|
},
|
|
38
39
|
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
39
40
|
resolvePath(baseName, pathMode, options$1) {
|
|
@@ -62,11 +63,10 @@ const pluginZod = createPlugin((options) => {
|
|
|
62
63
|
if (type) return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
63
64
|
return resolvedName;
|
|
64
65
|
},
|
|
65
|
-
async
|
|
66
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
67
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
66
|
+
async install() {
|
|
68
67
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
69
68
|
const mode = getMode(path.resolve(root, output.path));
|
|
69
|
+
const oas = await this.getOas();
|
|
70
70
|
if (this.plugin.options.typed && this.plugin.options.version === "3") await this.addFile({
|
|
71
71
|
baseName: "ToZod.ts",
|
|
72
72
|
path: path.resolve(root, ".kubb/ToZod.ts"),
|
|
@@ -99,7 +99,7 @@ const pluginZod = createPlugin((options) => {
|
|
|
99
99
|
mode
|
|
100
100
|
}).build(...generators);
|
|
101
101
|
await this.addFile(...operationFiles);
|
|
102
|
-
const barrelFiles = await getBarrelFiles(this.
|
|
102
|
+
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
103
103
|
type: output.barrelType ?? "named",
|
|
104
104
|
root,
|
|
105
105
|
output,
|
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 { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\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 = definePlugin<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 usedEnumNames: {},\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n if (this.plugin.options.typed && this.plugin.options.version === '3') {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'ToZod.ts',\n path: path.resolve(root, '.kubb/ToZod.ts'),\n sources: [\n {\n name: 'ToZod',\n value: resolveModuleSource('@kubb/plugin-zod/templates/ToZod').source,\n },\n ],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\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 fabric: this.fabric,\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 getBarrelFiles(this.fabric.files, {\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,cAAyB,YAAY;CAC5D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,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fabric
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
2
2
|
import * as OasTypes from "oas/types";
|
|
3
3
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
4
4
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -110,6 +110,21 @@ type Logger = {
|
|
|
110
110
|
type PossiblePromise<T> = Promise<T> | T;
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region ../core/src/types.d.ts
|
|
113
|
+
declare global {
|
|
114
|
+
namespace Kubb {
|
|
115
|
+
interface PluginContext {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Config used in `kubb.config.ts`
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* import { defineConfig } from '@kubb/core'
|
|
123
|
+
* export default defineConfig({
|
|
124
|
+
* ...
|
|
125
|
+
* })
|
|
126
|
+
*/
|
|
127
|
+
|
|
113
128
|
type InputPath = {
|
|
114
129
|
/**
|
|
115
130
|
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
264
279
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
265
280
|
*/
|
|
266
281
|
post?: Array<string>;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
} : {
|
|
270
|
-
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
271
|
-
});
|
|
282
|
+
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
283
|
+
};
|
|
272
284
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
273
285
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
274
286
|
/**
|
|
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
294
306
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
295
307
|
*/
|
|
296
308
|
options: TOptions['resolvedOptions'];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
309
|
+
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
|
|
312
|
+
*/
|
|
313
|
+
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
314
|
+
};
|
|
302
315
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
303
316
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
304
317
|
/**
|
|
305
318
|
* Start of the lifecycle of a plugin.
|
|
306
319
|
* @type hookParallel
|
|
307
320
|
*/
|
|
308
|
-
|
|
321
|
+
install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
309
322
|
/**
|
|
310
323
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
311
324
|
* Options can als be included.
|
|
312
325
|
* @type hookFirst
|
|
313
326
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
314
327
|
*/
|
|
315
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.
|
|
328
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
|
|
316
329
|
/**
|
|
317
330
|
* Resolve to a name based on a string.
|
|
318
331
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
320
333
|
* @example ('pet') => 'Pet'
|
|
321
334
|
*/
|
|
322
335
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
323
|
-
/**
|
|
324
|
-
* End of the plugin lifecycle.
|
|
325
|
-
* @type hookParallel
|
|
326
|
-
*/
|
|
327
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
328
336
|
};
|
|
329
337
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
330
338
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
@@ -351,24 +359,15 @@ type ResolveNameParams = {
|
|
|
351
359
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
352
360
|
fabric: Fabric;
|
|
353
361
|
config: Config;
|
|
354
|
-
/**
|
|
355
|
-
* @deprecated
|
|
356
|
-
*/
|
|
357
|
-
fileManager: FileManager;
|
|
358
362
|
pluginManager: PluginManager;
|
|
359
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<
|
|
360
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
361
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
363
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
362
364
|
logger: Logger;
|
|
363
|
-
|
|
364
|
-
* All plugins
|
|
365
|
-
*/
|
|
366
|
-
plugins: Plugin[];
|
|
365
|
+
mode: KubbFile.Mode;
|
|
367
366
|
/**
|
|
368
367
|
* Current plugin
|
|
369
368
|
*/
|
|
370
369
|
plugin: Plugin<TOptions>;
|
|
371
|
-
};
|
|
370
|
+
} & Kubb.PluginContext;
|
|
372
371
|
/**
|
|
373
372
|
* Specify the export location for the files and define the behavior of the output
|
|
374
373
|
*/
|
|
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
|
|
|
443
442
|
};
|
|
444
443
|
declare class PluginManager {
|
|
445
444
|
#private;
|
|
446
|
-
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
447
445
|
readonly events: EventEmitter<Events>;
|
|
448
446
|
readonly config: Config;
|
|
449
447
|
readonly executed: Array<Executer>;
|
|
450
448
|
readonly logger: Logger;
|
|
451
449
|
readonly options: Options$2;
|
|
452
450
|
constructor(config: Config, options: Options$2);
|
|
451
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
452
|
+
get plugins(): Array<Plugin>;
|
|
453
453
|
getFile<TOptions = object>({
|
|
454
454
|
name,
|
|
455
455
|
mode,
|
|
@@ -459,7 +459,7 @@ declare class PluginManager {
|
|
|
459
459
|
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
460
460
|
pluginKey: Plugin['key'];
|
|
461
461
|
}>;
|
|
462
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.
|
|
462
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
463
463
|
resolveName: (params: ResolveNameParams) => string;
|
|
464
464
|
/**
|
|
465
465
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
@@ -547,11 +547,9 @@ declare class PluginManager {
|
|
|
547
547
|
}): Promise<void>;
|
|
548
548
|
getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
|
|
549
549
|
getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
|
|
550
|
-
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
551
|
-
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
552
550
|
}
|
|
553
551
|
//#endregion
|
|
554
|
-
//#region ../core/src/
|
|
552
|
+
//#region ../core/src/utils/getBarrelFiles.d.ts
|
|
555
553
|
type FileMetaBase = {
|
|
556
554
|
pluginKey?: Plugin['key'];
|
|
557
555
|
};
|
|
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
|
|
|
669
667
|
/**
|
|
670
668
|
* Full qualified path.
|
|
671
669
|
*/
|
|
672
|
-
path: KubbFile.
|
|
670
|
+
path: KubbFile.Path;
|
|
673
671
|
/**
|
|
674
672
|
* When true `File.Import` will be used.
|
|
675
673
|
* When false a reference will be used inside the current file.
|
|
@@ -774,6 +772,15 @@ type Schema = {
|
|
|
774
772
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
775
773
|
//#endregion
|
|
776
774
|
//#region ../plugin-oas/src/types.d.ts
|
|
775
|
+
type Context$2 = {
|
|
776
|
+
getOas(): Promise<Oas>;
|
|
777
|
+
getBaseURL(): Promise<string | undefined>;
|
|
778
|
+
};
|
|
779
|
+
declare global {
|
|
780
|
+
namespace Kubb {
|
|
781
|
+
interface PluginContext extends Context$2 {}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
777
784
|
type ResolvePathOptions = {
|
|
778
785
|
pluginKey?: Plugin['key'];
|
|
779
786
|
group?: {
|
|
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
|
|
|
794
801
|
type Ref = {
|
|
795
802
|
propertyName: string;
|
|
796
803
|
originalName: string;
|
|
797
|
-
path: KubbFile.
|
|
804
|
+
path: KubbFile.Path;
|
|
798
805
|
pluginKey?: Plugin['key'];
|
|
799
806
|
};
|
|
800
807
|
type Refs = Record<string, Ref>;
|
|
@@ -1118,4 +1125,4 @@ type ResolvedOptions = {
|
|
|
1118
1125
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1119
1126
|
//#endregion
|
|
1120
1127
|
export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options$1 as t };
|
|
1121
|
-
//# sourceMappingURL=types-
|
|
1128
|
+
//# sourceMappingURL=types-Cb64GFh2.d.ts.map
|
|
@@ -5,7 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
5
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
6
|
import BaseOas from "oas";
|
|
7
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric
|
|
8
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -110,6 +110,21 @@ type Logger = {
|
|
|
110
110
|
type PossiblePromise<T> = Promise<T> | T;
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region ../core/src/types.d.ts
|
|
113
|
+
declare global {
|
|
114
|
+
namespace Kubb {
|
|
115
|
+
interface PluginContext {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Config used in `kubb.config.ts`
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* import { defineConfig } from '@kubb/core'
|
|
123
|
+
* export default defineConfig({
|
|
124
|
+
* ...
|
|
125
|
+
* })
|
|
126
|
+
*/
|
|
127
|
+
|
|
113
128
|
type InputPath = {
|
|
114
129
|
/**
|
|
115
130
|
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
264
279
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
265
280
|
*/
|
|
266
281
|
post?: Array<string>;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
} : {
|
|
270
|
-
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
271
|
-
});
|
|
282
|
+
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
283
|
+
};
|
|
272
284
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
273
285
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
274
286
|
/**
|
|
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
294
306
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
295
307
|
*/
|
|
296
308
|
options: TOptions['resolvedOptions'];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
309
|
+
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
|
|
312
|
+
*/
|
|
313
|
+
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
314
|
+
};
|
|
302
315
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
303
316
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
304
317
|
/**
|
|
305
318
|
* Start of the lifecycle of a plugin.
|
|
306
319
|
* @type hookParallel
|
|
307
320
|
*/
|
|
308
|
-
|
|
321
|
+
install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
309
322
|
/**
|
|
310
323
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
311
324
|
* Options can als be included.
|
|
312
325
|
* @type hookFirst
|
|
313
326
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
314
327
|
*/
|
|
315
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.
|
|
328
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
|
|
316
329
|
/**
|
|
317
330
|
* Resolve to a name based on a string.
|
|
318
331
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
320
333
|
* @example ('pet') => 'Pet'
|
|
321
334
|
*/
|
|
322
335
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
323
|
-
/**
|
|
324
|
-
* End of the plugin lifecycle.
|
|
325
|
-
* @type hookParallel
|
|
326
|
-
*/
|
|
327
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
328
336
|
};
|
|
329
337
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
330
338
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
@@ -351,24 +359,15 @@ type ResolveNameParams = {
|
|
|
351
359
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
352
360
|
fabric: Fabric;
|
|
353
361
|
config: Config;
|
|
354
|
-
/**
|
|
355
|
-
* @deprecated
|
|
356
|
-
*/
|
|
357
|
-
fileManager: FileManager;
|
|
358
362
|
pluginManager: PluginManager;
|
|
359
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<
|
|
360
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
361
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
363
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
362
364
|
logger: Logger;
|
|
363
|
-
|
|
364
|
-
* All plugins
|
|
365
|
-
*/
|
|
366
|
-
plugins: Plugin[];
|
|
365
|
+
mode: KubbFile.Mode;
|
|
367
366
|
/**
|
|
368
367
|
* Current plugin
|
|
369
368
|
*/
|
|
370
369
|
plugin: Plugin<TOptions>;
|
|
371
|
-
};
|
|
370
|
+
} & Kubb.PluginContext;
|
|
372
371
|
/**
|
|
373
372
|
* Specify the export location for the files and define the behavior of the output
|
|
374
373
|
*/
|
|
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
|
|
|
443
442
|
};
|
|
444
443
|
declare class PluginManager {
|
|
445
444
|
#private;
|
|
446
|
-
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
447
445
|
readonly events: EventEmitter<Events>;
|
|
448
446
|
readonly config: Config;
|
|
449
447
|
readonly executed: Array<Executer>;
|
|
450
448
|
readonly logger: Logger;
|
|
451
449
|
readonly options: Options$2;
|
|
452
450
|
constructor(config: Config, options: Options$2);
|
|
451
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
452
|
+
get plugins(): Array<Plugin>;
|
|
453
453
|
getFile<TOptions = object>({
|
|
454
454
|
name,
|
|
455
455
|
mode,
|
|
@@ -459,7 +459,7 @@ declare class PluginManager {
|
|
|
459
459
|
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
460
460
|
pluginKey: Plugin['key'];
|
|
461
461
|
}>;
|
|
462
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.
|
|
462
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
463
463
|
resolveName: (params: ResolveNameParams) => string;
|
|
464
464
|
/**
|
|
465
465
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
@@ -547,11 +547,9 @@ declare class PluginManager {
|
|
|
547
547
|
}): Promise<void>;
|
|
548
548
|
getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
|
|
549
549
|
getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
|
|
550
|
-
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
551
|
-
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
552
550
|
}
|
|
553
551
|
//#endregion
|
|
554
|
-
//#region ../core/src/
|
|
552
|
+
//#region ../core/src/utils/getBarrelFiles.d.ts
|
|
555
553
|
type FileMetaBase = {
|
|
556
554
|
pluginKey?: Plugin['key'];
|
|
557
555
|
};
|
|
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
|
|
|
669
667
|
/**
|
|
670
668
|
* Full qualified path.
|
|
671
669
|
*/
|
|
672
|
-
path: KubbFile.
|
|
670
|
+
path: KubbFile.Path;
|
|
673
671
|
/**
|
|
674
672
|
* When true `File.Import` will be used.
|
|
675
673
|
* When false a reference will be used inside the current file.
|
|
@@ -774,6 +772,15 @@ type Schema = {
|
|
|
774
772
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
775
773
|
//#endregion
|
|
776
774
|
//#region ../plugin-oas/src/types.d.ts
|
|
775
|
+
type Context$2 = {
|
|
776
|
+
getOas(): Promise<Oas>;
|
|
777
|
+
getBaseURL(): Promise<string | undefined>;
|
|
778
|
+
};
|
|
779
|
+
declare global {
|
|
780
|
+
namespace Kubb {
|
|
781
|
+
interface PluginContext extends Context$2 {}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
777
784
|
type ResolvePathOptions = {
|
|
778
785
|
pluginKey?: Plugin['key'];
|
|
779
786
|
group?: {
|
|
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
|
|
|
794
801
|
type Ref = {
|
|
795
802
|
propertyName: string;
|
|
796
803
|
originalName: string;
|
|
797
|
-
path: KubbFile.
|
|
804
|
+
path: KubbFile.Path;
|
|
798
805
|
pluginKey?: Plugin['key'];
|
|
799
806
|
};
|
|
800
807
|
type Refs = Record<string, Ref>;
|
|
@@ -1118,4 +1125,4 @@ type ResolvedOptions = {
|
|
|
1118
1125
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1119
1126
|
//#endregion
|
|
1120
1127
|
export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options$1 as t };
|
|
1121
|
-
//# sourceMappingURL=types-
|
|
1128
|
+
//# sourceMappingURL=types-CdCimOAr.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.2",
|
|
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",
|
|
@@ -68,20 +68,20 @@
|
|
|
68
68
|
}
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@kubb/react-fabric": "0.2.
|
|
72
|
-
"@kubb/core": "4.5.
|
|
73
|
-
"@kubb/oas": "4.5.
|
|
74
|
-
"@kubb/plugin-oas": "4.5.
|
|
75
|
-
"@kubb/plugin-ts": "4.5.
|
|
71
|
+
"@kubb/react-fabric": "0.2.19",
|
|
72
|
+
"@kubb/core": "4.5.2",
|
|
73
|
+
"@kubb/oas": "4.5.2",
|
|
74
|
+
"@kubb/plugin-oas": "4.5.2",
|
|
75
|
+
"@kubb/plugin-ts": "4.5.2"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@asteasolutions/zod-to-openapi": "^8.1.0",
|
|
79
79
|
"@hono/zod-openapi": "0.19.2",
|
|
80
80
|
"zod": "^3.25.76",
|
|
81
|
-
"@kubb/plugin-oas": "4.5.
|
|
81
|
+
"@kubb/plugin-oas": "4.5.2"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@kubb/react-fabric": "0.2.
|
|
84
|
+
"@kubb/react-fabric": "0.2.19"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=20"
|
|
@@ -6,7 +6,7 @@ import { z } from 'zod'
|
|
|
6
6
|
|
|
7
7
|
export const listPetsQueryParams = z.object({
|
|
8
8
|
limit: z.optional(z.string().describe('How many items to return at one time (max 100)')),
|
|
9
|
-
offset: z.
|
|
9
|
+
offset: z.coerce.number().int().default(0),
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import { z } from 'zod'
|
|
6
6
|
|
|
7
7
|
export const getThingsQueryParams = z.object({
|
|
8
|
-
limit: z.
|
|
9
|
-
skip: z.
|
|
8
|
+
limit: z.coerce.number().int().min(1).max(100).default(100).describe('Maximum number of things to return'),
|
|
9
|
+
skip: z.coerce.number().int().min(0).default(0).describe('Number of things to skip'),
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -40,10 +40,17 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
40
40
|
.filter(Boolean)
|
|
41
41
|
|
|
42
42
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
43
|
+
const hasProperties = Object.keys(schemaObject || {}).length > 0
|
|
44
|
+
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))
|
|
45
|
+
|
|
46
|
+
const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required
|
|
47
|
+
const optional = !required && !hasDefaults && hasProperties && name.includes('Params')
|
|
48
|
+
|
|
49
|
+
if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {
|
|
50
|
+
schemaObject.required = Object.entries(schemaObject.properties || {})
|
|
51
|
+
.filter(([_key, value]) => value && Object.hasOwn(value, 'default'))
|
|
52
|
+
.map(([key]) => key)
|
|
53
|
+
}
|
|
47
54
|
|
|
48
55
|
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)
|
|
49
56
|
const imports = schemaManager.getImports(tree)
|
package/src/plugin.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {
|
|
2
|
+
import { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'
|
|
3
3
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
4
4
|
import { resolveModuleSource } from '@kubb/core/utils'
|
|
5
|
-
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
6
5
|
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
7
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
7
|
import { operationsGenerator } from './generators'
|
|
@@ -11,7 +10,7 @@ import type { PluginZod } from './types.ts'
|
|
|
11
10
|
|
|
12
11
|
export const pluginZodName = 'plugin-zod' satisfies PluginZod['name']
|
|
13
12
|
|
|
14
|
-
export const pluginZod =
|
|
13
|
+
export const pluginZod = definePlugin<PluginZod>((options) => {
|
|
15
14
|
const {
|
|
16
15
|
output = { path: 'zod', barrelType: 'named' },
|
|
17
16
|
group,
|
|
@@ -54,6 +53,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
54
53
|
group,
|
|
55
54
|
wrapOutput,
|
|
56
55
|
version,
|
|
56
|
+
usedEnumNames: {},
|
|
57
57
|
},
|
|
58
58
|
pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
|
|
59
59
|
resolvePath(baseName, pathMode, options) {
|
|
@@ -106,12 +106,10 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
106
106
|
|
|
107
107
|
return resolvedName
|
|
108
108
|
},
|
|
109
|
-
async
|
|
110
|
-
const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
|
|
111
|
-
|
|
112
|
-
const oas = await swaggerPlugin.context.getOas()
|
|
109
|
+
async install() {
|
|
113
110
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
114
111
|
const mode = getMode(path.resolve(root, output.path))
|
|
112
|
+
const oas = await this.getOas()
|
|
115
113
|
|
|
116
114
|
if (this.plugin.options.typed && this.plugin.options.version === '3') {
|
|
117
115
|
// pre add bundled fetcher
|
|
@@ -157,7 +155,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
157
155
|
const operationFiles = await operationGenerator.build(...generators)
|
|
158
156
|
await this.addFile(...operationFiles)
|
|
159
157
|
|
|
160
|
-
const barrelFiles = await getBarrelFiles(this.
|
|
158
|
+
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
161
159
|
type: output.barrelType ?? 'named',
|
|
162
160
|
root,
|
|
163
161
|
output,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-9upbJt-4.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 },\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 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) => {\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 <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 />\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 },\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 />\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,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,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,oBAAC,KAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;IAC7F,CACD,OAAO,QAAQ;AAElB,SACE,qBAAC;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,UAAU;IAAE;IAAK;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K;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;MACjB;;IACG;;CAGZ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-T3e_E7Uy.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 },\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 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) => {\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 <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 />\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 },\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 />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,MAAa,6EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBAC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