@@ -225,11 +225,22 @@ internal static partial class OpenApiV3Deserializer
225225 {
226226 if ( bool . TryParse ( n . GetScalarValue ( ) , out var parsed ) && parsed )
227227 {
228- // While we are dealing with v3 document, we are still using x-nullable extension here.
229- // This is used only as a marker during deserialization to indicate that the schema is nullable.
230- // When we do FinalizeDeserialization, we will modify the OpenApiSchema.Type to
231- // include JsonSchemaType.Null (only if needed), and always remove the extension.
232- o . AddExtension ( OpenApiConstants . NullableExtension , _nullableTrueExtension ) ;
228+ if ( o . Type is not null && o . Type != 0 )
229+ {
230+ o . Type |= JsonSchemaType . Null ;
231+ }
232+ else
233+ {
234+ // While we are dealing with v3 document, we are still using x-nullable extension here.
235+ // This is used only as a marker during deserialization to indicate that the schema is nullable.
236+ // When we do FinalizeDeserialization, we will modify the OpenApiSchema.Type to
237+ // include JsonSchemaType.Null (only if needed), and always remove the extension.
238+ // The reason is that "nullable" property should only take effect if "Type" is set.
239+ // If we knew Type is set, we add "Null" to it.
240+ // Otherwise, it might be that it will be set later.
241+ // In this case, we add the marker extension, and check at the end of deserialization, and remove the extension.
242+ o . AddExtension ( OpenApiConstants . NullableExtension , _nullableTrueExtension ) ;
243+ }
233244 }
234245 }
235246 } ,
0 commit comments