Skip to content

Commit a478bd2

Browse files
committed
Use Where for sequence filtering
1 parent ae0c5a0 commit a478bd2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
5+
using System.Linq;
56
using System.Text.Json.Nodes;
67
using Microsoft.OpenApi.Models;
78

@@ -106,16 +107,13 @@ private static void ValidateMismatchedDataType(IValidationContext context,
106107

107108
if (examples != null)
108109
{
109-
foreach (var key in examples.Keys)
110+
foreach (var key in examples.Keys.Where(k => examples[k] != null))
110111
{
111-
if (examples[key] != null)
112-
{
113-
context.Enter(key);
114-
context.Enter("value");
115-
RuleHelpers.ValidateDataTypeMismatch(context, ruleName, examples[key]?.Value, schema);
116-
context.Exit();
117-
context.Exit();
118-
}
112+
context.Enter(key);
113+
context.Enter("value");
114+
RuleHelpers.ValidateDataTypeMismatch(context, ruleName, examples[key]?.Value, schema);
115+
context.Exit();
116+
context.Exit();
119117
}
120118
}
121119

0 commit comments

Comments
 (0)