@@ -126,11 +126,12 @@ export const hasAdditionalProperties = (
126126/**
127127 * Resolve a schema that might be a model reference (string) to the actual schema
128128 */
129- export const resolveSchema = (
130- schema : TAnySchema | string ,
129+ export const resolveSchema = (
130+ schema : TAnySchema | string | undefined ,
131131 models ?: Record < string , TAnySchema | StandardSchemaV1Like > ,
132132 modules ?: TModule < any , any >
133- ) : TAnySchema | StandardSchemaV1Like | undefined => {
133+ ) : TAnySchema | StandardSchemaV1Like | undefined => {
134+ if ( ! schema ) return undefined
134135 if ( typeof schema !== 'string' ) return schema
135136
136137 // Check modules first (higher priority)
@@ -141,7 +142,7 @@ export const resolveSchema = (
141142
142143 // Then check models
143144 return models ?. [ schema ]
144- }
145+ }
145146
146147export const hasType = ( type : string , schema : TAnySchema ) : boolean => {
147148 if ( ! schema ) return false
@@ -456,12 +457,14 @@ export const getSchemaValidator = <
456457 if ( ! schema ) return undefined as any
457458 }
458459
460+ const hasAdditionalCoerce = Array . isArray ( additionalCoerce ) ?
461+ additionalCoerce . length > 0 : ! ! additionalCoerce
459462 if ( Kind in schema ) {
460463 if ( schema [ Kind ] === 'Import' ) {
461464 if ( ! hasRef ( schema . $defs [ schema . $ref ] ) ) {
462465 schema = schema . $defs [ schema . $ref ]
463466
464- if ( coerce || additionalCoerce ) {
467+ if ( coerce || hasAdditionalCoerce ) {
465468 schema = replaceSchema ( schema as TSchema )
466469 if ( '$id' in schema && ! schema . $defs ) {
467470 schema . $id = `${ schema . $id } _coerced_${ randomId ( ) } ` ;
@@ -479,7 +482,7 @@ export const getSchemaValidator = <
479482 } )
480483
481484 schema = model . Import ( id )
482- } else if ( coerce || additionalCoerce )
485+ } else if ( coerce || hasAdditionalCoerce )
483486 schema = replaceSchema ( schema as TSchema )
484487 }
485488 }
@@ -694,16 +697,15 @@ export const getSchemaValidator = <
694697 schema = replaceSchemaTypeFromManyOptions ( schema , {
695698 onlyFirst : "object" ,
696699 from : t . Object ( { } ) ,
697- to ( { properties, ...options } ) {
698- // If nothing is return, use the original schema
699- if ( ! properties ) return { properties, ...options } ;
700- if ( "additionalProperties" in schema ) return { properties, ...options } ;
701-
702- return t . Object ( properties , {
703- ...options ,
704- additionalProperties : false ,
705- } ) ;
706- } ,
700+ to ( schema ) {
701+ if ( ! schema . properties ) return schema ;
702+ if ( "additionalProperties" in schema ) return schema ;
703+
704+ return t . Object ( schema . properties , {
705+ ...schema ,
706+ additionalProperties : false ,
707+ } ) ;
708+ }
707709 } ) ;
708710 }
709711
0 commit comments