@kubb/plugin-zod 0.0.0-canary-20251103140549 → 0.0.0-canary-20251103161135

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 (37) hide show
  1. package/dist/{components-DlFtXaJq.js → components-BtBB23cQ.js} +81 -71
  2. package/dist/components-BtBB23cQ.js.map +1 -0
  3. package/dist/{components-BShpQYfg.cjs → components-DIUzzW4k.cjs} +81 -71
  4. package/dist/components-DIUzzW4k.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +2 -2
  7. package/dist/components.d.ts +2 -2
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-BtR5ImYH.js → generators-9upbJt-4.js} +4 -4
  10. package/dist/generators-9upbJt-4.js.map +1 -0
  11. package/dist/{generators-CTwKUJk6.cjs → generators-T3e_E7Uy.cjs} +4 -4
  12. package/dist/generators-T3e_E7Uy.cjs.map +1 -0
  13. package/dist/generators.cjs +2 -2
  14. package/dist/generators.js +2 -2
  15. package/dist/index.cjs +2 -2
  16. package/dist/index.js +2 -2
  17. package/package.json +6 -6
  18. package/src/components/Zod.tsx +6 -12
  19. package/src/generators/__snapshots__/createPet.ts +2 -2
  20. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +2 -2
  21. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput.ts +7 -9
  22. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput_entire_.ts +7 -10
  23. package/src/generators/__snapshots__/createPet_wrapOutput.ts +7 -9
  24. package/src/generators/__snapshots__/discriminator.ts +20 -28
  25. package/src/generators/__snapshots__/getPets.ts +3 -3
  26. package/src/generators/__snapshots__/getPets_wrapOutput.ts +8 -10
  27. package/src/generators/__snapshots__/petArray.ts +1 -5
  28. package/src/generators/__snapshots__/queryAllDefaulted.ts +1 -1
  29. package/src/generators/__snapshots__/queryAllDefaulted_wrapOutput.ts +2 -2
  30. package/src/generators/__snapshots__/showPetById.ts +3 -3
  31. package/src/generators/__snapshots__/showPetById_wrapOutput.ts +8 -10
  32. package/src/generators/zodGenerator.tsx +2 -2
  33. package/src/parser.ts +37 -36
  34. package/dist/components-BShpQYfg.cjs.map +0 -1
  35. package/dist/components-DlFtXaJq.js.map +0 -1
  36. package/dist/generators-BtR5ImYH.js.map +0 -1
  37. package/dist/generators-CTwKUJk6.cjs.map +0 -1
@@ -11,7 +11,7 @@ type Props = {
11
11
  typeName?: string
12
12
  inferTypeName?: string
13
13
  tree: Array<Schema>
14
- rawSchema: SchemaObject
14
+ schema: SchemaObject
15
15
  description?: string
16
16
  coercion: PluginZod['resolvedOptions']['coercion']
17
17
  mapper: PluginZod['resolvedOptions']['mapper']
@@ -25,7 +25,7 @@ export function Zod({
25
25
  name,
26
26
  typeName,
27
27
  tree,
28
- rawSchema,
28
+ schema,
29
29
  inferTypeName,
30
30
  mapper,
31
31
  coercion,
@@ -49,10 +49,7 @@ export function Zod({
49
49
  .map((schema, index) => {
50
50
  const siblings = schemas.filter((_, i) => i !== index)
51
51
 
52
- return parserZod.parse(
53
- { parent: undefined, current: schema, siblings },
54
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version },
55
- )
52
+ return parserZod.parse({ schema, parent: undefined, current: schema, siblings, name }, { mapper, coercion, wrapOutput, version })
56
53
  })
57
54
  .filter(Boolean)
58
55
  .join('')
@@ -71,28 +68,25 @@ export function Zod({
71
68
  } else {
72
69
  suffix = '.unwrap()'
73
70
  }
74
- } else {
75
- if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref) && version === '3') {
76
- suffix = '.schema'
77
- }
78
71
  }
79
72
 
80
73
  const emptyValue = parserZod.parse(
81
74
  {
75
+ schema,
82
76
  parent: undefined,
83
77
  current: {
84
78
  keyword: schemaKeywords[emptySchemaType],
85
79
  },
86
80
  siblings: [],
87
81
  },
88
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version },
82
+ { mapper, coercion, wrapOutput, version },
89
83
  )
90
84
 
91
85
  const baseSchemaOutput =
92
86
  [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `'${key}': true`).join(',')} })` : undefined].filter(Boolean).join('') ||
93
87
  emptyValue ||
94
88
  ''
95
- const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema: rawSchema }) || baseSchemaOutput : baseSchemaOutput
89
+ const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema }) || baseSchemaOutput : baseSchemaOutput
96
90
  const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ${version === '4' ? 'z.ZodType' : 'ToZod'}<${typeName}>` : wrappedSchemaOutput
