From 0fc32f0cd94371fc3f03e6f6748851449d7ea653 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 17 Jan 2022 11:55:25 +0300 Subject: [PATCH 1/9] Remove unnecessary code --- .../Edm/EdmModelExtensions.cs | 38 +------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs index 7631419d..4755298c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs @@ -124,43 +124,7 @@ public static IEnumerable FindAllBaseTypes(this IEdmEntityType e current = current.BaseEntityType(); } } - - /// - /// Checks if the is assignable to . - /// In other words, if is a subtype of or not. - /// - /// Type of the base type. - /// Type of the sub type. - /// true, if the is assignable to . Otherwise returns false. - public static bool IsAssignableFrom(this IEdmEntityType baseType, IEdmEntityType subtype) - { - Utils.CheckArgumentNull(baseType, nameof(baseType)); - Utils.CheckArgumentNull(subtype, nameof(subtype)); - - if (baseType.TypeKind != subtype.TypeKind) - { - return false; - } - - if (subtype.IsEquivalentTo(baseType)) - { - return true; - } - - IEdmStructuredType structuredSubType = subtype; - while (structuredSubType != null) - { - if (structuredSubType.IsEquivalentTo(baseType)) - { - return true; - } - - structuredSubType = structuredSubType.BaseType; - } - - return false; - } - + /// /// Check whether the operation is overload in the model. /// From 3355bb85075deaeb17422cc2751c6f239b9cf55a Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 17 Jan 2022 11:56:09 +0300 Subject: [PATCH 2/9] Expand nav. prop. based on identifier name and not type --- .../Edm/ODataPathProvider.cs | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index baa37717..28736b85 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -273,6 +273,15 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr Debug.Assert(navigationProperty != null); Debug.Assert(currentPath != null); + // Check whether the navigation property has already been navigated in the path + foreach (ODataSegment segment in currentPath) + { + if (navigationProperty.Name.Equals(segment.Identifier)) + { + return; + } + } + // Check whether the navigation property should be part of the path NavigationRestrictionsType navigation = _model.GetRecord(navigationProperty, CapabilitiesConstants.NavigationRestrictions); if (navigation != null && !navigation.IsNavigable) @@ -281,7 +290,7 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr } // test the expandable for the navigation property. - bool shouldExpand = ShouldExpandNavigationProperty(navigationProperty, currentPath); + bool shouldExpand = navigationProperty.ContainsTarget; // append a navigation property. currentPath.Push(new ODataNavigationPropertySegment(navigationProperty)); @@ -362,31 +371,7 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr } } currentPath.Pop(); - } - - private bool ShouldExpandNavigationProperty(IEdmNavigationProperty navigationProperty, ODataPath currentPath) - { - Debug.Assert(navigationProperty != null); - Debug.Assert(currentPath != null); - - // not expand for the non-containment. - if (!navigationProperty.ContainsTarget) - { - return false; - } - - // check the type is visited before, if visited, not expand it. - IEdmEntityType navEntityType = navigationProperty.ToEntityType(); - foreach (ODataSegment segment in currentPath) - { - if (navEntityType.IsAssignableFrom(segment.EntityType)) - { - return false; - } - } - - return true; - } + } /// /// Create $ref paths. From 475fca7a68508bb9fd8596ca514ee93b170e39f7 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 17 Jan 2022 13:12:00 +0300 Subject: [PATCH 3/9] Update tests --- .../Edm/ODataPathProviderTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs index 6c578ff4..c1c975b3 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs @@ -48,7 +48,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(17178, paths.Count()); + Assert.Equal(57490, paths.Count()); } [Fact] @@ -67,7 +67,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(17163, paths.Count()); + Assert.Equal(57469, paths.Count()); } [Fact] From bbed6d24dd68996387658af6ba7dc8d5e5a37bd7 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 17 Jan 2022 15:53:20 +0300 Subject: [PATCH 4/9] Update comment --- src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 28736b85..f2dc39ad 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -289,7 +289,7 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr return; } - // test the expandable for the navigation property. + // Whether to expand the navigation property bool shouldExpand = navigationProperty.ContainsTarget; // append a navigation property. From 8d18b047f82d07aef077fc9c89eb1e27c9198f0b Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Mon, 17 Jan 2022 17:55:53 +0300 Subject: [PATCH 5/9] Re-add method and add obsolete attribute --- .../Edm/EdmModelExtensions.cs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs index 4755298c..d593d8a6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/EdmModelExtensions.cs @@ -124,7 +124,44 @@ public static IEnumerable FindAllBaseTypes(this IEdmEntityType e current = current.BaseEntityType(); } } - + + /// + /// Checks if the is assignable to . + /// In other words, if is a subtype of or not. + /// + /// Type of the base type. + /// Type of the sub type. + /// true, if the is assignable to . Otherwise returns false. + [Obsolete] + public static bool IsAssignableFrom(this IEdmEntityType baseType, IEdmEntityType subtype) + { + Utils.CheckArgumentNull(baseType, nameof(baseType)); + Utils.CheckArgumentNull(subtype, nameof(subtype)); + + if (baseType.TypeKind != subtype.TypeKind) + { + return false; + } + + if (subtype.IsEquivalentTo(baseType)) + { + return true; + } + + IEdmStructuredType structuredSubType = subtype; + while (structuredSubType != null) + { + if (structuredSubType.IsEquivalentTo(baseType)) + { + return true; + } + + structuredSubType = structuredSubType.BaseType; + } + + return false; + } + /// /// Check whether the operation is overload in the model. /// From 2a0fe271b042137aa8e1e20f4268dd3071515c63 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 20 Jan 2022 14:38:43 +0300 Subject: [PATCH 6/9] Expand all containment navigation properties Don't check on the defining type to determine whether or not to expand, but on whether the navigation property has already been navigated in the path --- .../Edm/ODataPathProvider.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 161fb29f..189c3a59 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -324,18 +324,28 @@ private void RetrieveMediaEntityStreamPaths(IEdmEntityType entityType, ODataPath /// The count restrictions. /// The current OData path. /// The settings for the current conversion. - private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationProperty, CountRestrictionsType count, ODataPath currentPath, OpenApiConvertSettings convertSettings) + /// A stack that holds the visited navigation properties in the . + private void RetrieveNavigationPropertyPaths( + IEdmNavigationProperty navigationProperty, + CountRestrictionsType count, + ODataPath currentPath, + OpenApiConvertSettings convertSettings, + Stack visitedNavigationProperties = null) { Debug.Assert(navigationProperty != null); Debug.Assert(currentPath != null); + if (visitedNavigationProperties == null) + { + visitedNavigationProperties = new Stack(); + } + + var navPropFullyQualifiedName = $"{navigationProperty.DeclaringType.FullTypeName()}/{navigationProperty.Name}"; + // Check whether the navigation property has already been navigated in the path - foreach (ODataSegment segment in currentPath) + if (visitedNavigationProperties.Contains(navPropFullyQualifiedName)) { - if (navigationProperty.Name.Equals(segment.Identifier)) - { - return; - } + return; } // Check whether the navigation property should be part of the path @@ -351,6 +361,7 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr // append a navigation property. currentPath.Push(new ODataNavigationPropertySegment(navigationProperty)); AppendPath(currentPath.Clone()); + visitedNavigationProperties.Push(navPropFullyQualifiedName); // Check whether a collection-valued navigation property should be indexed by key value(s). NavigationPropertyRestriction restriction = navigation?.RestrictedProperties?.FirstOrDefault(); @@ -421,7 +432,7 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr { if (CanFilter(subNavProperty)) { - RetrieveNavigationPropertyPaths(subNavProperty, count, currentPath, convertSettings); + RetrieveNavigationPropertyPaths(subNavProperty, count, currentPath, convertSettings, visitedNavigationProperties); } } } @@ -430,9 +441,10 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr if (targetsMany) { currentPath.Pop(); - } + } } currentPath.Pop(); + visitedNavigationProperties.Pop(); } /// From 0b05d214934aa7069b048b8a748a8f35e96030ec Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 20 Jan 2022 14:39:00 +0300 Subject: [PATCH 7/9] Update tests --- .../Edm/ODataPathProviderTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs index 739b36f7..1bf649f9 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs @@ -48,7 +48,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(50085, paths.Count()); + Assert.Equal(1413958, paths.Count()); } [Fact] @@ -67,7 +67,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(50070, paths.Count()); + Assert.Equal(1413937, paths.Count()); } [Fact] From 808e768dd0709f301c685ff6566519ddfd5b2d3d Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Wed, 9 Feb 2022 12:06:21 +0300 Subject: [PATCH 8/9] Update Beta integration file and tests --- .../Edm/ODataPathProviderTests.cs | 4 +- .../Resources/Graph.Beta.OData.xml | 42 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs index 2d5b997b..aae0001c 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs @@ -48,7 +48,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(28227, paths.Count()); + Assert.Equal(26436, paths.Count()); } [Fact] @@ -67,7 +67,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths() // Assert Assert.NotNull(paths); - Assert.Equal(28193, paths.Count()); + Assert.Equal(26394, paths.Count()); } [Fact] diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Graph.Beta.OData.xml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Graph.Beta.OData.xml index adb78aa9..e8b90f17 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Graph.Beta.OData.xml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Graph.Beta.OData.xml @@ -1,4 +1,4 @@ - + @@ -7799,7 +7799,7 @@ - + @@ -8120,11 +8120,11 @@ - + - + @@ -13878,7 +13878,7 @@ - + @@ -13908,9 +13908,9 @@ - + - + @@ -15724,7 +15724,7 @@ - + @@ -15738,14 +15738,14 @@ - + - + @@ -25182,8 +25182,8 @@ - - + + @@ -25192,7 +25192,7 @@ - + @@ -25216,7 +25216,7 @@ - + @@ -25511,7 +25511,7 @@ - + @@ -25528,7 +25528,7 @@ - + @@ -25544,7 +25544,7 @@ - + @@ -25553,8 +25553,8 @@ - - + + @@ -25566,7 +25566,7 @@ - + @@ -71196,7 +71196,7 @@ - + From 0ef6d39431c8879ceecd941ee45d62b501ca7878 Mon Sep 17 00:00:00 2001 From: Irvine Sunday <40403681+irvinesunday@users.noreply.github.com> Date: Wed, 9 Feb 2022 19:49:26 +0300 Subject: [PATCH 9/9] Update src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs Co-authored-by: Vincent Biret --- src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index ce43513d..77324149 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -337,7 +337,7 @@ private void RetrieveNavigationPropertyPaths( if (visitedNavigationProperties == null) { - visitedNavigationProperties = new Stack(); + visitedNavigationProperties = new (); } var navPropFullyQualifiedName = $"{navigationProperty.DeclaringType.FullTypeName()}/{navigationProperty.Name}";