Skip to content

Commit

Permalink
Add null check
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Oct 30, 2024
1 parent b806323 commit 5eb0010
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ public void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
writer.WriteOptionalCollection(OpenApiConstants.Enum, Enum, (nodeWriter, s) => nodeWriter.WriteAny(s));

// type
SerializeTypeProperty(Type, writer, version);
if (Type is not null)
{
SerializeTypeProperty(Type, writer, version);
}

// allOf
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AllOf, callback);
Expand Down Expand Up @@ -657,7 +660,10 @@ internal void SerializeAsV2(
writer.WriteStartObject();

// type
SerializeTypeProperty(Type, writer, OpenApiSpecVersion.OpenApi2_0);
if (Type is not null)
{
SerializeTypeProperty(Type, writer, OpenApiSpecVersion.OpenApi2_0);
}

// description
writer.WriteProperty(OpenApiConstants.Description, Description);
Expand Down Expand Up @@ -836,7 +842,7 @@ private static int CountEnumSetFlags(JsonSchemaType? schemaType)
// Check each flag in the enum
foreach (JsonSchemaType value in System.Enum.GetValues(typeof(JsonSchemaType)))
{
// Ignore the None flag and check if the flag is set
// Check if the flag is set
if (schemaType.Value.HasFlag(value))
{
count++;
Expand Down

0 comments on commit 5eb0010

Please sign in to comment.