Skip to content

Commit

Permalink
Simplify by using .Where() for sequence filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Aug 2, 2024
1 parent 91f83f8 commit 28142d5
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ private void SerializeExamples(IOpenApiWriter writer, IDictionary<string, OpenAp
{
writer.WritePropertyName(OpenApiConstants.Examples);
writer.WriteStartObject();
foreach (var kvp in examples)
foreach (var kvp in examples.Where(kvp => kvp.Value.Value is OpenApiArray arr && arr.Count == 0))
{
if (kvp.Value.Value is OpenApiArray arr && arr.Count == 0)
{
writer.WritePropertyName(kvp.Key);
writer.WriteStartObject();
writer.WriteRequiredObject(OpenApiConstants.Value, kvp.Value.Value, (w, v) => w.WriteAny(v));
writer.WriteEndObject();
}
writer.WritePropertyName(kvp.Key);
writer.WriteStartObject();
writer.WriteRequiredObject(OpenApiConstants.Value, kvp.Value.Value, (w, v) => w.WriteAny(v));
writer.WriteEndObject();
}
writer.WriteEndObject();
}
Expand Down

0 comments on commit 28142d5

Please sign in to comment.