- adds support for reading annotations for count restrictions for count path

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
This commit is contained in:
Vincent Biret 2021-11-23 11:37:48 -05:00
parent 4093249a19
commit 5d910fd29b
No known key found for this signature in database
GPG key ID: 32426322EDFFB7E3
2 changed files with 13 additions and 7 deletions

View file

@ -180,11 +180,14 @@ namespace Microsoft.OpenApi.OData.Edm
IEdmEntitySet entitySet = navigationSource as IEdmEntitySet; IEdmEntitySet entitySet = navigationSource as IEdmEntitySet;
IEdmEntityType entityType = navigationSource.EntityType(); IEdmEntityType entityType = navigationSource.EntityType();
CountRestrictionsType count = null;
// for entity set, create a path with key and a $count path // for entity set, create a path with key and a $count path
if (entitySet != null) if (entitySet != null)
{ {
CreateCountPath(path, convertSettings); count = _model.GetRecord<CountRestrictionsType>(entitySet, CapabilitiesConstants.CountRestrictions);
if(count?.Countable ?? true)
CreateCountPath(path, convertSettings);
path.Push(new ODataKeySegment(entityType)); path.Push(new ODataKeySegment(entityType));
AppendPath(path.Clone()); AppendPath(path.Clone());
@ -198,7 +201,7 @@ namespace Microsoft.OpenApi.OData.Edm
{ {
if (CanFilter(np)) 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 <see cref="IEdmNavigationProperty"/>. /// Retrieve the path for <see cref="IEdmNavigationProperty"/>.
/// </summary> /// </summary>
/// <param name="navigationProperty">The navigation property.</param> /// <param name="navigationProperty">The navigation property.</param>
/// <param name="count">The count restrictions.</param>
/// <param name="currentPath">The current OData path.</param> /// <param name="currentPath">The current OData path.</param>
/// <param name="convertSettings">The settings for the current conversion.</param> /// <param name="convertSettings">The settings for the current conversion.</param>
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(navigationProperty != null);
Debug.Assert(currentPath != null); Debug.Assert(currentPath != null);
@ -280,8 +284,10 @@ namespace Microsoft.OpenApi.OData.Edm
{ {
IEdmEntityType navEntityType = navigationProperty.ToEntityType(); IEdmEntityType navEntityType = navigationProperty.ToEntityType();
var targetsMany = navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many; 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 // ~/entityset/{key}/collection-valued-Nav/$count
CreateCountPath(currentPath, convertSettings); CreateCountPath(currentPath, convertSettings);
@ -323,7 +329,7 @@ namespace Microsoft.OpenApi.OData.Edm
{ {
if (CanFilter(subNavProperty)) if (CanFilter(subNavProperty))
{ {
RetrieveNavigationPropertyPaths(subNavProperty, currentPath, convertSettings); RetrieveNavigationPropertyPaths(subNavProperty, count, currentPath, convertSettings);
} }
} }
} }

View file

@ -48,7 +48,7 @@ namespace Microsoft.OpenApi.OData.Edm.Tests
// Assert // Assert
Assert.NotNull(paths); Assert.NotNull(paths);
Assert.Equal(17194, paths.Count()); Assert.Equal(17178, paths.Count());
} }
[Fact] [Fact]
@ -67,7 +67,7 @@ namespace Microsoft.OpenApi.OData.Edm.Tests
// Assert // Assert
Assert.NotNull(paths); Assert.NotNull(paths);
Assert.Equal(17179, paths.Count()); Assert.Equal(17163, paths.Count());
} }
[Fact] [Fact]