@@ -18,6 +18,7 @@ import {
1818import type { OpenApi3SchemaRulesOptions } from './openapi3.types'
1919import { AdapterContext , AdapterResolver , CompareRules } from '../types'
2020import {
21+ ChainItem ,
2122 cleanOrigins ,
2223 JSON_SCHEMA_NODE_TYPE_NULL ,
2324 JSON_SCHEMA_PROPERTY_ANY_OF ,
@@ -107,17 +108,17 @@ const buildNullTypeWithOrigins = (
107108 )
108109
109110 const inputOrigins = valueWithoutNullable [ originsFlag ] as Record < PropertyKey , unknown > | undefined
110- const nullTypeOrigins = nullTypeObject [ originsFlag ] as Record < PropertyKey , unknown > | undefined ?? { }
111+ const nullTypeOrigins = isObject ( nullTypeObject [ originsFlag ] ) ? nullTypeObject [ originsFlag ] as Record < PropertyKey , unknown > : { }
111112
112- const nullable = inputOrigins && inputOrigins . nullable
113+ const nullable = inputOrigins && inputOrigins . nullable as ChainItem [ ]
113114 if ( nullable ) {
114- const getOriginParent = ( item : unknown ) => ( {
115+ const getOriginParent = ( item : ChainItem | undefined ) => ( {
115116 value : JSON_SCHEMA_PROPERTY_TYPE ,
116- parent : ( item as any ) ?. parent ,
117+ parent : item ?. parent ,
117118 } )
118119
119120 nullTypeOrigins [ JSON_SCHEMA_PROPERTY_TYPE ] = isArray ( nullable )
120- ? nullable . map ( getOriginParent )
121+ ? ( nullable ) . map ( getOriginParent )
121122 : getOriginParent ( nullable )
122123 }
123124
@@ -154,10 +155,13 @@ const jsonSchemaOas30to31Adapter: (factory: NativeAnySchemaFactory) => AdapterRe
154155 const { originsFlag } = valueContext . options
155156
156157 return valueContext . transformer ( value , 'nullable-to-anyof' , ( current ) => {
158+ if ( ! isObject ( current ) ) {
159+ return current
160+ }
157161 const {
158162 [ JSON_SCHEMA_PROPERTY_NULLABLE ] : _nullable ,
159163 ...valueWithoutNullable
160- } = current as Record < PropertyKey , unknown >
164+ } = current
161165
162166 const nullTypeObject = buildNullTypeWithOrigins ( valueWithoutNullable , valueContext , factory )
163167
0 commit comments