Skip to content

Commit 6730096

Browse files
Merge pull request #1901 from lambdank/main
Recursive zod fields now uses string literal - Fixes #1900
2 parents d9e814a + 10f4b61 commit 6730096

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/legal-zebras-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kubb/plugin-zod": patch
3+
---
4+
5+
Recursive fields now use string literals

packages/plugin-zod/src/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,26 +367,26 @@ export function parse({ parent, current, name, siblings }: SchemaTree, options:
367367
if (options.version === '4' && SchemaGenerator.find(schemas, schemaKeywords.ref)) {
368368
// both optional and nullable
369369
if (isNullish) {
370-
return `get ${name}(){
370+
return `get "${name}"(){
371371
return ${zodKeywordMapper.nullish(objectValue)}
372372
}`
373373
}
374374

375375
// undefined
376376
if (isOptional) {
377-
return `get ${name}(){
377+
return `get "${name}"(){
378378
return ${zodKeywordMapper.optional(objectValue)}
379379
}`
380380
}
381381

382382
// null
383383
if (isNullable) {
384-
return `get ${name}(){
384+
return `get "${name}"(){
385385
return ${zodKeywordMapper.nullable(objectValue)}
386386
}`
387387
}
388388

389-
return `get ${name}(){
389+
return `get "${name}"(){
390390
return ${objectValue}
391391
}`
392392
}

0 commit comments

Comments
 (0)