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

[Fix] Updates operationIds of navigation property paths with OData type cast segments #443

Merged
merged 5 commits into from
Nov 6, 2023
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
22 changes: 14 additions & 8 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,25 @@ internal static IList<string> RetrieveNavigationPropertyPathsOperationIdSegments
navigationSource.Name
};

IEnumerable<ODataNavigationPropertySegment> navPropSegments = path.Segments.Skip(1).OfType<ODataNavigationPropertySegment>();
Utils.CheckArgumentNull(navPropSegments, nameof(navPropSegments));
// For navigation property paths with odata type cast segments
// the OData type cast segments identifiers will be used in the operation id
IEnumerable<ODataSegment> segments = path.Segments.Skip(1).Where(static s => s is ODataNavigationPropertySegment || s is ODataTypeCastSegment);
Utils.CheckArgumentNull(segments, nameof(segments));

foreach (var segment in navPropSegments)
string previousTypeCastSegmentId = null;
foreach (var segment in segments)
{
if (segment == navPropSegments.Last())
if (segment is ODataNavigationPropertySegment navPropSegment)
{
items.Add(segment.NavigationProperty.Name);
break;
items.Add(navPropSegment.NavigationProperty.Name);
}
else
else if (segment is ODataTypeCastSegment typeCastSegment && path.Kind == ODataPathKind.NavigationProperty)
{
items.Add(segment.NavigationProperty.Name);
// Only the last OData type cast segment identifier is added to the operation id
items.Remove(previousTypeCastSegmentId);
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
IEdmSchemaElement schemaElement = typeCastSegment.StructuredType as IEdmSchemaElement;
previousTypeCastSegmentId = "As" + Utils.UpperFirstChar(schemaElement.Name);
items.Add(previousTypeCastSegmentId);
}
}

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.5.0-preview7</Version>
<Version>1.5.0-preview8</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 @@ -28,6 +28,7 @@
- Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties #430
- Adds schema to content types of stream properties that have a collection of acceptable media types #435
- Retrieves complex properties of derived types #437
- Updates operationIds of navigation property paths with OData type cast segments #442
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Loading
Loading