From 88502940aed70915f3ff88c551d37db43d37ba45 Mon Sep 17 00:00:00 2001 From: Konrad Jamrozik Date: Tue, 23 Jul 2024 13:21:25 -0700 Subject: [PATCH] Fix NRE in CompareRequired (#345) --- .../src/modeler/AutoRest.Swagger/Model/Schema.cs | 10 ++++++---- package.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs b/openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs index e7094e3..3cee623 100644 --- a/openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs +++ b/openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs @@ -213,14 +213,16 @@ private void CompareRequired(ComparisonContext context, Schem var newRequiredNonReadOnlyPropNames = new List(); 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 diff --git a/package.json b/package.json index 81f630f..cf25bb5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@azure/oad", - "version": "0.10.12", + "version": "0.10.13", "author": { "name": "Microsoft Corporation", "email": "azsdkteam@microsoft.com",