From fdebe42a717fedd9b336ae23645735022fee4179 Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Mon, 17 Sep 2018 17:16:51 -0700 Subject: [PATCH] Modify the bug for Operation path --- .../Edm/ODataPathProvider.cs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 17b3ec3..6b49ba6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -252,7 +252,7 @@ namespace Microsoft.OpenApi.OData.Edm } // 2. Search for generated navigation property - foreach(var path in npPaths) + foreach (var path in npPaths) { ODataNavigationPropertySegment npSegment = path.Segments.Last(s => s is ODataNavigationPropertySegment) as ODataNavigationPropertySegment; IEdmEntityType navPropertyEntityType = npSegment.NavigationProperty.ToEntityType(); @@ -262,13 +262,31 @@ namespace Microsoft.OpenApi.OData.Edm } bool isLastKeySegment = path.LastSegment is ODataKeySegment; - if ((isCollection && !isLastKeySegment) || (!isCollection && isLastKeySegment)) + + if (isCollection) { - ODataPath newPath = path.Clone(); - newPath.Push(new ODataOperationSegment(edmOperation)); - _allODataPaths.Add(newPath); - found = true; + if (isLastKeySegment) + { + continue; + } + + if (npSegment.NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many) + { + continue; + } } + else + { + if (!isLastKeySegment && npSegment.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many) + { + continue; + } + } + + ODataPath newPath = path.Clone(); + newPath.Push(new ODataOperationSegment(edmOperation)); + _allODataPaths.Add(newPath); + found = true; } if (found)