Skip to content

Commit

Permalink
PR suggestion; simplify conditional statements
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinesunday committed Feb 1, 2024
1 parent 911b899 commit 0ddf800
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,23 @@ private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestrict
DeleteRestrictionsType navPropDeleteRestriction = restriction?.DeleteRestrictions ??
Context.Model.GetRecord<DeleteRestrictionsType>(NavigationProperty);

if (NavigationProperty.ContainsTarget)
{
DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(_navPropEntityType);
bool isDeletableDefault = navPropDeleteRestriction == null && entityDeleteRestriction == null;
if (!(NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment))
return;

if ((isDeletableDefault ||
DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(_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);
}

Expand Down

0 comments on commit 0ddf800

Please sign in to comment.