@kubb/plugin-zod 0.0.0-canary-20251028170426 → 0.0.0-canary-20251103132818
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-DUJ6Xkpc.js → components-DpM7dEpH.js} +4 -4
- package/dist/{components-DUJ6Xkpc.js.map → components-DpM7dEpH.js.map} +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-B2hD7k6l.cjs → generators-DXfU6W14.cjs} +113 -118
- package/dist/generators-DXfU6W14.cjs.map +1 -0
- package/dist/{generators-CwEOtNXG.js → generators-pT2oV1kT.js} +115 -121
- package/dist/generators-pT2oV1kT.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +4 -4
- package/dist/generators.d.ts +4 -4
- package/dist/generators.js +2 -2
- package/dist/index.cjs +11 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/{types-CS916VXJ.d.ts → types-DBZGvY3G.d.cts} +136 -139
- package/dist/{types-Cd7g28dR.d.cts → types-Dz_P13wd.d.ts} +136 -139
- package/package.json +10 -18
- package/src/generators/index.ts +1 -1
- package/src/generators/operationsGenerator.tsx +5 -5
- package/src/generators/zodGenerator.tsx +22 -19
- package/src/plugin.ts +15 -0
- package/dist/generators-B2hD7k6l.cjs.map +0 -1
- package/dist/generators-CwEOtNXG.js.map +0 -1
- package/dist/utils.cjs +0 -0
- package/dist/utils.d.cts +0 -28
- package/dist/utils.d.ts +0 -28
- package/dist/utils.js +0 -1
- package/src/utils/index.ts +0 -1
- /package/{src/utils → templates}/ToZod.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
1
|
+
import { usePluginManager } from '@kubb/core/hooks'
|
|
2
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
3
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
4
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
5
|
import { File } from '@kubb/react-fabric'
|
|
@@ -8,15 +8,15 @@ import type { PluginZod } from '../types'
|
|
|
8
8
|
|
|
9
9
|
export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
10
10
|
name: 'operations',
|
|
11
|
-
Operations({ operations }) {
|
|
11
|
+
Operations({ operations, generator, plugin }) {
|
|
12
12
|
const {
|
|
13
13
|
key: pluginKey,
|
|
14
14
|
options: { output, importPath },
|
|
15
|
-
} =
|
|
15
|
+
} = plugin
|
|
16
16
|
const pluginManager = usePluginManager()
|
|
17
17
|
|
|
18
18
|
const oas = useOas()
|
|
19
|
-
const { getFile, groupSchemasByName } = useOperationManager()
|
|
19
|
+
const { getFile, groupSchemasByName } = useOperationManager(generator)
|
|
20
20
|
|
|
21
21
|
const name = 'operations'
|
|
22
22
|
const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { useMode, usePluginManager } from '@kubb/core/hooks'
|
|
3
|
+
import { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
4
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
4
5
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
5
6
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
6
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { File } from '@kubb/react-fabric'
|
|
8
|
+
import { File, Fragment } from '@kubb/react-fabric'
|
|
8
9
|
import { Zod } from '../components'
|
|
9
10
|
import type { PluginZod } from '../types'
|
|
10
11
|
|
|
11
12
|
export const zodGenerator = createReactGenerator<PluginZod>({
|
|
12
13
|
name: 'zod',
|
|
13
|
-
Operation({ operation,
|
|
14
|
-
const {
|
|
14
|
+
Operation({ config, operation, generator, plugin }) {
|
|
15
|
+
const {
|
|
16
|
+
options,
|
|
17
|
+
options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version },
|
|
18
|
+
} = plugin
|
|
15
19
|
|
|
16
|
-
const plugin = usePlugin<PluginZod>()
|
|
17
20
|
const mode = useMode()
|
|
18
21
|
const pluginManager = usePluginManager()
|
|
19
22
|
|
|
20
23
|
const oas = useOas()
|
|
21
|
-
const { getSchemas, getFile, getGroup } = useOperationManager()
|
|
24
|
+
const { getSchemas, getFile, getGroup } = useOperationManager(generator)
|
|
22
25
|
const schemaManager = useSchemaManager()
|
|
23
26
|
|
|
24
27
|
const file = getFile(operation)
|
|
25
28
|
const schemas = getSchemas(operation)
|
|
26
29
|
const schemaGenerator = new SchemaGenerator(options, {
|
|
27
|
-
fabric:
|
|
30
|
+
fabric: generator.context.fabric,
|
|
28
31
|
oas,
|
|
29
32
|
plugin,
|
|
30
33
|
pluginManager,
|
|
@@ -36,7 +39,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
36
39
|
.flat()
|
|
37
40
|
.filter(Boolean)
|
|
38
41
|
|
|
39
|
-
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType
|
|
42
|
+
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {
|
|
40
43
|
// hack so Params can be optional when needed
|
|
41
44
|
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required
|
|
42
45
|
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)
|
|
@@ -66,9 +69,9 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
return (
|
|
69
|
-
<
|
|
72
|
+
<Fragment>
|
|
70
73
|
{typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
|
|
71
|
-
{typed &&
|
|
74
|
+
{typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}
|
|
72
75
|
{imports.map((imp) => (
|
|
73
76
|
<File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />
|
|
74
77
|
))}
|
|
@@ -86,7 +89,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
86
89
|
version={plugin.options.version}
|
|
87
90
|
emptySchemaType={plugin.options.emptySchemaType}
|
|
88
91
|
/>
|
|
89
|
-
</
|
|
92
|
+
</Fragment>
|
|
90
93
|
)
|
|
91
94
|
}
|
|
92
95
|
|
|
@@ -103,13 +106,11 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
103
106
|
</File>
|
|
104
107
|
)
|
|
105
108
|
},
|
|
106
|
-
Schema({ schema,
|
|
107
|
-
const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options
|
|
108
|
-
|
|
109
|
+
Schema({ config, schema, plugin }) {
|
|
109
110
|
const { getName, getFile, getImports } = useSchemaManager()
|
|
110
111
|
const {
|
|
111
|
-
options: { output, emptySchemaType },
|
|
112
|
-
} =
|
|
112
|
+
options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version },
|
|
113
|
+
} = plugin
|
|
113
114
|
const pluginManager = usePluginManager()
|
|
114
115
|
const oas = useOas()
|
|
115
116
|
|
|
@@ -136,7 +137,9 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
136
137
|
>
|
|
137
138
|
<File.Import name={['z']} path={importPath} />
|
|
138
139
|
{typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
|
|
139
|
-
{typed &&
|
|
140
|
+
{typed && version === '3' && (
|
|
141
|
+
<File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />
|
|
142
|
+
)}
|
|
140
143
|
{imports.map((imp) => (
|
|
141
144
|
<File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />
|
|
142
145
|
))}
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { createPlugin, type Group, getBarrelFiles, getMode, PackageManager, type Plugin, PluginManager } from '@kubb/core'
|
|
3
3
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
4
|
+
import { resolveModuleSource } from '@kubb/core/utils'
|
|
4
5
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
5
6
|
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
6
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -112,6 +113,20 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
112
113
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
113
114
|
const mode = getMode(path.resolve(root, output.path))
|
|
114
115
|
|
|
116
|
+
if (this.plugin.options.typed && this.plugin.options.version === '3') {
|
|
117
|
+
// pre add bundled fetcher
|
|
118
|
+
await this.addFile({
|
|
119
|
+
baseName: 'ToZod.ts',
|
|
120
|
+
path: path.resolve(root, '.kubb/ToZod.ts'),
|
|
121
|
+
sources: [
|
|
122
|
+
{
|
|
123
|
+
name: 'ToZod',
|
|
124
|
+
value: resolveModuleSource('@kubb/plugin-zod/templates/ToZod').source,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
115
130
|
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
116
131
|
fabric: this.fabric,
|
|
117
132
|
oas,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-B2hD7k6l.cjs","names":["SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","Zod","File","Operations"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { useMode, usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { 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 } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options, instance }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const plugin = usePlugin<PluginZod>()\n const mode = useMode()\n const pluginManager = usePluginManager()\n\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 fabric: instance.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, 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 && plugin.options.version === '3' && <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 options: { output, emptySchemaType },\n } = usePlugin<PluginZod>()\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 && <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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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 }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = usePlugin<PluginZod>()\n const pluginManager = usePluginManager()\n\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 <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAUA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,YAAY;EAC1C,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,eAAe;EAE1E,MAAM,2CAA+B;EACrC,MAAM,uCAAgB;EACtB,MAAM,yDAAkC;EAExC,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,+DAAkC;EAC/D,MAAM,+DAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,kCAAgB,SAAS;GACnD,QAAQ,SAAS,QAAQ;GACzB;GACA;GACA;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,sBAAsB,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGC,aAAgC,MAAc;GAElI,MAAM,WAAW,MAAM,QAAQ,cAAc,SAAS,GAAG,CAAC,CAAC,aAAa,SAAS,SAAS,CAAC,CAAC,cAAc;GAC1G,MAAM,eAAe,OAAO,OAAO,aAAa,cAAc,EAAE,CAAC,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,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,yDAACC,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,yBAAK;KAAO;KAAW,MAAM,CAAC,IAAI;KAAE,MAAM;MAAc;IACxD;IACD,yDAACC;KAAiB;KAAM,YAAY;MAAyB;;IACxD;;CAGZ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CwEOtNXG.js","names":["options"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { useMode, usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { 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 } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options, instance }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const plugin = usePlugin<PluginZod>()\n const mode = useMode()\n const pluginManager = usePluginManager()\n\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 fabric: instance.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, 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 && plugin.options.version === '3' && <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 options: { output, emptySchemaType },\n } = usePlugin<PluginZod>()\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 && <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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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 }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = usePlugin<PluginZod>()\n const pluginManager = usePluginManager()\n\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 <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,YAAY;EAC1C,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,eAAe;EAE1E,MAAM,SAAS,WAAsB;EACrC,MAAM,OAAO,SAAS;EACtB,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS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xD;;CAGZ,CAAC"}
|
package/dist/utils.cjs
DELETED
|
File without changes
|
package/dist/utils.d.cts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/ToZod.d.ts
|
|
4
|
-
|
|
5
|
-
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
6
|
-
type nonoptional<T> = T extends undefined ? never : T;
|
|
7
|
-
type nonnullable<T> = T extends null ? never : T;
|
|
8
|
-
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
9
|
-
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 {
|
|
10
|
-
[k: string]: any;
|
|
11
|
-
} ? 'object' : 'rest';
|
|
12
|
-
type ToZod<T> = {
|
|
13
|
-
any: z.ZodAny;
|
|
14
|
-
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
15
|
-
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
16
|
-
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
17
|
-
string: z.ZodString;
|
|
18
|
-
bigint: z.ZodBigInt;
|
|
19
|
-
number: z.ZodNumber;
|
|
20
|
-
boolean: z.ZodBoolean;
|
|
21
|
-
date: z.ZodDate;
|
|
22
|
-
object: z.ZodObject<{ [K in keyof T]: T[K] }, 'passthrough', unknown, T>;
|
|
23
|
-
rest: z.ZodType<T>;
|
|
24
|
-
}[zodKey<T>];
|
|
25
|
-
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
26
|
-
//#endregion
|
|
27
|
-
export { type ToZod, type ZodShape };
|
|
28
|
-
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/ToZod.d.ts
|
|
4
|
-
|
|
5
|
-
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
6
|
-
type nonoptional<T> = T extends undefined ? never : T;
|
|
7
|
-
type nonnullable<T> = T extends null ? never : T;
|
|
8
|
-
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
9
|
-
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 {
|
|
10
|
-
[k: string]: any;
|
|
11
|
-
} ? 'object' : 'rest';
|
|
12
|
-
type ToZod<T> = {
|
|
13
|
-
any: z.ZodAny;
|
|
14
|
-
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
15
|
-
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
16
|
-
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
17
|
-
string: z.ZodString;
|
|
18
|
-
bigint: z.ZodBigInt;
|
|
19
|
-
number: z.ZodNumber;
|
|
20
|
-
boolean: z.ZodBoolean;
|
|
21
|
-
date: z.ZodDate;
|
|
22
|
-
object: z.ZodObject<{ [K in keyof T]: T[K] }, 'passthrough', unknown, T>;
|
|
23
|
-
rest: z.ZodType<T>;
|
|
24
|
-
}[zodKey<T>];
|
|
25
|
-
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
26
|
-
//#endregion
|
|
27
|
-
export { type ToZod, type ZodShape };
|
|
28
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { ToZod, ZodShape } from './ToZod.ts'
|
|
File without changes
|