Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds config setting for composable functions generation #552

Merged
merged 5 commits into from
Jul 24, 2024
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
33 changes: 30 additions & 3 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,32 @@ private void RetrieveBoundOperationPaths(OpenApiConvertSettings convertSettings)
continue;
}

ODataSegment secondLastSeg = functionPath.ElementAt(functionPath.Count - 2);
if (convertSettings.ComposableFunctionsExpansionDepth < 2 &&
functionPath.LastSegment is ODataOperationSegment &&
secondLastSeg is ODataOperationSegment)
{
// Only one level of composable functions expansion allowed
continue;
}

foreach (var navProperty in returnBindingEntityType.NavigationProperties())
{
ODataPath newNavigationPath = functionPath.Clone();
newNavigationPath.Push(new ODataNavigationPropertySegment(navProperty));
AppendPath(newNavigationPath);
/* Get number of segments already appended after the first composable function segment
*/
int composableFuncSegIndex = functionPath.Segments.IndexOf(
functionPath.Segments.FirstOrDefault(
x => x is ODataOperationSegment operationSegment &&
operationSegment.Operation is IEdmFunction edmFunction &&
edmFunction.IsComposable));
int currentDepth = functionPath.Count - composableFuncSegIndex - 1;

if (currentDepth < convertSettings.ComposableFunctionsExpansionDepth)
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
{
ODataPath newNavigationPath = functionPath.Clone();
newNavigationPath.Push(new ODataNavigationPropertySegment(navProperty));
AppendPath(newNavigationPath);
}
}
}
}
Expand Down Expand Up @@ -1171,6 +1192,12 @@ private void AppendBoundOperationOnOperationPath(IEdmOperation edmOperation, boo
continue;
}

var segName = path.LastSegment as ODataOperationSegment;
if (edmOperation.Name.Equals(segName?.Identifier))
{
continue;
}

ODataPath newOperationPath = path.Clone();
newOperationPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction, _model));
AppendPath(newOperationPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.6.7</Version>
<Version>1.6.8</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>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
<PackageReleaseNotes>
- Fixes empty response objects for OData type cast paths. #546
- Adds support for configuring composable functions generations #551
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
8 changes: 7 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ public bool ExpandDerivedTypesNavigationProperties
/// </summary>
public bool UseStringArrayForQueryOptionsSchema { get; set; } = true;

/// <summary>
/// Gets/Sets a value indicating the depth to expand composable functions.
/// </summary>
public int ComposableFunctionsExpansionDepth { get; set; } = 1;

internal OpenApiConvertSettings Clone()
{
var newSettings = new OpenApiConvertSettings
Expand Down Expand Up @@ -416,7 +421,8 @@ internal OpenApiConvertSettings Clone()
EnableAliasForTypeCastSegments = this.EnableAliasForTypeCastSegments,
SemVerVersion = this.SemVerVersion,
EnableAliasForOperationSegments = this.EnableAliasForOperationSegments,
UseStringArrayForQueryOptionsSchema = this.UseStringArrayForQueryOptionsSchema
UseStringArrayForQueryOptionsSchema = this.UseStringArrayForQueryOptionsSchema,
ComposableFunctionsExpansionDepth = this.ComposableFunctionsExpansionDepth
};

return newSettings;
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.AddEnumFlagsExtension.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.AddEnumFlagsExtension.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.ComposableFunctionsExpansionDepth.get -> int
Microsoft.OpenApi.OData.OpenApiConvertSettings.ComposableFunctionsExpansionDepth.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.get -> System.Collections.Generic.Dictionary<Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey, string>
Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableAliasForOperationSegments.get -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void GetPathsForGraphBetaModelReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(16980, paths.Count());
Assert.Equal(15210, paths.Count());
AssertGraphBetaModelPaths(paths);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(17631, paths.Count());
Assert.Equal(15861, paths.Count());
}

[Theory]
Expand Down Expand Up @@ -208,9 +208,9 @@ public void GetPathsForComposableFunctionsReturnsAllPaths()

// Assert
Assert.NotNull(paths);
Assert.Equal(38, paths.Count());
Assert.Equal(20, paths.Where(p => p.LastSegment is ODataOperationSegment).Count());
Assert.Equal(12, paths.Where(p => p.Segments.Count > 1 && p.LastSegment is ODataNavigationPropertySegment && p.Segments[p.Segments.Count - 2] is ODataOperationSegment).Count());
Assert.Equal(26, paths.Count());
Assert.Equal(17, paths.Where(p => p.LastSegment is ODataOperationSegment).Count());
Assert.Equal(3, paths.Where(p => p.Segments.Count > 1 && p.LastSegment is ODataNavigationPropertySegment && p.Segments[p.Segments.Count - 2] is ODataOperationSegment).Count());
}

[Fact]
Expand Down
Loading