File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed
packages/openapi-ts/src/plugins/zod Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1
- packages/openapi-ts/README.md
1
+ packages/openapi-ts/README.md
Original file line number Diff line number Diff line change @@ -469,8 +469,7 @@ const objectTypeToZodSchema = ({
469
469
470
470
if (
471
471
schema . additionalProperties &&
472
- schema . additionalProperties . type === 'object' &&
473
- ! Object . keys ( properties ) . length
472
+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
474
473
) {
475
474
const zodSchema = schemaToZodSchema ( {
476
475
plugin,
Original file line number Diff line number Diff line change @@ -391,8 +391,7 @@ const objectTypeToZodSchema = ({
391
391
392
392
if (
393
393
schema . additionalProperties &&
394
- schema . additionalProperties . type === 'object' &&
395
- ! Object . keys ( properties ) . length
394
+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
396
395
) {
397
396
const zodSchema = schemaToZodSchema ( {
398
397
plugin,
Original file line number Diff line number Diff line change @@ -431,8 +431,7 @@ const objectTypeToZodSchema = ({
431
431
432
432
if (
433
433
schema . additionalProperties &&
434
- schema . additionalProperties . type === 'object' &&
435
- ! Object . keys ( properties ) . length
434
+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
436
435
) {
437
436
const zodSchema = schemaToZodSchema ( {
438
437
plugin,
@@ -458,6 +457,15 @@ const objectTypeToZodSchema = ({
458
457
if ( zodSchema . hasCircularReference ) {
459
458
result . hasCircularReference = true ;
460
459
}
460
+
461
+ // Return with typeName for circular references
462
+ if ( result . hasCircularReference ) {
463
+ return {
464
+ ...result ,
465
+ typeName : 'ZodType' ,
466
+ } as ZodSchema ;
467
+ }
468
+
461
469
return result as Omit < ZodSchema , 'typeName' > ;
462
470
}
463
471
@@ -469,6 +477,14 @@ const objectTypeToZodSchema = ({
469
477
parameters : [ ts . factory . createObjectLiteralExpression ( properties , true ) ] ,
470
478
} ) ;
471
479
480
+ // Return with typeName for circular references (AnyZodObject doesn't exist in Zod v4, use ZodType)
481
+ if ( result . hasCircularReference ) {
482
+ return {
483
+ ...result ,
484
+ typeName : 'ZodType' ,
485
+ } as ZodSchema ;
486
+ }
487
+
472
488
return result as Omit < ZodSchema , 'typeName' > ;
473
489
} ;
474
490
You can’t perform that action at this time.
0 commit comments