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 = ({
469469
470470 if (
471471 schema . additionalProperties &&
472- schema . additionalProperties . type === 'object' &&
473- ! Object . keys ( properties ) . length
472+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
474473 ) {
475474 const zodSchema = schemaToZodSchema ( {
476475 plugin,
Original file line number Diff line number Diff line change @@ -391,8 +391,7 @@ const objectTypeToZodSchema = ({
391391
392392 if (
393393 schema . additionalProperties &&
394- schema . additionalProperties . type === 'object' &&
395- ! Object . keys ( properties ) . length
394+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
396395 ) {
397396 const zodSchema = schemaToZodSchema ( {
398397 plugin,
Original file line number Diff line number Diff line change @@ -431,8 +431,7 @@ const objectTypeToZodSchema = ({
431431
432432 if (
433433 schema . additionalProperties &&
434- schema . additionalProperties . type === 'object' &&
435- ! Object . keys ( properties ) . length
434+ ( ! schema . properties || ! Object . keys ( schema . properties ) . length )
436435 ) {
437436 const zodSchema = schemaToZodSchema ( {
438437 plugin,
@@ -458,6 +457,15 @@ const objectTypeToZodSchema = ({
458457 if ( zodSchema . hasCircularReference ) {
459458 result . hasCircularReference = true ;
460459 }
460+
461+ // Return with typeName for circular references
462+ if ( result . hasCircularReference ) {
463+ return {
464+ ...result ,
465+ typeName : 'ZodType' ,
466+ } as ZodSchema ;
467+ }
468+
461469 return result as Omit < ZodSchema , 'typeName' > ;
462470 }
463471
@@ -469,6 +477,14 @@ const objectTypeToZodSchema = ({
469477 parameters : [ ts . factory . createObjectLiteralExpression ( properties , true ) ] ,
470478 } ) ;
471479
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+
472488 return result as Omit < ZodSchema , 'typeName' > ;
473489} ;
474490
You can’t perform that action at this time.
0 commit comments