Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,40 +254,41 @@ private void RetrieveNavigationPropertyPaths(IEdmNavigationProperty navigationPr
newPath.Push(ODataRefSegment.Instance); // $ref
AppendPath(newPath);
}

// append a navigation property key.
IEdmEntityType navEntityType = navigationProperty.ToEntityType();
if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
else
{
currentPath.Push(new ODataKeySegment(navEntityType));
AppendPath(currentPath.Clone());
IEdmEntityType navEntityType = navigationProperty.ToEntityType();

if (!navigationProperty.ContainsTarget)
// append a navigation property key.
if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
// TODO: Shall we add "$ref" after {key}, and only support delete?
// ODataPath newPath = currentPath.Clone();
// newPath.Push(ODataRefSegment.Instance); // $ref
// AppendPath(newPath);
currentPath.Push(new ODataKeySegment(navEntityType));
AppendPath(currentPath.Clone());

if (!navigationProperty.ContainsTarget)
{
// TODO: Shall we add "$ref" after {key}, and only support delete?
// ODataPath newPath = currentPath.Clone();
// newPath.Push(ODataRefSegment.Instance); // $ref
// AppendPath(newPath);
}
}
}

if (shouldExpand)
{
// expand to sub navigation properties
foreach (IEdmNavigationProperty subNavProperty in navEntityType.DeclaredNavigationProperties())
if (shouldExpand)
{
if (CanFilter(subNavProperty))
// expand to sub navigation properties
foreach (IEdmNavigationProperty subNavProperty in navEntityType.DeclaredNavigationProperties())
{
RetrieveNavigationPropertyPaths(subNavProperty, currentPath);
if (CanFilter(subNavProperty))
{
RetrieveNavigationPropertyPaths(subNavProperty, currentPath);
}
}
}
if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
currentPath.Pop();
}
}

if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
currentPath.Pop();
}

currentPath.Pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(4585, paths.Count());
Assert.Equal(4457, paths.Count());
}

[Fact]
Expand Down Expand Up @@ -149,7 +149,7 @@ public void GetPathsWithUnboundOperationImportWorks()
}

[Fact]
public void GetPathsWithNavigationPropertytWorks()
public void GetPathsWithNonContainedNavigationPropertytWorks()
{
// Arrange
string entityType =
Expand All @@ -171,16 +171,45 @@ public void GetPathsWithNavigationPropertytWorks()

// Assert
Assert.NotNull(paths);
Assert.Equal(9, paths.Count());
Assert.Equal(8, paths.Count());

var pathItems = paths.Select(p => p.GetPathItemName()).ToList();
Assert.Contains("/Orders({id})/MultipleCustomers", pathItems);
Assert.Contains("/Orders({id})/MultipleCustomers({ID})", pathItems);
Assert.Contains("/Orders({id})/SingleCustomer", pathItems);
Assert.Contains("/Orders({id})/SingleCustomer/$ref", pathItems);
Assert.Contains("/Orders({id})/MultipleCustomers/$ref", pathItems);
}

[Fact]
public void GetPathsWithContainedNavigationPropertytWorks()
{
// Arrange
string entityType =
@"<EntityType Name=""Order"">
<Key>
<PropertyRef Name=""id"" />
</Key>
<NavigationProperty Name=""MultipleCustomers"" Type=""Collection(NS.Customer)"" ContainsTarget=""true"" />
<NavigationProperty Name=""SingleCustomer"" Type=""NS.Customer"" ContainsTarget=""true"" />
</EntityType>";

string entitySet = @"<EntitySet Name=""Orders"" EntityType=""NS.Order"" />";
IEdmModel model = GetEdmModel(entityType, entitySet);
ODataPathProvider provider = new ODataPathProvider();

// Act
var paths = provider.GetPaths(model);

// Assert
Assert.NotNull(paths);
Assert.Equal(7, paths.Count());

var pathItems = paths.Select(p => p.GetPathItemName()).ToList();
Assert.Contains("/Orders({id})/MultipleCustomers", pathItems);
Assert.Contains("/Orders({id})/MultipleCustomers({ID})", pathItems);
Assert.Contains("/Orders({id})/SingleCustomer", pathItems);
}

[Theory]
[InlineData(true, "Logo")]
[InlineData(false, "Logo")]
Expand Down
Loading