Skip to content

Commit dedf3a2

Browse files
committed
Use pattern matching and the native count extension method
1 parent 0880d82 commit dedf3a2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ public override void Visit(ref JsonSchema schema)
206206
}
207207

208208
var builder = new JsonSchemaBuilder();
209-
foreach (var keyword in schema?.Keywords)
209+
if (schema?.Keywords is { } keywords)
210210
{
211-
builder.Add(keyword);
211+
foreach (var keyword in schema?.Keywords)
212+
{
213+
builder.Add(keyword);
214+
}
212215
}
213216

214217
ResolveJsonSchema(schema.GetItems(), r => builder.Items(r));

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ public static class JsonSchemaRules
3939

4040
if (jsonSchema.GetExamples() is { } examples)
4141
{
42-
var examplesCount = examples.Count();
43-
for (int i = 0; i < examplesCount; i++)
42+
for (int i = 0; i < examples.Count; i++)
4443
{
4544
context.Enter(i.ToString());
4645
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), examples.ElementAt(i), jsonSchema);
4746
context.Exit();
4847
}
49-
5048
}
5149

5250
context.Exit();

0 commit comments

Comments
 (0)