diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs index 1edd130f1..f02be33ee 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Linq; using System.Text.Json.Nodes; using Microsoft.OpenApi.Models; @@ -106,16 +107,13 @@ private static void ValidateMismatchedDataType(IValidationContext context, if (examples != null) { - foreach (var key in examples.Keys) + foreach (var key in examples.Keys.Where(k => examples[k] != null)) { - if (examples[key] != null) - { - context.Enter(key); - context.Enter("value"); - RuleHelpers.ValidateDataTypeMismatch(context, ruleName, examples[key]?.Value, schema); - context.Exit(); - context.Exit(); - } + context.Enter(key); + context.Enter("value"); + RuleHelpers.ValidateDataTypeMismatch(context, ruleName, examples[key]?.Value, schema); + context.Exit(); + context.Exit(); } }