in openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs [204:238]
private void CompareRequired(ComparisonContext<ServiceDefinition> context, Schema priorSchema)
{
// If Required list is null then no properties are required in the new model,
// so there are no breaking changes.
if (Required == null)
{
return;
}
var newRequiredNonReadOnlyPropNames = new List<string>();
foreach (string requiredPropName in Required)
{
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.
newRequiredNonReadOnlyPropNames.Add(requiredPropName);
}
else
{
// Property was required and is required, or it is read-only, hence it is not a breaking change.
}
}
if (newRequiredNonReadOnlyPropNames.Any())
{
context.LogBreakingChange(ComparisonMessages.AddedRequiredProperty, string.Join(", ", newRequiredNonReadOnlyPropNames));
}
}