diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs index 9595f4ee..37084b61 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs @@ -199,26 +199,23 @@ private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestrict DeleteRestrictionsType navPropDeleteRestriction = restriction?.DeleteRestrictions ?? Context.Model.GetRecord(NavigationProperty); - if (NavigationProperty.ContainsTarget) - { - DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord(_navPropEntityType); - bool isDeletableDefault = navPropDeleteRestriction == null && entityDeleteRestriction == null; + if (!(NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment)) + return; - if ((isDeletableDefault || + DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord(_navPropEntityType); + bool isDeletable = + (navPropDeleteRestriction == null && entityDeleteRestriction == null) || ((entityDeleteRestriction?.IsDeletable ?? true) && - (navPropDeleteRestriction?.IsDeletable ?? true))) && - (NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || - LastSegmentIsKeySegment)) - { - AddOperation(item, OperationType.Delete); - } + (navPropDeleteRestriction?.IsDeletable ?? true)); + + if (NavigationProperty.ContainsTarget && isDeletable) + { + AddOperation(item, OperationType.Delete); } - else if ((navPropDeleteRestriction?.Deletable ?? false) && - (NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || - LastSegmentIsKeySegment)) + else if (navPropDeleteRestriction?.Deletable ?? false) { // Add delete operation for non-contained nav. props only if explicitly set to true via annotation - // Note: Use Deletable and not IsDeletable + // Note: Use Deletable and NOT IsDeletable AddOperation(item, OperationType.Delete); }