Skip to content

Commit

Permalink
Fixes missing bound operations on some navigation property paths (#227)
Browse files Browse the repository at this point in the history
* Remove conditions preventing generation of bound operations for other paths

* Update integration tests
  • Loading branch information
irvinesunday authored May 30, 2022
1 parent 0bfd9b3 commit 33efcb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
49 changes: 8 additions & 41 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,29 +614,16 @@ bool filter(IEdmNavigationSource z) =>
foreach (var bindingEntityType in allEntitiesForOperation)
{
// 1. Search for corresponding navigation source path
if (AppendBoundOperationOnNavigationSourcePath(edmOperation, isCollection, bindingEntityType))
{
continue;
}
AppendBoundOperationOnNavigationSourcePath(edmOperation, isCollection, bindingEntityType);

// 2. Search for generated navigation property
if (AppendBoundOperationOnNavigationPropertyPath(edmOperation, isCollection, bindingEntityType))
{
continue;
}
AppendBoundOperationOnNavigationPropertyPath(edmOperation, isCollection, bindingEntityType);

// 3. Search for derived
if (AppendBoundOperationOnDerived(edmOperation, isCollection, bindingEntityType, convertSettings))
{
continue;
}
AppendBoundOperationOnDerived(edmOperation, isCollection, bindingEntityType, convertSettings);

// 4. Search for derived generated navigation property
if (AppendBoundOperationOnDerivedNavigationPropertyPath(edmOperation, isCollection, bindingEntityType, convertSettings))
{
continue;
}

AppendBoundOperationOnDerivedNavigationPropertyPath(edmOperation, isCollection, bindingEntityType, convertSettings);
}
}
}
Expand All @@ -646,10 +633,8 @@ bool filter(IEdmNavigationSource z) =>
ODataPathKind.DollarCount,
ODataPathKind.ComplexProperty,
};
private bool AppendBoundOperationOnNavigationSourcePath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
private void AppendBoundOperationOnNavigationSourcePath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
{
bool found = false;

if (_allNavigationSourcePaths.TryGetValue(bindingEntityType, out IList<ODataPath> value))
{
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
Expand All @@ -676,19 +661,15 @@ secondLastPathSegment is not ODataKeySegment &&
ODataPath newPath = subPath.Clone();
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
}
}

return found;
}
private static readonly HashSet<ODataPathKind> _pathKindToSkipForNavigationProperties = new () {
ODataPathKind.Ref,
};
private bool AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
private void AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
{
bool found = false;
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);

if (_allNavigationPropertyPaths.TryGetValue(bindingEntityType, out IList<ODataPath> value))
Expand Down Expand Up @@ -727,21 +708,16 @@ private bool AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera
ODataPath newPath = path.Clone();
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
}

return found;
}

private bool AppendBoundOperationOnDerived(
private void AppendBoundOperationOnDerived(
IEdmOperation edmOperation,
bool isCollection,
IEdmEntityType bindingEntityType,
OpenApiConvertSettings convertSettings)
{
bool found = false;

bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
foreach (var baseType in bindingEntityType.FindAllBaseTypes())
{
Expand All @@ -764,7 +740,6 @@ private bool AppendBoundOperationOnDerived(
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
}
else
Expand All @@ -774,22 +749,18 @@ private bool AppendBoundOperationOnDerived(
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
else
{
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()),
new ODataTypeCastSegment(bindingEntityType),
new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
}
}
}
}

return found;
}

private bool HasUnsatisfiedDerivedTypeConstraint(
Expand All @@ -804,13 +775,12 @@ private bool HasUnsatisfiedDerivedTypeConstraint(
private IEnumerable<string> GetDerivedTypeConstaintTypeNames(IEdmVocabularyAnnotatable annotatable) =>
_model.GetCollection(annotatable, "Org.OData.Validation.V1.DerivedTypeConstraint") ?? Enumerable.Empty<string>();

private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
private void AppendBoundOperationOnDerivedNavigationPropertyPath(
IEdmOperation edmOperation,
bool isCollection,
IEdmEntityType bindingEntityType,
OpenApiConvertSettings convertSettings)
{
bool found = false;
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);

foreach (var baseType in bindingEntityType.FindAllBaseTypes())
Expand Down Expand Up @@ -865,12 +835,9 @@ private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
newPath.Push(new ODataTypeCastSegment(bindingEntityType));
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
AppendPath(newPath);
found = true;
}
}
}

return found;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(14624, paths.Count());
Assert.Equal(16354, paths.Count());
}

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

// Assert
Assert.NotNull(paths);
Assert.Equal(14582, paths.Count());
Assert.Equal(15293, paths.Count());
}

[Fact]
Expand Down

0 comments on commit 33efcb0

Please sign in to comment.