Skip to content

Commit 5eb0010

Browse files
committed
Add null check
1 parent b806323 commit 5eb0010

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ public void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
476476
writer.WriteOptionalCollection(OpenApiConstants.Enum, Enum, (nodeWriter, s) => nodeWriter.WriteAny(s));
477477

478478
// type
479-
SerializeTypeProperty(Type, writer, version);
479+
if (Type is not null)
480+
{
481+
SerializeTypeProperty(Type, writer, version);
482+
}
480483

481484
// allOf
482485
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AllOf, callback);
@@ -657,7 +660,10 @@ internal void SerializeAsV2(
657660
writer.WriteStartObject();
658661

659662
// type
660-
SerializeTypeProperty(Type, writer, OpenApiSpecVersion.OpenApi2_0);
663+
if (Type is not null)
664+
{
665+
SerializeTypeProperty(Type, writer, OpenApiSpecVersion.OpenApi2_0);
666+
}
661667

662668
// description
663669
writer.WriteProperty(OpenApiConstants.Description, Description);
@@ -836,7 +842,7 @@ private static int CountEnumSetFlags(JsonSchemaType? schemaType)
836842
// Check each flag in the enum
837843
foreach (JsonSchemaType value in System.Enum.GetValues(typeof(JsonSchemaType)))
838844
{
839-
// Ignore the None flag and check if the flag is set
845+
// Check if the flag is set
840846
if (schemaType.Value.HasFlag(value))
841847
{
842848
count++;

0 commit comments

Comments
 (0)