Skip to content

Commit 33efcb0

Browse files
authored
Fixes missing bound operations on some navigation property paths (#227)
* Remove conditions preventing generation of bound operations for other paths * Update integration tests
1 parent 0bfd9b3 commit 33efcb0

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -614,29 +614,16 @@ bool filter(IEdmNavigationSource z) =>
614614
foreach (var bindingEntityType in allEntitiesForOperation)
615615
{
616616
// 1. Search for corresponding navigation source path
617-
if (AppendBoundOperationOnNavigationSourcePath(edmOperation, isCollection, bindingEntityType))
618-
{
619-
continue;
620-
}
617+
AppendBoundOperationOnNavigationSourcePath(edmOperation, isCollection, bindingEntityType);
621618

622619
// 2. Search for generated navigation property
623-
if (AppendBoundOperationOnNavigationPropertyPath(edmOperation, isCollection, bindingEntityType))
624-
{
625-
continue;
626-
}
620+
AppendBoundOperationOnNavigationPropertyPath(edmOperation, isCollection, bindingEntityType);
627621

628622
// 3. Search for derived
629-
if (AppendBoundOperationOnDerived(edmOperation, isCollection, bindingEntityType, convertSettings))
630-
{
631-
continue;
632-
}
623+
AppendBoundOperationOnDerived(edmOperation, isCollection, bindingEntityType, convertSettings);
633624

634625
// 4. Search for derived generated navigation property
635-
if (AppendBoundOperationOnDerivedNavigationPropertyPath(edmOperation, isCollection, bindingEntityType, convertSettings))
636-
{
637-
continue;
638-
}
639-
626+
AppendBoundOperationOnDerivedNavigationPropertyPath(edmOperation, isCollection, bindingEntityType, convertSettings);
640627
}
641628
}
642629
}
@@ -646,10 +633,8 @@ bool filter(IEdmNavigationSource z) =>
646633
ODataPathKind.DollarCount,
647634
ODataPathKind.ComplexProperty,
648635
};
649-
private bool AppendBoundOperationOnNavigationSourcePath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
636+
private void AppendBoundOperationOnNavigationSourcePath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
650637
{
651-
bool found = false;
652-
653638
if (_allNavigationSourcePaths.TryGetValue(bindingEntityType, out IList<ODataPath> value))
654639
{
655640
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
@@ -676,19 +661,15 @@ secondLastPathSegment is not ODataKeySegment &&
676661
ODataPath newPath = subPath.Clone();
677662
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
678663
AppendPath(newPath);
679-
found = true;
680664
}
681665
}
682666
}
683-
684-
return found;
685667
}
686668
private static readonly HashSet<ODataPathKind> _pathKindToSkipForNavigationProperties = new () {
687669
ODataPathKind.Ref,
688670
};
689-
private bool AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
671+
private void AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
690672
{
691-
bool found = false;
692673
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
693674

694675
if (_allNavigationPropertyPaths.TryGetValue(bindingEntityType, out IList<ODataPath> value))
@@ -727,21 +708,16 @@ private bool AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera
727708
ODataPath newPath = path.Clone();
728709
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
729710
AppendPath(newPath);
730-
found = true;
731711
}
732712
}
733-
734-
return found;
735713
}
736714

737-
private bool AppendBoundOperationOnDerived(
715+
private void AppendBoundOperationOnDerived(
738716
IEdmOperation edmOperation,
739717
bool isCollection,
740718
IEdmEntityType bindingEntityType,
741719
OpenApiConvertSettings convertSettings)
742720
{
743-
bool found = false;
744-
745721
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
746722
foreach (var baseType in bindingEntityType.FindAllBaseTypes())
747723
{
@@ -764,7 +740,6 @@ private bool AppendBoundOperationOnDerived(
764740
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
765741
new ODataOperationSegment(edmOperation, isEscapedFunction));
766742
AppendPath(newPath);
767-
found = true;
768743
}
769744
}
770745
else
@@ -774,22 +749,18 @@ private bool AppendBoundOperationOnDerived(
774749
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
775750
new ODataOperationSegment(edmOperation, isEscapedFunction));
776751
AppendPath(newPath);
777-
found = true;
778752
}
779753
else
780754
{
781755
ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()),
782756
new ODataTypeCastSegment(bindingEntityType),
783757
new ODataOperationSegment(edmOperation, isEscapedFunction));
784758
AppendPath(newPath);
785-
found = true;
786759
}
787760
}
788761
}
789762
}
790763
}
791-
792-
return found;
793764
}
794765

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

807-
private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
778+
private void AppendBoundOperationOnDerivedNavigationPropertyPath(
808779
IEdmOperation edmOperation,
809780
bool isCollection,
810781
IEdmEntityType bindingEntityType,
811782
OpenApiConvertSettings convertSettings)
812783
{
813-
bool found = false;
814784
bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);
815785

816786
foreach (var baseType in bindingEntityType.FindAllBaseTypes())
@@ -865,12 +835,9 @@ private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
865835
newPath.Push(new ODataTypeCastSegment(bindingEntityType));
866836
newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
867837
AppendPath(newPath);
868-
found = true;
869838
}
870839
}
871840
}
872-
873-
return found;
874841
}
875842
}
876843
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataPathProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()
5151

5252
// Assert
5353
Assert.NotNull(paths);
54-
Assert.Equal(14624, paths.Count());
54+
Assert.Equal(16354, paths.Count());
5555
}
5656

5757
[Fact]
@@ -71,7 +71,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
7171

7272
// Assert
7373
Assert.NotNull(paths);
74-
Assert.Equal(14582, paths.Count());
74+
Assert.Equal(15293, paths.Count());
7575
}
7676

7777
[Fact]

0 commit comments

Comments
 (0)