Skip to content

Commit 8445ddc

Browse files
irvinesundaybaywet
andauthored
[Fix] Updates operationIds of navigation property paths with OData type cast segments (#443)
* Account for OData type cast segments present in NavigationProperty path kind * Update integration tests * Retrieve type cast segments if it appears before any navigation property * Update release notes * Update src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs --------- Co-authored-by: Vincent Biret <[email protected]>
1 parent dbce910 commit 8445ddc

File tree

6 files changed

+176
-169
lines changed

6 files changed

+176
-169
lines changed

src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,25 @@ internal static IList<string> RetrieveNavigationPropertyPathsOperationIdSegments
161161
navigationSource.Name
162162
};
163163

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

167-
foreach (var segment in navPropSegments)
169+
string previousTypeCastSegmentId = null;
170+
foreach (var segment in segments)
168171
{
169-
if (segment == navPropSegments.Last())
172+
if (segment is ODataNavigationPropertySegment navPropSegment)
170173
{
171-
items.Add(segment.NavigationProperty.Name);
172-
break;
174+
items.Add(navPropSegment.NavigationProperty.Name);
173175
}
174-
else
176+
else if (segment is ODataTypeCastSegment typeCastSegment && path.Kind == ODataPathKind.NavigationProperty)
175177
{
176-
items.Add(segment.NavigationProperty.Name);
178+
// Only the last OData type cast segment identifier is added to the operation id
179+
items.Remove(previousTypeCastSegmentId);
180+
IEdmSchemaElement schemaElement = typeCastSegment.StructuredType as IEdmSchemaElement;
181+
previousTypeCastSegmentId = "As" + Utils.UpperFirstChar(schemaElement.Name);
182+
items.Add(previousTypeCastSegmentId);
177183
}
178184
}
179185

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.5.0-preview7</Version>
18+
<Version>1.5.0-preview8</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
@@ -28,6 +28,7 @@
2828
- Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties #430
2929
- Adds schema to content types of stream properties that have a collection of acceptable media types #435
3030
- Retrieves complex properties of derived types #437
31+
- Updates operationIds of navigation property paths with OData type cast segments #442
3132
</PackageReleaseNotes>
3233
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3334
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

0 commit comments

Comments
 (0)