Skip to content

Commit 4b74290

Browse files
committed
AddExtension only if Type is still unknown
1 parent e754250 commit 4b74290

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)