@kubb/plugin-zod 5.0.0-alpha.9 → 5.0.0-beta.100

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.
Files changed (41) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -23
  3. package/dist/index.cjs +1964 -133
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +482 -6
  6. package/dist/index.js +1950 -132
  7. package/dist/index.js.map +1 -1
  8. package/package.json +36 -81
  9. package/dist/components-B7zUFnAm.cjs +0 -890
  10. package/dist/components-B7zUFnAm.cjs.map +0 -1
  11. package/dist/components-eECfXVou.js +0 -842
  12. package/dist/components-eECfXVou.js.map +0 -1
  13. package/dist/components.cjs +0 -4
  14. package/dist/components.d.ts +0 -56
  15. package/dist/components.js +0 -2
  16. package/dist/generators-BjPDdJUz.cjs +0 -301
  17. package/dist/generators-BjPDdJUz.cjs.map +0 -1
  18. package/dist/generators-lTWPS6oN.js +0 -290
  19. package/dist/generators-lTWPS6oN.js.map +0 -1
  20. package/dist/generators.cjs +0 -4
  21. package/dist/generators.d.ts +0 -508
  22. package/dist/generators.js +0 -2
  23. package/dist/templates/ToZod.source.cjs +0 -7
  24. package/dist/templates/ToZod.source.cjs.map +0 -1
  25. package/dist/templates/ToZod.source.d.ts +0 -7
  26. package/dist/templates/ToZod.source.js +0 -6
  27. package/dist/templates/ToZod.source.js.map +0 -1
  28. package/dist/types-CoCoOc2u.d.ts +0 -172
  29. package/src/components/Operations.tsx +0 -70
  30. package/src/components/Zod.tsx +0 -142
  31. package/src/components/index.ts +0 -2
  32. package/src/generators/index.ts +0 -2
  33. package/src/generators/operationsGenerator.tsx +0 -50
  34. package/src/generators/zodGenerator.tsx +0 -202
  35. package/src/index.ts +0 -2
  36. package/src/parser.ts +0 -909
  37. package/src/plugin.ts +0 -183
  38. package/src/templates/ToZod.source.ts +0 -4
  39. package/src/types.ts +0 -172
  40. package/templates/ToZod.ts +0 -61
  41. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -1,172 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
