Skip to content

Commit 39214d4

Browse files
authored
Fixes operation id`s of paths with type cast segments (#493)
* Fix operation id of paths with type cast segments * Update integration tests * Update conditional and add comment * Update release notes
1 parent e4e8cee commit 39214d4

File tree

6 files changed

+714
-704
lines changed

6 files changed

+714
-704
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ s is ODataOperationSegment ||
179179
{
180180
items.Add(navPropSegment.NavigationProperty.Name);
181181
}
182-
else if (segment is ODataTypeCastSegment typeCastSegment && path.Kind == ODataPathKind.NavigationProperty)
182+
else if (segment is ODataTypeCastSegment typeCastSegment
183+
&& path.Kind != ODataPathKind.TypeCast // ex: ~/NavSource/NavProp/TypeCast
184+
&& !(path.Kind == ODataPathKind.DollarCount && path.Segments.ElementAt(path.Segments.Count - 2)?.Kind == ODataSegmentKind.TypeCast)) // ex: ~/NavSource/NavProp/TypeCast/$count
183185
{
184186
// Only the last OData type cast segment identifier is added to the operation id
185187
items.Remove(previousTypeCastSegmentId);
@@ -352,28 +354,35 @@ internal static string GenerateODataTypeCastPathOperationIdPrefix(ODataPath path
352354
string listOrGet = includeListOrGetPrefix ? (complexSegment.Property.Type.IsCollection() ? "List" : "Get") : null;
353355
operationId = GenerateComplexPropertyPathOperationId(path, listOrGet);
354356
}
355-
else if (secondLastSegment as ODataNavigationPropertySegment is not null || isIndexedCollValuedNavProp)
357+
else if (secondLastSegment is ODataNavigationPropertySegment navPropSegment)
356358
{
357-
string listOrGet = null;
359+
string prefix = null;
358360
if (includeListOrGetPrefix)
359361
{
360-
listOrGet = !isIndexedCollValuedNavProp && (secondLastSegment as ODataNavigationPropertySegment)?.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many ? "List" : "Get";
362+
prefix = navPropSegment?.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many ? "List" : "Get";
361363
}
362364

363-
operationId = GenerateNavigationPropertyPathOperationId(path, listOrGet);
365+
operationId = GenerateNavigationPropertyPathOperationId(path, prefix);
364366
}
365-
else if (secondLastSegment is ODataKeySegment keySegment && !isIndexedCollValuedNavProp)
367+
else if (secondLastSegment is ODataKeySegment keySegment)
366368
{
367-
string entityTypeName = keySegment.EntityType.Name;
368-
string getPrefix = includeListOrGetPrefix ? "Get" : null;
369-
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
370-
if (keySegment.IsAlternateKey)
371-
{
372-
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
373-
operationName = $"{operationName}By{alternateKeyName}";
369+
if (isIndexedCollValuedNavProp)
370+
{
371+
operationId = GenerateNavigationPropertyPathOperationId(path, "Get");
374372
}
375-
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
376-
operationId += $".{entityTypeName}.{operationName}";
373+
else
374+
{
375+
string entityTypeName = keySegment.EntityType.Name;
376+
string getPrefix = includeListOrGetPrefix ? "Get" : null;
377+
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
378+
if (keySegment.IsAlternateKey)
379+
{
380+
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
381+
operationName = $"{operationName}By{alternateKeyName}";
382+
}
383+
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
384+
operationId += $".{entityTypeName}.{operationName}";
385+
}
377386
}
378387
else if (secondLastSegment is ODataNavigationSourceSegment)
379388
{

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.6.0-preview.7</Version>
18+
<Version>1.6.0-preview.8</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>
@@ -29,6 +29,7 @@
2929
- Adds delete operation for non-contained navigation properties only if explicitly allowed via annotation #483
3030
- Appends parameters and fixes operation ids of navigation property paths generated via composable functions #486
3131
- Use alternate keys in the generation of operation ids of operations and navigation property alternate paths #488
32+
- Fixes operation ids of paths with type cast segments #492
3233
</PackageReleaseNotes>
3334
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3435
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

0 commit comments

Comments
 (0)