Skip to content

Commit

Permalink
Retrieve type cast segments if it appears before any navigation property
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinesunday committed Nov 3, 2023
1 parent dc5017f commit b99f3d7
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +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(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)
{
// If there exists an OData type cast segment present in the path,
// this segement identifier needs to be added to the operation id
ODataTypeCastSegment typeCastSegment = path.Segments.OfType<ODataTypeCastSegment>().LastOrDefault();
if (typeCastSegment != null && path.Kind == ODataPathKind.NavigationProperty)
{
IEdmSchemaElement schemaElement = typeCastSegment.StructuredType as IEdmSchemaElement;
items.Add("As" + Utils.UpperFirstChar(schemaElement.Name));
}

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);
IEdmSchemaElement schemaElement = typeCastSegment.StructuredType as IEdmSchemaElement;
previousTypeCastSegmentId = "As" + Utils.UpperFirstChar(schemaElement.Name);
items.Add(previousTypeCastSegmentId);
}
}

Expand Down

0 comments on commit b99f3d7

Please sign in to comment.