97
91
 
98
92
  return (
@@ -12,11 +12,11 @@ export const createPets201 = z.unknown()
12
12
  /**
13
13
  * @description unexpected error
14
14
  */
15
- export const createPetsError = z.lazy(() => error)
15
+ export const createPetsError = error
16
16
 
17
17
  export const createPetsMutationRequest = z.object({
18
18
  name: z.string(),
19
19
  tag: z.string(),
20
20
  })
21
21
 
22
- export const createPetsMutationResponse = z.lazy(() => createPets201)
22
+ export const createPetsMutationResponse = createPets201
@@ -12,11 +12,11 @@ export const createPets201 = z.unknown()
12
12
  /**
13
13
  * @description unexpected error
14
14
  */
15
- export const createPetsError = z.lazy(() => error)
15
+ export const createPetsError = error
16
16
 
17
17
  export const createPetsMutationRequest = z.object({
18
18
  name: z.string(),
19
19
  tag: z.string(),
20
20
  })
21
21
 
22
- export const createPetsMutationResponse = z.lazy(() => createPets201)
22
+ export const createPetsMutationResponse = createPets201
@@ -12,18 +12,16 @@ export const createPets201 = z.unknown()
12
12
  /**
13
13
  * @description unexpected error
14
14
  */
15
- export const createPetsError = z
16
- .lazy(() => error)
17
- .openapi({
18
- examples: [
19
- { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
20
- { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
21
- ],
22
- })
15
+ export const createPetsError = error.openapi({
16
+ examples: [
17
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
18
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
19
+ ],
20
+ })
23
21
 
24
22
  export const createPetsMutationRequest = z.object({
25
23
  name: z.string().openapi({ example: 'Baxter' }),
26
24
  tag: z.string(),
27
25
  })
28
26
 
29
- export const createPetsMutationResponse = z.lazy(() => createPets201)
27
+ export const createPetsMutationResponse = createPets201
@@ -12,19 +12,16 @@ export const createPets201 = z.unknown()
12
12
  /**
13
13
  * @description unexpected error
14
14
  */
15
- export const createPetsError = extendApi(
16
- z.lazy(() => error),
17
- {
18
- examples: [
19
- { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
20
- { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
21
- ],
22
- },
23
- )
15
+ export const createPetsError = extendApi(error, {
16
+ examples: [
17
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
18
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
19
+ ],
20
+ })
24
21
 
25
22
  export const createPetsMutationRequest = z.object({
26
23
  name: extendApi(z.string(), { example: 'Baxter' }),
27
24
  tag: z.string(),
28
25
  })
29
26
 
30
- export const createPetsMutationResponse = z.lazy(() => createPets201)
27
+ export const createPetsMutationResponse = createPets201
@@ -12,18 +12,16 @@ export const createPets201 = z.unknown()
12
12
  /**
13
13
  * @description unexpected error
14
14
  */
15
- export const createPetsError = z
16
- .lazy(() => error)
17
- .openapi({
18
- examples: [
19
- { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
20
- { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
21
- ],
22
- })
15
+ export const createPetsError = error.openapi({
16
+ examples: [
17
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
18
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
19
+ ],
20
+ })
23
21
 
24
22
  export const createPetsMutationRequest = z.object({
25
23
  name: z.string().openapi({ example: 'Baxter' }),
26
24
  tag: z.string(),
27
25
  })
28
26
 
29
- export const createPetsMutationResponse = z.lazy(() => createPets201)
27
+ export const createPetsMutationResponse = createPets201
@@ -5,32 +5,24 @@
5
5
  import { z } from 'zod'
6
6
 
7
7
  export const advanced = z.union([
8
- z
9
- .lazy(() => enumerationValueSpecificationDto)
10
- .and(
11
- z.object({
12
- type: z.literal('enum'),
13
- }),
14
- ),
15
- z
16
- .lazy(() => rangeValueSpecificationDto)
17
- .and(
18
- z.object({
19
- type: z.literal('range'),
20
- }),
21
- ),
22
- z
23
- .lazy(() => regexValueSpecificationDto)
24
- .and(
25
- z.object({
26
- type: z.literal('regex'),
27
- }),
28
- ),
29
- z
30
- .lazy(() => sliderValueSpecificationDto)
31
- .and(
32
- z.object({
33
- type: z.literal('slider'),
34
- }),
35
- ),
8
+ enumerationValueSpecificationDto.and(
9
+ z.object({
10
+ type: z.literal('enum'),
11
+ }),
12
+ ),
13
+ rangeValueSpecificationDto.and(
14
+ z.object({
15
+ type: z.literal('range'),
16
+ }),
17
+ ),
18
+ regexValueSpecificationDto.and(
19
+ z.object({
20
+ type: z.literal('regex'),
21
+ }),
22
+ ),
23
+ sliderValueSpecificationDto.and(
24
+ z.object({
25
+ type: z.literal('slider'),
26
+ }),
27
+ ),
36
28
  ])
@@ -12,11 +12,11 @@ export const listPetsQueryParams = z.object({
12
12
  /**
13
13
  * @description A paged array of pets
14
14
  */
15
- export const listPets200 = z.lazy(() => pets)
15
+ export const listPets200 = pets
16
16
 
17
17
  /**
18
18
  * @description unexpected error
19
19
  */
20
- export const listPetsError = z.lazy(() => error)
20
+ export const listPetsError = error
21
21
 
22
- export const listPetsQueryResponse = z.lazy(() => listPets200)
22
+ export const listPetsQueryResponse = listPets200
@@ -12,18 +12,16 @@ export const listPetsQueryParams = z.object({
12
12
  /**
13
13
  * @description A paged array of pets
14
14
  */
15
- export const listPets200 = z.lazy(() => pets)
15
+ export const listPets200 = pets
16
16
 
17
17
  /**
18
18
  * @description unexpected error
19
19
  */
20
- export const listPetsError = z
21
- .lazy(() => error)
22
- .openapi({
23
- examples: [
24
- { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
25
- { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
26
- ],
27
- })
20
+ export const listPetsError = error.openapi({
21
+ examples: [
22
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
23
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
24
+ ],
25
+ })
28
26
 
29
- export const listPetsQueryResponse = z.lazy(() => listPets200)
27
+ export const listPetsQueryResponse = listPets200
@@ -7,8 +7,4 @@ import { z } from 'zod'
7
7
  /**
8
8
  * @description List of Pet object
9
9
  */
10
- export const petArray = z
11
- .array(z.lazy(() => pet))
12
- .min(1)
13
- .max(3)
14
- .describe('List of Pet object')
10
+ export const petArray = z.array(pet).min(1).max(3).describe('List of Pet object')
@@ -16,4 +16,4 @@ export const getThings200 = z.object({
16
16
  items: z.array(z.lazy(() => thing)),
17
17
  })
18
18
 
19
- export const getThingsQueryResponse = z.lazy(() => getThings200)
19
+ export const getThingsQueryResponse = getThings200
@@ -13,7 +13,7 @@ export const getThingsQueryParams = z.object({
13
13
  * @description A list of things
14
14
  */
15
15
  export const getThings200 = z.object({
16
- items: z.array(z.lazy(() => thing)),
16
+ items: z.array(thing),
17
17
  })
18
18
 
19
- export const getThingsQueryResponse = z.lazy(() => getThings200)
19
+ export const getThingsQueryResponse = getThings200
@@ -12,11 +12,11 @@ export const showPetByIdPathParams = z.object({
12
12
  /**
13
13
  * @description Expected response to a valid request
14
14
  */
15
- export const showPetById200 = z.lazy(() => pet)
15
+ export const showPetById200 = pet
16
16
 
17
17
  /**
18
18
  * @description unexpected error
19
19
  */
20
- export const showPetByIdError = z.lazy(() => error)
20
+ export const showPetByIdError = error
21
21
 
22
- export const showPetByIdQueryResponse = z.lazy(() => showPetById200)
22
+ export const showPetByIdQueryResponse = showPetById200
@@ -12,18 +12,16 @@ export const showPetByIdPathParams = z.object({
12
12
  /**
13
13
  * @description Expected response to a valid request
14
14
  */
15
- export const showPetById200 = z.lazy(() => pet)
15
+ export const showPetById200 = pet
16
16
 
17
17
  /**
18
18
  * @description unexpected error
19
19
  */
20
- export const showPetByIdError = z
21
- .lazy(() => error)
22
- .openapi({
23
- examples: [
24
- { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
25
- { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
26
- ],
27
- })
20
+ export const showPetByIdError = error.openapi({
21
+ examples: [
22
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
23
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
24
+ ],
25
+ })
28
26
 
29
- export const showPetByIdQueryResponse = z.lazy(() => showPetById200)
27
+ export const showPetByIdQueryResponse = showPetById200
@@ -81,7 +81,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
81
81
  inferTypeName={inferred ? zod.inferTypeName : undefined}
82
82
  description={description}
83
83
  tree={tree}
84
- rawSchema={schemaObject}
84
+ schema={schemaObject}
85
85
  mapper={mapper}
86
86
  coercion={coercion}
87
87
  keysToOmit={keysToOmit}
@@ -150,7 +150,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
150
150
  inferTypeName={inferred ? zod.inferTypeName : undefined}
151
151
  description={schema.value.description}
152
152
  tree={schema.tree}
153
- rawSchema={schema.value}
153
+ schema={schema.value}
154
154
  mapper={mapper}
155
155
  coercion={coercion}
156
156
  wrapOutput={wrapOutput}
package/src/parser.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import transformers from '@kubb/core/transformers'
2
- import type { SchemaObject } from '@kubb/oas'
3
2
 
4
3
  import type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'
5
4
  import { isKeyword, SchemaGenerator, type SchemaKeywordMapper, type SchemaTree, schemaKeywords } from '@kubb/plugin-oas'
@@ -191,12 +190,12 @@ const zodKeywordMapper = {
191
190
  phone: undefined,
192
191
  readOnly: undefined,
193
192
  writeOnly: undefined,
194
- ref: (value?: string, version: '3' | '4' = '3') => {
193
+ ref: (value?: string, lazy = true) => {
195
194
  if (!value) {
196
195
  return undefined
197
196
  }
198
197
 
199
- return version === '4' ? value : `z.lazy(() => ${value})`
198
+ return lazy ? `z.lazy(() => ${value})` : value
200
199
  },
201
200
  blob: () => 'z.instanceof(File)',
202
201
  deprecated: undefined,
@@ -258,18 +257,14 @@ const shouldCoerce = (coercion: ParserOptions['coercion'] | undefined, type: 'da
258
257
  }
259
258
 
260
259
  type ParserOptions = {
261
- name: string
262
- typeName?: string
263
- description?: string
264
- keysToOmit?: string[]
260
+ lazy?: boolean
265
261
  mapper?: Record<string, string>
266
262
  coercion?: boolean | { dates?: boolean; strings?: boolean; numbers?: boolean }
267
263
  wrapOutput?: (opts: { output: string; schema: any }) => string | undefined
268
- rawSchema: SchemaObject
269
264
  version: '3' | '4'
270
265
  }
271
266
 
272
- export function parse({ parent, current, name, siblings }: SchemaTree, options: ParserOptions): string | undefined {
267
+ export function parse({ schema, parent, current, name, siblings }: SchemaTree, options: ParserOptions): string | undefined {
273
268
  const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]
274
269
 
275
270
  // Early exit: if siblings contain both matches and ref → skip matches entirely
@@ -287,7 +282,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
287
282
  if (isKeyword(current, schemaKeywords.union)) {
288
283
  // zod union type needs at least 2 items
289
284
  if (Array.isArray(current.args) && current.args.length === 1) {
290
- return parse({ parent, name: name, current: current.args[0] as Schema, siblings }, options)
285
+ return parse({ schema, parent, name, current: current.args[0] as Schema, siblings }, options)
291
286
  }
292
287
  if (Array.isArray(current.args) && !current.args.length) {
293
288
  return ''
@@ -295,7 +290,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
295
290
 
296
291
  return zodKeywordMapper.union(
297
292
  sort(current.args)
298
- .map((schema, _index, siblings) => parse({ parent: current, name: name, current: schema, siblings }, options))
293
+ .map((it, _index, siblings) => parse({ schema, parent: current, name, current: it, siblings }, options))
299
294
  .filter(Boolean),
300
295
  )
301
296
  }
@@ -305,7 +300,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
305
300
  .filter((schema: Schema) => {
306
301
  return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword as typeof schemaKeywords.describe)
307
302
  })
308
- .map((schema: Schema, _index, siblings) => parse({ parent: current, name: name, current: schema, siblings }, options))
303
+ .map((it: Schema, _index, siblings) => parse({ schema, parent: current, name, current: it, siblings }, options))
309
304
  .filter(Boolean)
310
305
 
311
306
  return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`
@@ -314,7 +309,9 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
314
309
  if (isKeyword(current, schemaKeywords.array)) {
315
310
  return zodKeywordMapper.array(
316
311
  sort(current.args.items)
317
- .map((schemas, _index, siblings) => parse({ parent: current, name: name, current: schemas, siblings }, options))
312
+ .map((it, _index, siblings) => {
313
+ return parse({ schema, parent: current, name, current: it, siblings }, options)
314
+ })
318
315
  .filter(Boolean),
319
316
  current.args.min,
320
317
  current.args.max,
@@ -329,7 +326,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
329
326
  keyword: schemaKeywords.const,
330
327
  args: current.args.items[0],
331
328
  }
332
- return parse({ parent: current, name: name, current: child, siblings: [child] }, options)
329
+ return parse({ schema, parent: current, name, current: child, siblings: [child] }, options)
333
330
  }
334
331
 
335
332
  return zodKeywordMapper.union(
@@ -338,8 +335,8 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
338
335
  keyword: schemaKeywords.const,
339
336
  args: schema,
340
337
  }))
341
- .map((schema, _index, siblings) => {
342
- return parse({ parent: current, name: name, current: schema, siblings }, options)
338
+ .map((it, _index, siblings) => {
339
+ return parse({ schema, parent: current, name, current: it, siblings }, options)
343
340
  })
344
341
  .filter(Boolean),
345
342
  )
@@ -360,7 +357,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
360
357
  }
361
358
 
362
359
  if (isKeyword(current, schemaKeywords.ref)) {
363
- return zodKeywordMapper.ref(current.args?.name, options.version)
360
+ return zodKeywordMapper.ref(current.args?.name, options.lazy ?? name === current.args.name)
364
361
  }
365
362
 
366
363
  if (isKeyword(current, schemaKeywords.object)) {
@@ -370,80 +367,84 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
370
367
  })
371
368
 
372
369
  const properties = propertyEntries
373
- .map(([name, schemas]) => {
370
+ .map(([propertyName, schemas]) => {
374
371
  const nameSchema = schemas.find((it) => it.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']
375
372
  const isNullable = schemas.some((it) => isKeyword(it, schemaKeywords.nullable))
376
373
  const isNullish = schemas.some((it) => isKeyword(it, schemaKeywords.nullish))
377
374
  const isOptional = schemas.some((it) => isKeyword(it, schemaKeywords.optional))
375
+ const hasRef = !!SchemaGenerator.find(schemas, schemaKeywords.ref)
378
376
 
379
- const mappedName = nameSchema?.args || name
377
+ const mappedName = nameSchema?.args || propertyName
380
378
 
381
379
  // custom mapper(pluginOptions)
382
380
  if (options.mapper?.[mappedName]) {
383
- return `"${name}": ${options.mapper?.[mappedName]}`
381
+ return `"${propertyName}": ${options.mapper?.[mappedName]}`
384
382
  }
385
383
 
386
384
  const baseSchemaOutput = sort(schemas)
387
385
  .filter((schema) => {
388
386
  return !isKeyword(schema, schemaKeywords.optional) && !isKeyword(schema, schemaKeywords.nullable) && !isKeyword(schema, schemaKeywords.nullish)
389
387
  })
390
- .map((schema) => parse({ parent: current, name, current: schema, siblings: schemas }, options))
388
+ .map((it) => {
389
+ const lazy = !(options.version === '4' && hasRef)
390
+ return parse({ schema, parent: current, name, current: it, siblings: schemas }, { ...options, lazy })
391
+ })
391
392
  .filter(Boolean)
392
393
  .join('')
393
394
 
394
395
  const objectValue = options.wrapOutput
395
- ? options.wrapOutput({ output: baseSchemaOutput, schema: options.rawSchema?.properties?.[name] }) || baseSchemaOutput
396
+ ? options.wrapOutput({ output: baseSchemaOutput, schema: schema?.properties?.[propertyName] }) || baseSchemaOutput
396
397
  : baseSchemaOutput
397
398
 
398
- if (options.version === '4' && SchemaGenerator.find(schemas, schemaKeywords.ref)) {
399
+ if (options.version === '4' && hasRef) {
399
400
  // both optional and nullable
400
401
  if (isNullish) {
401
- return `get "${name}"(){
402
- return ${zodKeywordMapper.nullish(objectValue)}
402
+ return `get "${propertyName}"(){
403
+ return ${objectValue}${zodKeywordMapper.nullish()}
403
404
  }`
404
405
  }
405
406
 
406
407
  // undefined
407
408
  if (isOptional) {
408
- return `get "${name}"(){
409
- return ${zodKeywordMapper.optional(objectValue)}
409
+ return `get "${propertyName}"(){
410
+ return ${objectValue}${zodKeywordMapper.optional()}
410
411
  }`
411
412
  }
412
413
 
413
414
  // null
414
415
  if (isNullable) {
415
- return `get "${name}"(){
416
- return ${zodKeywordMapper.nullable(objectValue)}
416
+ return `get "${propertyName}"(){
417
+ return ${objectValue}${zodKeywordMapper.nullable()}
417
418
  }`
418
419
  }
419
420
 
420
- return `get "${name}"(){
421
+ return `get "${propertyName}"(){
421
422
  return ${objectValue}
422
423
  }`
423
424
  }
424
425
 
425
426
  // both optional and nullable
426
427
  if (isNullish) {
427
- return `"${name}": ${objectValue}${zodKeywordMapper.nullish()}`
428
+ return `"${propertyName}": ${objectValue}${zodKeywordMapper.nullish()}`
428
429
  }
429
430
 
430
431
  // undefined
431
432
  if (isOptional) {
432
- return `"${name}": ${zodKeywordMapper.optional(objectValue)}`
433
+ return `"${propertyName}": ${zodKeywordMapper.optional(objectValue)}`
433
434
  }
434
435
 
435
436
  // null
436
437
  if (isNullable) {
437
- return `"${name}": ${zodKeywordMapper.nullable(objectValue)}`
438
+ return `"${propertyName}": ${zodKeywordMapper.nullable(objectValue)}`
438
439
  }
439
440
 
440
- return `"${name}": ${objectValue}`
441
+ return `"${propertyName}": ${objectValue}`
441
442
  })
442
443
  .join(',\n')
443
444
 
444
445
  const additionalProperties = current.args?.additionalProperties?.length
445
446
  ? current.args.additionalProperties
446
- .map((schema, _index, siblings) => parse({ parent: current, name: name, current: schema, siblings }, options))
447
+ .map((it, _index, siblings) => parse({ schema, parent: current, name, current: it, siblings }, options))
447
448
  .filter(Boolean)
448
449
  .join('')
449
450
  : undefined
@@ -458,7 +459,7 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
458
459
 
459
460
  if (isKeyword(current, schemaKeywords.tuple)) {
460
461
  return zodKeywordMapper.tuple(
461
- current.args.items.map((schema, _index, siblings) => parse({ parent: current, name: name, current: schema, siblings }, options)).filter(Boolean),
462
+ current.args.items.map((it, _index, siblings) => parse({ schema, parent: current, name, current: it, siblings }, options)).filter(Boolean),
462
463
  )
463
464
  }
464
465