diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 1068d5c..be569ec 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -180,11 +180,14 @@ namespace Microsoft.OpenApi.OData.Edm IEdmEntitySet entitySet = navigationSource as IEdmEntitySet; IEdmEntityType entityType = navigationSource.EntityType(); + CountRestrictionsType count = null; // for entity set, create a path with key and a $count path if (entitySet != null) { - CreateCountPath(path, convertSettings); + count = _model.GetRecord(entitySet, CapabilitiesConstants.CountRestrictions); + if(count?.Countable ?? true) + CreateCountPath(path, convertSettings); path.Push(new ODataKeySegment(entityType)); AppendPath(path.Clone()); @@ -198,7 +201,7 @@ namespace Microsoft.OpenApi.OData.Edm { if (CanFilter(np)) { - RetrieveNavigationPropertyPaths(np, path, convertSettings); + RetrieveNavigationPropertyPaths(np, count, path, convertSettings); } } @@ -252,9 +255,10 @@ namespace Microsoft.OpenApi.OData.Edm /// Retrieve the path for . /// /// The navigation property. + /// The count restrictions. /// The current OData path. /// The settings for the current conversion. - private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationProperty, ODataPath currentPath, OpenApiConvertSettings convertSettings) + private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationProperty, CountRestrictionsType count, ODataPath currentPath, OpenApiConvertSettings convertSettings) { Debug.Assert(navigationProperty != null); Debug.Assert(currentPath != null); @@ -280,8 +284,10 @@ namespace Microsoft.OpenApi.OData.Edm { IEdmEntityType navEntityType = navigationProperty.ToEntityType(); var targetsMany = navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many; + var propertyPath = navigationProperty.GetPartnerPath()?.Path; - if (targetsMany) + if (targetsMany && (string.IsNullOrEmpty(propertyPath) || + (count?.IsNonCountableNavigationProperty(propertyPath) ?? true))) { // ~/entityset/{key}/collection-valued-Nav/$count CreateCountPath(currentPath, convertSettings); @@ -323,7 +329,7 @@ namespace Microsoft.OpenApi.OData.Edm { if (CanFilter(subNavProperty)) { - RetrieveNavigationPropertyPaths(subNavProperty, currentPath, convertSettings); + RetrieveNavigationPropertyPaths(subNavProperty, count, currentPath, convertSettings); } } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs index 24ddffc..dfe27a3 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 @@ namespace Microsoft.OpenApi.OData.Edm.Tests // Assert Assert.NotNull(paths); - Assert.Equal(17194, paths.Count()); + Assert.Equal(17178, paths.Count()); } [Fact] @@ -67,7 +67,7 @@ namespace Microsoft.OpenApi.OData.Edm.Tests // Assert Assert.NotNull(paths); - Assert.Equal(17179, paths.Count()); + Assert.Equal(17163, paths.Count()); } [Fact]