Skip to content

Commit

Permalink
Fix NRE in CompareRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jul 23, 2024
1 parent 1bc9117 commit 4964899
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ private void CompareRequired(ComparisonContext<ServiceDefinition> context, Schem
var newRequiredNonReadOnlyPropNames = new List<string>();
foreach (string requiredPropName in Required)
{
Properties.TryGetValue(requiredPropName, out Schema propSchema);
priorSchema.Properties.TryGetValue(requiredPropName, out Schema priorPropSchema);
bool propWasRequired = priorSchema.Required?.Contains(requiredPropName) == true;
Schema propSchema = null;
Schema priorPropSchema = null;
Properties?.TryGetValue(requiredPropName, out propSchema);
priorSchema?.Properties?.TryGetValue(requiredPropName, out priorPropSchema);
bool propWasRequired = priorSchema?.Required?.Contains(requiredPropName) == true;
// Note that property is considered read-only only if it is consistently read-only both in the old and new models.
bool propIsReadOnly = propSchema?.ReadOnly == true && priorPropSchema?.ReadOnly == true;
if (!propWasRequired && !propIsReadOnly)
{
// Property is newly required and it is not read-only, hence it is a breaking change.
// Property is newly required, and it is not read-only, hence it is a breaking change.
newRequiredNonReadOnlyPropNames.Add(requiredPropName);
}
else
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/oad",
"version": "0.10.12",
"version": "0.10.13",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
Expand Down

0 comments on commit 4964899

Please sign in to comment.