From 0ddf800e67a0dd4cdc72dc519874143989b7a323 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 1 Feb 2024 17:22:33 +0300 Subject: [PATCH] PR suggestion; simplify conditional statements --- .../NavigationPropertyPathItemHandler.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) 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); }