@kubb/plugin-zod 5.0.0-alpha.34 → 5.0.0-alpha.35

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.
@@ -1,7 +1,5 @@
1
- import { caseParams } from '@kubb/ast'
2
- import type { SchemaNode } from '@kubb/ast/types'
3
- import { defineGenerator } from '@kubb/core'
4
- import { File } from '@kubb/renderer-jsx'
1
+ import { ast, defineGenerator } from '@kubb/core'
2
+ import { File, jsxRenderer } from '@kubb/renderer-jsx'
5
3
  import { Operations } from '../components/Operations.tsx'
6
4
  import { Zod } from '../components/Zod.tsx'
7
5
  import { ZOD_NAMESPACE_IMPORTS } from '../constants.ts'
@@ -12,15 +10,16 @@ import { buildSchemaNames } from '../utils.ts'
12
10
 
13
11
  export const zodGenerator = defineGenerator<PluginZod>({
14
12
  name: 'zod',
15
- schema(node, options) {
16
- const { adapter, config, resolver, root } = this
17
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options
13
+ renderer: jsxRenderer,
14
+ schema(node, ctx) {
15
+ const { adapter, config, resolver, root } = ctx
16
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options
18
17
 
19
18
  if (!node.name) {
20
19
  return
21
20
  }
22
21
 
23
- const mode = this.getMode(output)
22
+ const mode = ctx.getMode(output)
24
23
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath as 'zod' | 'zod/mini')
25
24
 
26
25
  const imports = adapter.getImports(node, (schemaName) => ({
@@ -54,20 +53,20 @@ export const zodGenerator = defineGenerator<PluginZod>({
54
53
  </File>
55
54
  )
56
55
  },
57
- operation(node, options) {
58
- const { adapter, config, resolver, root } = this
59
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options
56
+ operation(node, ctx) {
57
+ const { adapter, config, resolver, root } = ctx
58
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options
60
59
 
61
- const mode = this.getMode(output)
60
+ const mode = ctx.getMode(output)
62
61
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath as 'zod' | 'zod/mini')
63
62
 
64
- const params = caseParams(node.parameters, paramsCasing)
63
+ const params = ast.caseParams(node.parameters, paramsCasing)
65
64
 
66
65
  const meta = {
67
66
  file: resolver.resolveFile({ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
68
67
  } as const
69
68
 
70
- function renderSchemaEntry({ schema, name, keysToOmit }: { schema: SchemaNode | null; name: string; keysToOmit?: Array<string> }) {
69
+ function renderSchemaEntry({ schema, name, keysToOmit }: { schema: ast.SchemaNode | null; name: string; keysToOmit?: Array<string> }) {
71
70
  if (!schema) return null
72
71
 
73
72
  const inferTypeName = inferred ? resolver.resolveTypeName(name) : undefined
@@ -126,9 +125,9 @@ export const zodGenerator = defineGenerator<PluginZod>({
126
125
  </File>
127
126
  )
128
127
  },
129
- operations(nodes, options) {
130
- const { adapter, config, resolver, root } = this
131
- const { output, importPath, group, operations, paramsCasing } = options
128
+ operations(nodes, ctx) {
129
+ const { adapter, config, resolver, root } = ctx
130
+ const { output, importPath, group, operations, paramsCasing } = ctx.options
132
131
 
133
132
  if (!operations) {
134
133
  return
@@ -140,7 +139,7 @@ export const zodGenerator = defineGenerator<PluginZod>({
140
139
  } as const
141
140
 
142
141
  const transformedOperations = nodes.map((node) => {
143
- const params = caseParams(node.parameters, paramsCasing)
142
+ const params = ast.caseParams(node.parameters, paramsCasing)
144
143
 
145
144
  return {
146
145
  node,
@@ -1,7 +1,5 @@
1
- import { caseParams, createProperty, createSchema } from '@kubb/ast'
2
- import type { OperationNode, ParameterNode, SchemaNode } from '@kubb/ast/types'
3
- import { defineGenerator } from '@kubb/core'
4
- import { File } from '@kubb/renderer-jsx'
1
+ import { ast, defineGenerator } from '@kubb/core'
2
+ import { File, jsxRenderer } from '@kubb/renderer-jsx'
5
3
  import { Operations } from '../components/Operations.tsx'
6
4
  import { Zod } from '../components/Zod.tsx'
7
5
  import { ZOD_NAMESPACE_IMPORTS } from '../constants.ts'
@@ -10,16 +8,16 @@ import { printerZodMini } from '../printers/printerZodMini.ts'
10
8
  import type { PluginZod, ResolverZod } from '../types'
11
9
 
12
10
  type BuildGroupedParamsSchemaOptions = {
13
- params: Array<ParameterNode>
11
+ params: Array<ast.ParameterNode>
14
12
  }
15
13
 
16
- function buildGroupedParamsSchema({ params, optional }: BuildGroupedParamsSchemaOptions & { optional?: boolean }): SchemaNode {
17
- return createSchema({
14
+ function buildGroupedParamsSchema({ params, optional }: BuildGroupedParamsSchemaOptions & { optional?: boolean }): ast.SchemaNode {
15
+ return ast.createSchema({
18
16
  type: 'object',
19
17
  optional,
20
18
  primitive: 'object',
21
19
  properties: params.map((param) => {
22
- return createProperty({
20
+ return ast.createProperty({
23
21
  name: param.name,
24
22
  required: param.required,
25
23
  schema: param.schema,
@@ -32,7 +30,7 @@ type BuildOperationSchemaOptions = {
32
30
  resolver: ResolverZod
33
31
  }
34
32
 
35
- function buildLegacyResponsesSchemaNode(node: OperationNode, { resolver }: BuildOperationSchemaOptions): SchemaNode | null {
33
+ function buildLegacyResponsesSchemaNode(node: ast.OperationNode, { resolver }: BuildOperationSchemaOptions): ast.SchemaNode | null {
36
34
  const isGet = node.method.toLowerCase() === 'get'
37
35
  const successResponses = node.responses.filter((res) => {
38
36
  const code = Number(res.statusCode)
@@ -43,31 +41,31 @@ function buildLegacyResponsesSchemaNode(node: OperationNode, { resolver }: Build
43
41
  const responseSchema =
44
42
  successResponses.length > 0
45
43
  ? successResponses.length === 1
46
- ? createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, successResponses[0]!.statusCode) })
47
- : createSchema({
44
+ ? ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, successResponses[0]!.statusCode) })
45
+ : ast.createSchema({
48
46
  type: 'union',
49
- members: successResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
47
+ members: successResponses.map((res) => ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
50
48
  })
51
- : createSchema({ type: 'any' })
49
+ : ast.createSchema({ type: 'any' })
52
50
 
53
51
  const errorsSchema =
54
52
  errorResponses.length > 0
55
53
  ? errorResponses.length === 1
56
- ? createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, errorResponses[0]!.statusCode) })
57
- : createSchema({
54
+ ? ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, errorResponses[0]!.statusCode) })
55
+ : ast.createSchema({
58
56
  type: 'union',
59
- members: errorResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
57
+ members: errorResponses.map((res) => ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
60
58
  })
61
- : createSchema({ type: 'any' })
59
+ : ast.createSchema({ type: 'any' })
62
60
 
63
- const properties = [createProperty({ name: 'Response', required: true, schema: responseSchema })]
61
+ const properties = [ast.createProperty({ name: 'Response', required: true, schema: responseSchema })]
64
62
 
65
63
  if (!isGet && node.requestBody?.schema) {
66
64
  properties.push(
67
- createProperty({
65
+ ast.createProperty({
68
66
  name: 'Request',
69
67
  required: true,
70
- schema: createSchema({ type: 'ref', name: resolver.resolveDataName(node) }),
68
+ schema: ast.createSchema({ type: 'ref', name: resolver.resolveDataName(node) }),
71
69
  }),
72
70
  )
73
71
  }
@@ -75,10 +73,10 @@ function buildLegacyResponsesSchemaNode(node: OperationNode, { resolver }: Build
75
73
  const queryParam = node.parameters.find((p) => p.in === 'query')
76
74
  if (queryParam) {
77
75
  properties.push(
78
- createProperty({
76
+ ast.createProperty({
79
77
  name: 'QueryParams',
80
78
  required: true,
81
- schema: createSchema({ type: 'ref', name: resolver.resolveQueryParamsName(node, queryParam) }),
79
+ schema: ast.createSchema({ type: 'ref', name: resolver.resolveQueryParamsName(node, queryParam) }),
82
80
  }),
83
81
  )
84
82
  }
@@ -86,10 +84,10 @@ function buildLegacyResponsesSchemaNode(node: OperationNode, { resolver }: Build
86
84
  const pathParam = node.parameters.find((p) => p.in === 'path')
87
85
  if (pathParam) {
88
86
  properties.push(
89
- createProperty({
87
+ ast.createProperty({
90
88
  name: 'PathParams',
91
89
  required: true,
92
- schema: createSchema({ type: 'ref', name: resolver.resolvePathParamsName(node, pathParam) }),
90
+ schema: ast.createSchema({ type: 'ref', name: resolver.resolvePathParamsName(node, pathParam) }),
93
91
  }),
94
92
  )
95
93
  }
@@ -97,40 +95,40 @@ function buildLegacyResponsesSchemaNode(node: OperationNode, { resolver }: Build
97
95
  const headerParam = node.parameters.find((p) => p.in === 'header')
98
96
  if (headerParam) {
99
97
  properties.push(
100
- createProperty({
98
+ ast.createProperty({
101
99
  name: 'HeaderParams',
102
100
  required: true,
103
- schema: createSchema({ type: 'ref', name: resolver.resolveHeaderParamsName(node, headerParam) }),
101
+ schema: ast.createSchema({ type: 'ref', name: resolver.resolveHeaderParamsName(node, headerParam) }),
104
102
  }),
105
103
  )
106
104
  }
107
105
 
108
- properties.push(createProperty({ name: 'Errors', required: true, schema: errorsSchema }))
106
+ properties.push(ast.createProperty({ name: 'Errors', required: true, schema: errorsSchema }))
109
107
 
110
- return createSchema({ type: 'object', primitive: 'object', properties })
108
+ return ast.createSchema({ type: 'object', primitive: 'object', properties })
111
109
  }
112
110
 
113
- function buildLegacyResponseUnionSchemaNode(node: OperationNode, { resolver }: BuildOperationSchemaOptions): SchemaNode {
111
+ function buildLegacyResponseUnionSchemaNode(node: ast.OperationNode, { resolver }: BuildOperationSchemaOptions): ast.SchemaNode {
114
112
  const successResponses = node.responses.filter((res) => {
115
113
  const code = Number(res.statusCode)
116
114
  return !Number.isNaN(code) && code >= 200 && code < 300
117
115
  })
118
116
 
119
117
  if (successResponses.length === 0) {
120
- return createSchema({ type: 'any' })
118
+ return ast.createSchema({ type: 'any' })
121
119
  }
122
120
 
123
121
  if (successResponses.length === 1) {
124
- return createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, successResponses[0]!.statusCode) })
122
+ return ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, successResponses[0]!.statusCode) })
125
123
  }
126
124
 
127
- return createSchema({
125
+ return ast.createSchema({
128
126
  type: 'union',
129
- members: successResponses.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
127
+ members: successResponses.map((res) => ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
130
128
  })
131
129
  }
132
130
 
133
- function buildLegacySchemaNames(node: OperationNode, params: Array<ParameterNode>, resolver: ResolverZod) {
131
+ function buildLegacySchemaNames(node: ast.OperationNode, params: Array<ast.ParameterNode>, resolver: ResolverZod) {
134
132
  const pathParam = params.find((p) => p.in === 'path')
135
133
  const queryParam = params.find((p) => p.in === 'query')
136
134
  const headerParam = params.find((p) => p.in === 'header')
@@ -166,15 +164,16 @@ function buildLegacySchemaNames(node: OperationNode, params: Array<ParameterNode
166
164
 
167
165
  export const zodGeneratorLegacy = defineGenerator<PluginZod>({
168
166
  name: 'zod-legacy',
169
- schema(node, options) {
170
- const { adapter, config, resolver, root } = this
171
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options
167
+ renderer: jsxRenderer,
168
+ schema(node, ctx) {
169
+ const { adapter, config, resolver, root } = ctx
170
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options
172
171
 
173
172
  if (!node.name) {
174
173
  return
175
174
  }
176
175
 
177
- const mode = this.getMode(output)
176
+ const mode = ctx.getMode(output)
178
177
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath as 'zod' | 'zod/mini')
179
178
 
180
179
  const imports = adapter.getImports(node, (schemaName) => ({
@@ -208,20 +207,20 @@ export const zodGeneratorLegacy = defineGenerator<PluginZod>({
208
207
  </File>
209
208
  )
210
209
  },
211
- operation(node, options) {
212
- const { adapter, config, resolver, root } = this
213
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options
210
+ operation(node, ctx) {
211
+ const { adapter, config, resolver, root } = ctx
212
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options
214
213
 
215
- const mode = this.getMode(output)
214
+ const mode = ctx.getMode(output)
216
215
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath as 'zod' | 'zod/mini')
217
216
 
218
- const params = caseParams(node.parameters, paramsCasing)
217
+ const params = ast.caseParams(node.parameters, paramsCasing)
219
218
 
220
219
  const meta = {
221
220
  file: resolver.resolveFile({ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
222
221
  } as const
223
222
 
224
- function renderSchemaEntry({ schema, name, keysToOmit }: { schema: SchemaNode | null; name: string; keysToOmit?: Array<string> }) {
223
+ function renderSchemaEntry({ schema, name, keysToOmit }: { schema: ast.SchemaNode | null; name: string; keysToOmit?: Array<string> }) {
225
224
  if (!schema) return null
226
225
 
227
226
  const inferTypeName = inferred ? resolver.resolveTypeName(name) : undefined
@@ -319,9 +318,9 @@ export const zodGeneratorLegacy = defineGenerator<PluginZod>({
319
318
  </File>
320
319
  )
321
320
  },
322
- operations(nodes, options) {
323
- const { adapter, config, resolver, root } = this
324
- const { output, importPath, group, operations, paramsCasing } = options
321
+ operations(nodes, ctx) {
322
+ const { adapter, config, resolver, root } = ctx
323
+ const { output, importPath, group, operations, paramsCasing } = ctx.options
325
324
 
326
325
  if (!operations) {
327
326
  return
@@ -333,7 +332,7 @@ export const zodGeneratorLegacy = defineGenerator<PluginZod>({
333
332
  } as const
334
333
 
335
334
  const transformedOperations = nodes.map((node) => {
336
- const params = caseParams(node.parameters, paramsCasing)
335
+ const params = ast.caseParams(node.parameters, paramsCasing)
337
336
 
338
337
  return {
339
338
  node,
package/src/plugin.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { camelCase } from '@internals/utils'
2
- import { createPlugin, type Group, getPreset, mergeGenerators } from '@kubb/core'
3
- import { version } from '../package.json'
4
- import { presets } from './presets.ts'
2
+ import { definePlugin, type Group } from '@kubb/core'
3
+ import { zodGenerator } from './generators/zodGenerator.tsx'
4
+ import { zodGeneratorLegacy } from './generators/zodGeneratorLegacy.tsx'
5
+ import { resolverZod } from './resolvers/resolverZod.ts'
6
+ import { resolverZodLegacy } from './resolvers/resolverZodLegacy.ts'
5
7
  import type { PluginZod } from './types.ts'
6
8
 
7
9
  /**
@@ -25,7 +27,7 @@ export const pluginZodName = 'plugin-zod' satisfies PluginZod['name']
25
27
  * })
26
28
  * ```
27
29
  */
28
- export const pluginZod = createPlugin<PluginZod>((options) => {
30
+ export const pluginZod = definePlugin<PluginZod>((options) => {
29
31
  const {
30
32
  output = { path: 'zod', barrelType: 'named' },
31
33
  group,
@@ -43,95 +45,59 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
43
45
  wrapOutput = undefined,
44
46
  paramsCasing,
45
47
  printer,
46
- compatibilityPreset = 'default',
47
48
  resolver: userResolver,
48
49
  transformer: userTransformer,
49
50
  generators: userGenerators = [],
51
+ compatibilityPreset = 'default',
50
52
  } = options
51
53
 
52
- const preset = getPreset({
53
- preset: compatibilityPreset,
54
- presets: presets,
55
- resolver: userResolver,
56
- transformer: userTransformer,
57
- generators: userGenerators,
58
- })
59
-
60
- const generators = preset.generators ?? []
61
- const mergedGenerator = mergeGenerators(generators)
54
+ const defaultResolver = compatibilityPreset === 'kubbV4' ? resolverZodLegacy : resolverZod
55
+ const defaultGenerator = compatibilityPreset === 'kubbV4' ? zodGeneratorLegacy : zodGenerator
62
56
 
63
- let resolveNameWarning = false
64
- let resolvePathWarning = false
57
+ const groupConfig = group
58
+ ? ({
59
+ ...group,
60
+ name: (ctx) => {
61
+ if (group.type === 'path') {
62
+ return `${ctx.group.split('/')[1]}`
63
+ }
64
+ return `${camelCase(ctx.group)}Controller`
65
+ },
66
+ } satisfies Group)
67
+ : undefined
65
68
 
66
69
  return {
67
70
  name: pluginZodName,
68
- version,
69
- get resolver() {
70
- return preset.resolver
71
- },
72
- get transformer() {
73
- return preset.transformer
74
- },
75
- get options() {
76
- return {
77
- output,
78
- exclude,
79
- include,
80
- override,
81
- group: group
82
- ? ({
83
- ...group,
84
- name: (ctx) => {
85
- if (group.type === 'path') {
86
- return `${ctx.group.split('/')[1]}`
87
- }
88
- return `${camelCase(ctx.group)}Controller`
89
- },
90
- } satisfies Group)
91
- : undefined,
92
- dateType,
93
- typed,
94
- importPath,
95
- coercion,
96
- operations,
97
- inferred,
98
- guidType,
99
- mini,
100
- wrapOutput,
101
- paramsCasing,
102
- printer,
103
- }
104
- },
105
- resolvePath(baseName, pathMode, options) {
106
- if (!resolvePathWarning) {
107
- this.warn('Do not use resolvePath for pluginZod, use resolverZod.resolvePath instead')
108
- resolvePathWarning = true
109
- }
110
-
111
- return this.plugin.resolver.resolvePath(
112
- { baseName, pathMode, tag: options?.group?.tag, path: options?.group?.path },
113
- { root: this.root, output, group: this.plugin.options.group },
114
- )
115
- },
116
- resolveName(name, type) {
117
- if (!resolveNameWarning) {
118
- this.warn('Do not use resolveName for pluginZod, use resolverZod.default instead')
119
- resolveNameWarning = true
120
- }
121
-
122
- return this.plugin.resolver.default(name, type)
123
- },
124
- async schema(node, options) {
125
- return mergedGenerator.schema?.call(this, node, options)
126
- },
127
- async operation(node, options) {
128
- return mergedGenerator.operation?.call(this, node, options)
129
- },
130
- async operations(nodes, options) {
131
- return mergedGenerator.operations?.call(this, nodes, options)
132
- },
133
- async buildStart() {
134
- await this.openInStudio({ ast: true })
71
+ options,
72
+ hooks: {
73
+ 'kubb:plugin:setup'(ctx) {
74
+ ctx.setOptions({
75
+ output,
76
+ exclude,
77
+ include,
78
+ override,
79
+ group: groupConfig,
80
+ dateType,
81
+ typed,
82
+ importPath,
83
+ coercion,
84
+ operations,
85
+ inferred,
86
+ guidType,
87
+ mini,
88
+ wrapOutput,
89
+ paramsCasing,
90
+ printer,
91
+ })
92
+ ctx.setResolver(userResolver ? { ...defaultResolver, ...userResolver } : defaultResolver)
93
+ if (userTransformer) {
94
+ ctx.setTransformer(userTransformer)
95
+ }
96
+ ctx.addGenerator(defaultGenerator)
97
+ for (const gen of userGenerators) {
98
+ ctx.addGenerator(gen)
99
+ }
100
+ },
135
101
  },
136
102
  }
137
103
  })
@@ -1,7 +1,7 @@
1
1
  import { stringify } from '@internals/utils'
2
- import { createSchema, extractRefName, narrowSchema, syncSchemaRef } from '@kubb/ast'
2
+
3
3
  import type { PrinterFactoryOptions, PrinterPartial } from '@kubb/core'
4
- import { definePrinter } from '@kubb/core'
4
+ import { ast, definePrinter } from '@kubb/core'
5
5
  import type { PluginZod, ResolverZod } from '../types.ts'
6
6
  import { applyModifiers, containsSelfRef, formatLiteral, lengthConstraints, numberConstraints, shouldCoerce } from '../utils.ts'
7
7
 
@@ -139,7 +139,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
139
139
  },
140
140
  ref(node) {
141
141
  if (!node.name) return undefined
142
- const refName = node.ref ? (extractRefName(node.ref) ?? node.name) : node.name
142
+ const refName = node.ref ? (ast.extractRefName(node.ref) ?? node.name) : node.name
143
143
  const resolvedName = node.ref ? (this.options.resolver?.default(refName, 'function') ?? refName) : node.name
144
144
  const isSelfRef = node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName
145
145
 
@@ -154,7 +154,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
154
154
  .map((prop) => {
155
155
  const { name: propName, schema } = prop
156
156
 
157
- const meta = syncSchemaRef(schema)
157
+ const meta = ast.syncSchemaRef(schema)
158
158
 
159
159
  const isNullable = meta.nullable
160
160
  const isOptional = schema.optional
@@ -162,7 +162,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
162
162
 
163
163
  const hasSelfRef =
164
164
  this.options.schemaName != null && containsSelfRef(schema, { schemaName: this.options.schemaName, resolver: this.options.resolver })
165
- const baseOutput = this.transform(schema) ?? this.transform(createSchema({ type: 'unknown' }))!
165
+ const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: 'unknown' }))!
166
166
  // Strip z.lazy() wrappers inside object getters — the getter itself provides deferred evaluation
167
167
  const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName!) : baseOutput
168
168
 
@@ -193,7 +193,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
193
193
  result += `.catchall(${catchallType})`
194
194
  }
195
195
  } else if (node.additionalProperties === true) {
196
- result += `.catchall(${this.transform(createSchema({ type: 'unknown' }))})`
196
+ result += `.catchall(${this.transform(ast.createSchema({ type: 'unknown' }))})`
197
197
  } else if (node.additionalProperties === false) {
198
198
  result += '.strict()'
199
199
  }
@@ -202,7 +202,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
202
202
  },
203
203
  array(node) {
204
204
  const items = (node.items ?? []).map((item) => this.transform(item)).filter(Boolean)
205
- const inner = items.join(', ') || this.transform(createSchema({ type: 'unknown' }))!
205
+ const inner = items.join(', ') || this.transform(ast.createSchema({ type: 'unknown' }))!
206
206
  let result = `z.array(${inner})${lengthConstraints(node)}`
207
207
 
208
208
  if (node.unique) {
@@ -241,21 +241,21 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
241
241
 
242
242
  for (const member of rest) {
243
243
  if (member.primitive === 'string') {
244
- const s = narrowSchema(member, 'string')
244
+ const s = ast.narrowSchema(member, 'string')
245
245
  const c = lengthConstraints(s ?? {})
246
246
  if (c) {
247
247
  base += c
248
248
  continue
249
249
  }
250
250
  } else if (member.primitive === 'number' || member.primitive === 'integer') {
251
- const n = narrowSchema(member, 'number') ?? narrowSchema(member, 'integer')
251
+ const n = ast.narrowSchema(member, 'number') ?? ast.narrowSchema(member, 'integer')
252
252
  const c = numberConstraints(n ?? {})
253
253
  if (c) {
254
254
  base += c
255
255
  continue
256
256
  }
257
257
  } else if (member.primitive === 'array') {
258
- const a = narrowSchema(member, 'array')
258
+ const a = ast.narrowSchema(member, 'array')
259
259
  const c = lengthConstraints(a ?? {})
260
260
  if (c) {
261
261
  base += c
@@ -276,7 +276,7 @@ export const printerZod = definePrinter<PrinterZodFactory>((options) => {
276
276
  let base = this.transform(node)
277
277
  if (!base) return null
278
278
 
279
- const meta = syncSchemaRef(node)
279
+ const meta = ast.syncSchemaRef(node)
280
280
 
281
281
  if (keysToOmit?.length && meta.primitive === 'object' && !(meta.type === 'union' && meta.discriminatorPropertyName)) {
282
282
  // Mirror printerTs `nonNullable: true`: when omitting keys, the resulting
@@ -1,7 +1,7 @@
1
1
  import { stringify } from '@internals/utils'
2
- import { createSchema, extractRefName, narrowSchema, syncSchemaRef } from '@kubb/ast'
2
+
3
3
  import type { PrinterFactoryOptions, PrinterPartial } from '@kubb/core'
4
- import { definePrinter } from '@kubb/core'
4
+ import { ast, definePrinter } from '@kubb/core'
5
5
  import type { PluginZod, ResolverZod } from '../types.ts'
6
6
  import { applyMiniModifiers, containsSelfRef, formatLiteral, lengthChecksMini, numberChecksMini } from '../utils.ts'
7
7
 
@@ -130,7 +130,7 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
130
130
 
131
131
  ref(node) {
132
132
  if (!node.name) return undefined
133
- const refName = node.ref ? (extractRefName(node.ref) ?? node.name) : node.name
133
+ const refName = node.ref ? (ast.extractRefName(node.ref) ?? node.name) : node.name
134
134
  const resolvedName = node.ref ? (this.options.resolver?.default(refName, 'function') ?? refName) : node.name
135
135
  const isSelfRef = node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName
136
136
 
@@ -145,7 +145,7 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
145
145
  .map((prop) => {
146
146
  const { name: propName, schema } = prop
147
147
 
148
- const meta = syncSchemaRef(schema)
148
+ const meta = ast.syncSchemaRef(schema)
149
149
 
150
150
  const isNullable = meta.nullable
151
151
  const isOptional = schema.optional
@@ -153,7 +153,7 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
153
153
 
154
154
  const hasSelfRef =
155
155
  this.options.schemaName != null && containsSelfRef(schema, { schemaName: this.options.schemaName, resolver: this.options.resolver })
156
- const baseOutput = this.transform(schema) ?? this.transform(createSchema({ type: 'unknown' }))!
156
+ const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: 'unknown' }))!
157
157
  // Strip z.lazy() wrappers inside object getters — the getter itself provides deferred evaluation
158
158
  const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName!) : baseOutput
159
159
 
@@ -178,7 +178,7 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
178
178
  },
179
179
  array(node) {
180
180
  const items = (node.items ?? []).map((item) => this.transform(item)).filter(Boolean)
181
- const inner = items.join(', ') || this.transform(createSchema({ type: 'unknown' }))!
181
+ const inner = items.join(', ') || this.transform(ast.createSchema({ type: 'unknown' }))!
182
182
  let result = `z.array(${inner})${lengthChecksMini(node)}`
183
183
 
184
184
  if (node.unique) {
@@ -217,21 +217,21 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
217
217
 
218
218
  for (const member of rest) {
219
219
  if (member.primitive === 'string') {
220
- const s = narrowSchema(member, 'string')
220
+ const s = ast.narrowSchema(member, 'string')
221
221
  const c = lengthChecksMini(s ?? {})
222
222
  if (c) {
223
223
  base += c
224
224
  continue
225
225
  }
226
226
  } else if (member.primitive === 'number' || member.primitive === 'integer') {
227
- const n = narrowSchema(member, 'number') ?? narrowSchema(member, 'integer')
227
+ const n = ast.narrowSchema(member, 'number') ?? ast.narrowSchema(member, 'integer')
228
228
  const c = numberChecksMini(n ?? {})
229
229
  if (c) {
230
230
  base += c
231
231
  continue
232
232
  }
233
233
  } else if (member.primitive === 'array') {
234
- const a = narrowSchema(member, 'array')
234
+ const a = ast.narrowSchema(member, 'array')
235
235
  const c = lengthChecksMini(a ?? {})
236
236
  if (c) {
237
237
  base += c
@@ -252,7 +252,7 @@ export const printerZodMini = definePrinter<PrinterZodMiniFactory>((options) =>
252
252
  let base = this.transform(node)
253
253
  if (!base) return null
254
254
 
255
- const meta = syncSchemaRef(node)
255
+ const meta = ast.syncSchemaRef(node)
256
256
 
257
257
  if (keysToOmit?.length && meta.primitive === 'object' && !(meta.type === 'union' && meta.discriminatorPropertyName)) {
258
258
  // Mirror printerTs `nonNullable: true`: when omitting keys, the resulting