3
- import { Exclude, Include, Override, ResolvePathOptions, Schema } from "@kubb/plugin-oas";
4
- import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
5
- import { Oas, SchemaObject, contentType } from "@kubb/oas";
6
-
7
- //#region src/types.d.ts
8
- type Options = {
9
- /**
10
- * @default 'zod'
11
- */
12
- output?: Output<Oas>;
13
- /**
14
- * Define which contentType should be used.
15
- * By default, the first JSON valid mediaType is used
16
- */
17
- contentType?: contentType;
18
- /**
19
- * Group the Zod schemas based on the provided name.
20
- */
21
- group?: Group;
22
- /**
23
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
24
- */
25
- exclude?: Array<Exclude>;
26
- /**
27
- * Array containing include parameters to include tags/operations/methods/paths.
28
- */
29
- include?: Array<Include>;
30
- /**
31
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
32
- */
33
- override?: Array<Override<ResolvedOptions>>;
34
- /**
35
- * Path to Zod
36
- * It used as `import { z } from '${importPath}'`.
37
- * Accepts relative and absolute paths.
38
- * Path is used as-is; relative paths are based on the generated file location.
39
- * @default 'zod'
40
- */
41
- importPath?: string;
42
- /**
43
- * Choose to use date or datetime as JavaScript Date instead of string.
44
- * - false falls back to a simple z.string() format.
45
- * - 'string' uses z.string().datetime() for datetime validation.
46
- * - 'stringOffset' uses z.string().datetime({ offset: true }) for datetime with timezone offset validation.
47
- * - 'stringLocal' uses z.string().datetime({ local: true }) for local datetime validation.
48
- * - 'date' uses z.date() for JavaScript Date objects.
49
- * @default 'string'
50
- * @note 'stringOffset' will become the default in Kubb v3.
51
- */
52
- dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
53
- /**
54
- * Choose to use `number` or `bigint` for integer fields with `int64` format.
55
- * - 'number' uses the JavaScript `number` type (matches JSON.parse() runtime behavior).
56
- * - 'bigint' uses the JavaScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
57
- * @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
58
- * @default 'number'
59
- */
60
- integerType?: 'number' | 'bigint';
61
- /**
62
- * Which type to use when the Swagger/OpenAPI file is not providing more information.
63
- * - 'any' allows any value.
64
- * - 'unknown' requires type narrowing before use.
65
- * - 'void' represents no value.
66
- * @default 'any'
67
- */
68
- unknownType?: 'any' | 'unknown' | 'void';
69
- /**
70
- * Which type to use for empty schema values.
71
- * - 'any' allows any value.
72
- * - 'unknown' requires type narrowing before use.
73
- * - 'void' represents no value.
74
- * @default `unknownType`
75
- */
76
- emptySchemaType?: 'any' | 'unknown' | 'void';
77
- /**
78
- * Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
79
- */
80
- typed?: boolean;
81
- /**
82
- * Return Zod generated schema as type with z.infer<TYPE>
83
- */
84
- inferred?: boolean;
85
- /**
86
- * Use of z.coerce.string() instead of z.string()
87
- * can also be an object to enable coercion for dates, strings, and numbers
88
- */
89
- coercion?: boolean | {
90
- dates?: boolean;
91
- strings?: boolean;
92
- numbers?: boolean;
93
- };
94
- operations?: boolean;
95
- mapper?: Record<string, string>;
96
- transformers?: {
97
- /**
98
- * Customize the names based on the type that is provided by the plugin.
99
- */
100
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
101
- /**
102
- * Receive schema and baseName(propertyName) and return FakerMeta array
103
- * TODO TODO add docs
104
- * @beta
105
- */
106
- schema?: (props: {
107
- schema: SchemaObject | null;
108
- name: string | null;
109
- parentName: string | null;
110
- }, defaultSchemas: Schema[]) => Schema[] | undefined;
111
- };
112
- /**
113
- * Which version of Zod should be used.
114
- * - '3' uses Zod v3.x syntax and features.
115
- * - '4' uses Zod v4.x syntax and features.
116
- * @default '3'
117
- */
118
- version?: '3' | '4';
119
- /**
120
- * Which Zod GUID validator to use for OpenAPI `format: uuid`.
121
- * - 'uuid' uses UUID validation.
122
- * - 'guid' uses GUID validation (Zod v4 only).
123
- * @default 'uuid'
124
- */
125
- guidType?: 'uuid' | 'guid';
126
- /**
127
- * Use Zod Mini's functional API for better tree-shaking support.
128
- * When enabled, generates functional syntax (e.g., `z.optional(z.string())`) instead of chainable methods (e.g., `z.string().optional()`).
129
- * Requires Zod v4 or later. When `mini: true`, `version` is set to '4' and `importPath` will default to 'zod/mini'.
130
- * @default false
131
- */
132
- mini?: boolean;
133
- /**
134
- * Callback function to wrap the output of the generated zod schema
135
- *
136
- * This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
137
- * or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
138
- * while going from openapi -> zod -> openapi
139
- */
140
- wrapOutput?: (arg: {
141
- output: string;
142
- schema: SchemaObject;
143
- }) => string | undefined;
144
- /**
145
- * Define some generators next to the zod generators
146
- */
147
- generators?: Array<Generator$1<PluginZod>>;
148
- };
149
- type ResolvedOptions = {
150
- output: Output<Oas>;
151
- group: Options['group'];
152
- override: NonNullable<Options['override']>;
153
- transformers: NonNullable<Options['transformers']>;
154
- dateType: NonNullable<Options['dateType']>;
155
- integerType: NonNullable<Options['integerType']>;
156
- unknownType: NonNullable<Options['unknownType']>;
157
- emptySchemaType: NonNullable<Options['emptySchemaType']>;
158
- typed: NonNullable<Options['typed']>;
159
- inferred: NonNullable<Options['inferred']>;
160
- mapper: NonNullable<Options['mapper']>;
161
- importPath: NonNullable<Options['importPath']>;
162
- coercion: NonNullable<Options['coercion']>;
163
- operations: NonNullable<Options['operations']>;
164
- wrapOutput: Options['wrapOutput'];
165
- version: NonNullable<Options['version']>;
166
- guidType: NonNullable<Options['guidType']>;
167
- mini: NonNullable<Options['mini']>;
168
- };
169
- type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
170
- //#endregion
171
- export { PluginZod as n, Options as t };
172
- //# sourceMappingURL=types-CoCoOc2u.d.ts.map
@@ -1,70 +0,0 @@
1
- import { stringifyObject } from '@internals/utils'
2
- import type { HttpMethod, Operation } from '@kubb/oas'
3
- import type { SchemaNames } from '@kubb/plugin-oas/hooks'
4
- import { Const, File, Type } from '@kubb/react-fabric'
5
- import type { FabricReactNode } from '@kubb/react-fabric/types'
6
-
7
- type Props = {
8
- name: string
9
- operations: Array<{ operation: Operation; data: SchemaNames }>
10
- }
11
-
12
- export function Operations({ name, operations }: Props): FabricReactNode {
13
- const operationsJSON = operations.reduce(
14
- (prev, acc) => {
15
- prev[`"${acc.operation.getOperationId()}"`] = acc.data
16
-
17
- return prev
18
- },
19
- {} as Record<string, unknown>,
20
- )
21
-
22
- const pathsJSON = operations.reduce(
23
- (prev, acc) => {
24
- prev[`"${acc.operation.path}"`] = {
25
- ...(prev[`"${acc.operation.path}"`] || ({} as Record<HttpMethod, string>)),
26
- [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`,
27
- }
28
-
29
- return prev
30
- },
31
- {} as Record<string, Record<HttpMethod, string>>,
32
- )
33
-
34
- return (
35
- <>
36
- <File.Source name="OperationSchema" isExportable isIndexable>
37
- <Type name="OperationSchema" export>{`{
38
- readonly request: z.ZodTypeAny | undefined;
39
- readonly parameters: {
40
- readonly path: z.ZodTypeAny | undefined;
41
- readonly query: z.ZodTypeAny | undefined;
42
- readonly header: z.ZodTypeAny | undefined;
43
- };
44
- readonly responses: {
45
- readonly [status: number]: z.ZodTypeAny;
46
- readonly default: z.ZodTypeAny;
47
- };
48
- readonly errors: {
49
- readonly [status: number]: z.ZodTypeAny;
50
- };
51
- }`}</Type>
52
- </File.Source>
53
- <File.Source name="OperationsMap" isExportable isIndexable>
54
- <Type name="OperationsMap" export>
55
- {'Record<string, OperationSchema>'}
56
- </Type>
57
- </File.Source>
58
- <File.Source name={name} isExportable isIndexable>
59
- <Const export name={name} asConst>
60
- {`{${stringifyObject(operationsJSON)}}`}
61
- </Const>
62
- </File.Source>
63
- <File.Source name={'paths'} isExportable isIndexable>
64
- <Const export name={'paths'} asConst>
65
- {`{${stringifyObject(pathsJSON)}}`}
66
- </Const>
67
- </File.Source>
68
- </>
69
- )
70
- }
@@ -1,142 +0,0 @@
1
- import { jsStringEscape } from '@internals/utils'
2
- import type { SchemaObject } from '@kubb/oas'
3
- import { isKeyword, type Schema, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
4
- import { Const, File, Type } from '@kubb/react-fabric'
5
- import type { FabricReactNode } from '@kubb/react-fabric/types'
6
- import * as parserZod from '../parser.ts'
7
- import type { PluginZod } from '../types.ts'
8
-
9
- type Props = {
10
- name: string
11
- typeName?: string
12
- inferTypeName?: string
13
- tree: Array<Schema>
14
- schema: SchemaObject
15
- description?: string
16
- coercion: PluginZod['resolvedOptions']['coercion']
17
- mapper: PluginZod['resolvedOptions']['mapper']
18
- keysToOmit?: string[]
19
- wrapOutput?: PluginZod['resolvedOptions']['wrapOutput']
20
- version: '3' | '4'
21
- guidType: PluginZod['resolvedOptions']['guidType']
22
- emptySchemaType: PluginZod['resolvedOptions']['emptySchemaType']
23
- mini?: boolean
24
- }
25
-
26
- export function Zod({
27
- name,
28
- typeName,
29
- tree,
30
- schema,
31
- inferTypeName,
32
- mapper,
33
- coercion,
34
- keysToOmit,
35
- description,
36
- wrapOutput,
37
- version,
38
- guidType,
39
- emptySchemaType,
40
- mini = false,
41
- }: Props): FabricReactNode {
42
- const hasTuple = !!SchemaGenerator.find(tree, schemaKeywords.tuple)
43
-
44
- const schemas = parserZod.sort(tree).filter((item) => {
45
- if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
46
- return false
47
- }
48
-
49
- return true
50
- })
51
-
52
- // In mini mode, filter out modifiers from the main schema parsing
53
- const baseSchemas = mini ? parserZod.filterMiniModifiers(schemas) : schemas
54
-
55
- const output = baseSchemas
56
- .map((schemaKeyword, index) => {
57
- const siblings = baseSchemas.filter((_, i) => i !== index)
58
-
59
- return parserZod.parse({ schema, parent: undefined, current: schemaKeyword, siblings, name }, { mapper, coercion, wrapOutput, version, guidType, mini })
60
- })
61
- .filter(Boolean)
62
- .join('')
63
-
64
- let suffix = ''
65
- const firstSchema = schemas.at(0)
66
- const lastSchema = schemas.at(-1)
67
-
68
- if (!mini && lastSchema && isKeyword(lastSchema, schemaKeywords.nullable)) {
69
- if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) {
70
- if (version === '3') {
71
- suffix = '.unwrap().schema.unwrap()'
72
- } else {
73
- suffix = '.unwrap().unwrap()'
74
- }
75
- } else {
76
- suffix = '.unwrap()'
77
- }
78
- } else if (!mini) {
79
- if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) {
80
- if (version === '3') {
81
- suffix = '.schema'
82
- } else {
83
- suffix = '.unwrap()'
84
- }
85
- }
86
- }
87
-
88
- const emptyValue = parserZod.parse(
89
- {
90
- schema,
91
- parent: undefined,
92
- current: {
93
- keyword: schemaKeywords[emptySchemaType],
94
- },
95
- siblings: [],
96
- },
97
- { mapper, coercion, wrapOutput, version, guidType, mini },
98
- )
99
-
100
- let baseSchemaOutput =
101
- [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `'${key}': true`).join(',')} })` : undefined].filter(Boolean).join('') ||
102
- emptyValue ||
103
- ''
104
-
105
- // For mini mode, wrap the output with modifiers using the parser function
106
- if (mini) {
107
- baseSchemaOutput = parserZod.wrapWithMiniModifiers(baseSchemaOutput, parserZod.extractMiniModifiers(schemas))
108
- }
109
-
110
- const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema }) || baseSchemaOutput : baseSchemaOutput
111
- const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ${version === '4' ? 'z.ZodType' : 'ToZod'}<${typeName}>` : wrappedSchemaOutput
112
-
113
- return (
114
- <>
115
- <File.Source name={name} isExportable isIndexable>
116
- <Const
117
- export
118
- name={name}
119
- JSDoc={{
120
- comments: [description ? `@description ${jsStringEscape(description)}` : undefined].filter(Boolean),
121
- }}
122
- >
123
- {finalOutput}
124
- </Const>
125
- </File.Source>
126
- {inferTypeName && (
127
- <File.Source name={inferTypeName} isExportable isIndexable isTypeOnly>
128
- {typeName && (
129
- <Type export name={inferTypeName}>
130
- {typeName}
131
- </Type>
132
- )}
133
- {!typeName && (
134
- <Type export name={inferTypeName}>
135
- {`z.infer<typeof ${name}>`}
136
- </Type>
137
- )}
138
- </File.Source>
139
- )}
140
- </>
141
- )
142
- }
@@ -1,2 +0,0 @@
1
- export { Operations } from './Operations.tsx'
2
- export { Zod } from './Zod.tsx'
@@ -1,2 +0,0 @@
1
- export { operationsGenerator } from './operationsGenerator.tsx'
2
- export { zodGenerator } from './zodGenerator.tsx'
@@ -1,50 +0,0 @@
1
- import { usePluginDriver } from '@kubb/core/hooks'
2
- import { createReactGenerator } from '@kubb/plugin-oas/generators'
3
- import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
4
- import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
5
- import { File } from '@kubb/react-fabric'
6
- import { Operations } from '../components/Operations.tsx'
7
- import type { PluginZod } from '../types'
8
-
9
- export const operationsGenerator = createReactGenerator<PluginZod>({
10
- name: 'operations',
11
- Operations({ operations, generator, plugin }) {
12
- const {
13
- name: pluginName,
14
- options: { output, importPath },
15
- } = plugin
16
- const driver = usePluginDriver()
17
-
18
- const oas = useOas()
19
- const { getFile, groupSchemasByName } = useOperationManager(generator)
20
-
21
- const name = 'operations'
22
- const file = driver.getFile({ name, extname: '.ts', pluginName })
23
-
24
- const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))
25
-
26
- const imports = Object.entries(transformedOperations)
27
- .map(([key, { data, operation }]) => {
28
- const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)
29
-
30
- return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />
31
- })
32
- .filter(Boolean)
33
-
34
- const isZodImport = importPath === 'zod' || importPath === 'zod/mini'
35
-
36
- return (
37
- <File
38
- baseName={file.baseName}
39
- path={file.path}
40
- meta={file.meta}
41
- banner={getBanner({ oas, output, config: driver.config })}
42
- footer={getFooter({ oas, output })}
43
- >
44
- <File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />
45
- {imports}
46
- <Operations name={name} operations={transformedOperations} />
47
- </File>
48
- )
49
- },
50
- })
@@ -1,202 +0,0 @@
1
- import path from 'node:path'
2
- import { useMode, usePluginDriver } from '@kubb/core/hooks'
3
- import { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
4
- import { createReactGenerator } from '@kubb/plugin-oas/generators'
5
- import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
6
- import { getBanner, getFooter, getImports } from '@kubb/plugin-oas/utils'
7
- import { pluginTsName } from '@kubb/plugin-ts'
8
- import { File } from '@kubb/react-fabric'
9
- import { Zod } from '../components'
10
- import type { PluginZod } from '../types'
11
-
12
- export const zodGenerator = createReactGenerator<PluginZod>({
13
- name: 'zod',
14
- Operation({ config, operation, generator, plugin }) {
15
- const {
16
- options,
17
- options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, guidType, mini },
18
- } = plugin
19
-
20
- const mode = useMode()
21
- const driver = usePluginDriver()
22
-
23
- const oas = useOas()
24
- const { getSchemas, getFile, getGroup } = useOperationManager(generator)
25
- const schemaManager = useSchemaManager()
26
-
27
- const file = getFile(operation)
28
- const schemas = getSchemas(operation)
29
- const schemaGenerator = new SchemaGenerator(options, {
30
- fabric: generator.context.fabric,
31
- oas,
32
- plugin,
33
- driver,
34
- events: generator.context.events,
35
- mode,
36
- override: options.override,
37
- })
38
-
39
- const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
40
- .flat()
41
- .filter(Boolean)
42
- const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')
43
-
44
- const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {
45
- let schemaObject = schemaOriginal
46
- let keysToOmit = keysToOmitOriginal
47
-
48
- if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
49
- schemaObject = structuredClone(schemaOriginal)
50
-
51
- // Remove $ref so the schema parser generates inline schema instead of a reference
52
- delete schemaObject.$ref
53
-
54
- for (const key of keysToOmitOriginal) {
55
- delete schemaObject.properties?.[key]
56
- }
57
-
58
- if (Array.isArray(schemaObject.required)) {
59
- schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))
60
- }
61
-
62
- keysToOmit = undefined
63
- }
64
-
65
- const hasProperties = Object.keys(schemaObject || {}).length > 0
66
- const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))
67
-
68
- const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required
69
- const optional = !required && !hasDefaults && hasProperties && name.includes('Params')
70
-
71
- if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {
72
- schemaObject.required = Object.entries(schemaObject.properties || {})
73
- .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))
74
- .map(([key]) => key)
75
- }
76
-
77
- const tree = [
78
- ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),
79
- optional ? { keyword: schemaKeywords.optional } : undefined,
80
- ].filter(Boolean)
81
- const imports = getImports(tree)
82
- const group = options.operation ? getGroup(options.operation) : undefined
83
-
84
- const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion
85
-
86
- const zod = {
87
- name: schemaManager.getName(name, { type: 'function' }),
88
- inferTypeName: schemaManager.getName(name, { type: 'type' }),
89
- file: schemaManager.getFile(name),
90
- }
91
-
92
- const type = {
93
- name: schemaManager.getName(name, {
94
- type: 'type',
95
- pluginName: pluginTsName,
96
- }),
97
- file: schemaManager.getFile(options.operationName || name, {
98
- pluginName: pluginTsName,
99
- group,
100
- }),
101
- }
102
-
103
- return (
104
- <>
105
- {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
106
- {imports.map((imp) => (
107
- <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />
108
- ))}
109
- <Zod
110
- name={zod.name}
111
- typeName={typed ? type.name : undefined}
112
- inferTypeName={inferred ? zod.inferTypeName : undefined}
113
- description={description}
114
- tree={tree}
115
- schema={schemaObject}
116
- mapper={mapper}
117
- coercion={coercion}
118
- keysToOmit={keysToOmit}
119
- wrapOutput={wrapOutput}
120
- version={plugin.options.version}
121
- guidType={guidType}
122
- emptySchemaType={plugin.options.emptySchemaType}
123
- mini={mini}
124
- />
125
- </>
126
- )
127
- }
128
-
129
- const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'
130
-
131
- return (
132
- <File
133
- baseName={file.baseName}
134
- path={file.path}
135
- meta={file.meta}
136
- banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}
137
- footer={getFooter({ oas, output: plugin.options.output })}
138
- >
139
- <File.Import name={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />
140
- {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}
141
- {operationSchemas.map(mapOperationSchema)}
142
- </File>
143
- )
144
- },
145
- Schema({ config, schema, plugin }) {
146
- const { getName, getFile } = useSchemaManager()
147
- const {
148
- options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini },
149
- } = plugin
150
- const driver = usePluginDriver()
151
- const oas = useOas()
152
-
153
- const imports = getImports(schema.tree)
154
-
155
- const zod = {
156
- name: getName(schema.name, { type: 'function' }),
157
- inferTypeName: getName(schema.name, { type: 'type' }),
158
- file: getFile(schema.name),
159
- }
160
-
161
- const type = {
162
- name: getName(schema.name, { type: 'type', pluginName: pluginTsName }),
163
- file: getFile(schema.name, { pluginName: pluginTsName }),
164
- }
165
-
166
- const isZodImport = importPath === 'zod' || importPath === 'zod/mini'
167
- const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')
168
-
169
- return (
170
- <File
171
- baseName={zod.file.baseName}
172
- path={zod.file.path}
173
- meta={zod.file.meta}
174
- banner={getBanner({ oas, output, config: driver.config })}
175
- footer={getFooter({ oas, output })}
176
- >
177
- <File.Import name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />
178
- {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
179
- {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}
180
- {imports.map((imp) => (
181
- <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />
182
- ))}
183
-
184
- <Zod
185
- name={zod.name}
186
- typeName={typed ? type.name : undefined}
187
- inferTypeName={inferred ? zod.inferTypeName : undefined}
188
- description={schema.value.description}
189
- tree={schema.tree}
190
- schema={schema.value}
191
- mapper={mapper}
192
- coercion={coercion}
193
- wrapOutput={wrapOutput}
194
- version={version}
195
- guidType={guidType}
196
- emptySchemaType={emptySchemaType}
197
- mini={mini}
198
- />
199
- </File>
200
- )
201
- },
202
- })
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { pluginZod, pluginZodName } from './plugin.ts'
2
- export type { PluginZod } from './types.ts'