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
19 changes: 16 additions & 3 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,34 @@ bool filter(IEdmStructuredType x) =>
.OfType<IEdmStructuredType>()
.ToArray();

foreach(var targetType in targetTypes)
foreach (var targetType in targetTypes)
{
var castPath = currentPath.Clone();
var targetTypeSegment = new ODataTypeCastSegment(targetType);

if (currentPath.Segments.Any(x => x.Identifier.Equals(targetTypeSegment.Identifier)))
{
// In case we have expanded a derived type's navigation property
// and we are in a cyclic loop where the expanded navigation property
// has a derived type that has already been added to the path.
continue;
}

var castPath = currentPath.Clone();
castPath.Push(targetTypeSegment);
AppendPath(castPath);
if(targetsMany)
if (targetsMany)
{
CreateCountPath(castPath, convertSettings);
}
else
{
if (convertSettings.ExpandDerivedTypesNavigationProperties)
{
if (annotable is IEdmNavigationProperty navigationProperty && !navigationProperty.ContainsTarget)
{
continue;
}

foreach (var declaredNavigationProperty in targetType.DeclaredNavigationProperties())
{
RetrieveNavigationPropertyPaths(declaredNavigationProperty, null, castPath, convertSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.2.0-preview5</Version>
<Version>1.2.0-preview6</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
Expand All @@ -27,6 +27,7 @@
- Adds create and update operations to non-containment navigation properties when restrictions annotations are explicitly set to true #265
- Generate odata.nextLink and odata.deltaLink properties on delta functions response schemas #285
- Omits paths with PathItems without any operation #148
- Expands navigation properties of derived types only if declaring navigation property is a containment #269
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()
{
// Arrange
IEdmModel model = EdmModelHelper.GraphBetaModel;
var settings = new OpenApiConvertSettings()
{
ExpandDerivedTypesNavigationProperties = false
};
ODataPathProvider provider = new ODataPathProvider();
var settings = new OpenApiConvertSettings();

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

// Assert
Assert.NotNull(paths);
Assert.Equal(13836, paths.Count());
Assert.Equal(18316, paths.Count());
}

[Fact]
Expand All @@ -63,7 +60,6 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
var settings = new OpenApiConvertSettings
{
RequireDerivedTypesConstraintForBoundOperations = true,
ExpandDerivedTypesNavigationProperties = false,
AppendBoundOperationsOnDerivedTypeCastSegments = true
};

Expand All @@ -72,7 +68,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()

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

[Fact]
Expand Down
Loading