Skip to content

Commit c0cb0cc

Browse files
author
Vlad Barosan
authored
Merge pull request #109 from vladbarosan/fixRequired
Fix exception on null required params in new spec
2 parents f817f39 + df221f6 commit c0cb0cc

File tree

2 files changed

+3481
-6
lines changed

2 files changed

+3481
-6
lines changed

openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class Schema : SwaggerObject
6666

6767
private LinkedList<Schema> _visitedSchemas = new LinkedList<Schema>();
6868

69+
/// <inheritdoc />
6970
/// <summary>
7071
/// Compare a modified document node (this) to a previous one and look for breaking as well as non-breaking changes.
7172
/// </summary>
@@ -74,9 +75,7 @@ public class Schema : SwaggerObject
7475
/// <returns>A list of messages from the comparison.</returns>
7576
public override IEnumerable<ComparisonMessage> Compare(ComparisonContext context, SwaggerBase previous)
7677
{
77-
var priorSchema = previous as Schema;
78-
79-
if (priorSchema == null)
78+
if (!(previous is Schema priorSchema))
8079
{
8180
throw new ArgumentNullException("priorVersion");
8281
}
@@ -178,7 +177,7 @@ public override IEnumerable<ComparisonMessage> Compare(ComparisonContext context
178177
/// <param name="priorSchema">Schema of the old model</param>
179178
private void CompareRequired(ComparisonContext context, Schema priorSchema)
180179
{
181-
if (Required == null && priorSchema.Required == null)
180+
if (Required == null)
182181
{
183182
return;
184183
}
@@ -232,8 +231,7 @@ private void CompareProperties(ComparisonContext context, Schema priorSchema)
232231
{
233232
foreach (var def in priorSchema.Properties)
234233
{
235-
Schema model = null;
236-
if (Properties == null || !Properties.TryGetValue(def.Key, out model))
234+
if (Properties == null || !Properties.TryGetValue(def.Key, out var model))
237235
{
238236
context.LogBreakingChange(ComparisonMessages.RemovedProperty, def.Key);
239237
}

0 commit comments

Comments
 (0)