Skip to content
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
10 changes: 10 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ private bool AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera

ODataNavigationPropertySegment npSegment = path.Segments.Last(s => s is ODataNavigationPropertySegment) as ODataNavigationPropertySegment;

if (!npSegment.NavigationProperty.ContainsTarget)
{
continue;
}

bool isLastKeySegment = path.LastSegment is ODataKeySegment;

if (isCollection)
Expand Down Expand Up @@ -605,6 +610,11 @@ private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
continue;
}

if (!npSegment.NavigationProperty.ContainsTarget)
{
continue;
}

bool isLastKeySegment = path.LastSegment is ODataKeySegment;

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

// Assert
Assert.NotNull(paths);
Assert.Equal(17401, paths.Count());
Assert.Equal(13727, paths.Count());
}

[Fact]
Expand All @@ -67,7 +67,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(13730, paths.Count());
Assert.Equal(13712, paths.Count());
}

[Fact]
Expand Down Expand Up @@ -276,6 +276,80 @@ public void GetPathsWithBoundActionOperationWorks()
Assert.Contains("/Customers({ID})/NS.renew", paths.Select(p => p.GetPathItemName()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetPathsWithBoundActionOperationForContainmentNavigationPropertyPathsWorks(bool containsTarget)
{
// Arrange
string navProp = $@"<NavigationProperty Name=""Referral"" Type=""NS.NiceCustomer"" ContainsTarget=""{containsTarget}""/>";
string boundAction =
@"<Action Name=""Ack"" IsBound=""true"">
<Parameter Name=""bindingParameter"" Type=""NS.NiceCustomer"" />
<ReturnType Type=""Edm.Boolean"" />
</Action>
<EntityType Name=""NiceCustomer"">
<Property Name=""Other"" Type=""Edm.Int32"" Nullable=""true"" />
</EntityType>";

IEdmModel model = GetEdmModel(boundAction, "", navProp);
ODataPathProvider provider = new ODataPathProvider();
var settings = new OpenApiConvertSettings();

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

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

if (containsTarget)
{
Assert.Contains("/Customers({ID})/Referral/NS.Ack", paths.Select(p => p.GetPathItemName()));
}
else
{
Assert.DoesNotContain("/Customers({ID})/Referral/NS.Ack", paths.Select(p => p.GetPathItemName()));
}
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetPathsWithBoundFunctionOperationForContainmentNavigationPropertyPathsWorks(bool containsTarget)
{
// Arrange
string navProp = $@"<NavigationProperty Name=""Referral"" Type=""NS.NiceCustomer"" ContainsTarget=""{containsTarget}""/>";
string boundAction =
@"<Function Name=""Search"" IsBound=""true"">
<Parameter Name=""bindingParameter"" Type=""NS.NiceCustomer"" />
<ReturnType Type=""Collection(NS.Customer)"" />
</Function>
<EntityType Name=""NiceCustomer"">
<Property Name=""Other"" Type=""Edm.Int32"" Nullable=""true"" />
</EntityType>";

IEdmModel model = GetEdmModel(boundAction, "", navProp);
ODataPathProvider provider = new ODataPathProvider();
var settings = new OpenApiConvertSettings();

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

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

if (containsTarget)
{
Assert.Contains("/Customers({ID})/Referral/NS.Search()", paths.Select(p => p.GetPathItemName()));
}
else
{
Assert.DoesNotContain("/Customers({ID})/Referral/NS.Search()", paths.Select(p => p.GetPathItemName()));
}
}

[Fact]
public void GetPathsWithUnboundOperationImportWorks()
{
Expand Down Expand Up @@ -500,7 +574,7 @@ public void GetPathsWithStreamPropertyAndWithEntityHasStreamWorks(bool hasStream
}
}

private static IEdmModel GetEdmModel(string schemaElement, string containerElement)
private static IEdmModel GetEdmModel(string schemaElement, string containerElement, string propertySchema = null)
{
string template = $@"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""NS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
Expand All @@ -509,6 +583,7 @@ private static IEdmModel GetEdmModel(string schemaElement, string containerEleme
<PropertyRef Name=""ID"" />
</Key>
<Property Name=""ID"" Type=""Edm.Int32"" Nullable=""false"" />
{propertySchema}
</EntityType>
{schemaElement}
<EntityContainer Name =""Default"">
Expand Down