Skip to content

Commit

Permalink
Fixes operation id`s of paths with type cast segments (#493)
Browse files Browse the repository at this point in the history
* Fix operation id of paths with type cast segments

* Update integration tests

* Update conditional and add comment

* Update release notes
  • Loading branch information
irvinesunday authored Feb 13, 2024
1 parent e4e8cee commit 39214d4
Show file tree
Hide file tree
Showing 6 changed files with 714 additions and 704 deletions.
39 changes: 24 additions & 15 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ s is ODataOperationSegment ||
{
items.Add(navPropSegment.NavigationProperty.Name);
}
else if (segment is ODataTypeCastSegment typeCastSegment && path.Kind == ODataPathKind.NavigationProperty)
else if (segment is ODataTypeCastSegment typeCastSegment
&& path.Kind != ODataPathKind.TypeCast // ex: ~/NavSource/NavProp/TypeCast
&& !(path.Kind == ODataPathKind.DollarCount && path.Segments.ElementAt(path.Segments.Count - 2)?.Kind == ODataSegmentKind.TypeCast)) // ex: ~/NavSource/NavProp/TypeCast/$count
{
// Only the last OData type cast segment identifier is added to the operation id
items.Remove(previousTypeCastSegmentId);
Expand Down Expand Up @@ -352,28 +354,35 @@ internal static string GenerateODataTypeCastPathOperationIdPrefix(ODataPath path
string listOrGet = includeListOrGetPrefix ? (complexSegment.Property.Type.IsCollection() ? "List" : "Get") : null;
operationId = GenerateComplexPropertyPathOperationId(path, listOrGet);
}
else if (secondLastSegment as ODataNavigationPropertySegment is not null || isIndexedCollValuedNavProp)
else if (secondLastSegment is ODataNavigationPropertySegment navPropSegment)
{
string listOrGet = null;
string prefix = null;
if (includeListOrGetPrefix)
{
listOrGet = !isIndexedCollValuedNavProp && (secondLastSegment as ODataNavigationPropertySegment)?.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many ? "List" : "Get";
prefix = navPropSegment?.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many ? "List" : "Get";
}

operationId = GenerateNavigationPropertyPathOperationId(path, listOrGet);
operationId = GenerateNavigationPropertyPathOperationId(path, prefix);
}
else if (secondLastSegment is ODataKeySegment keySegment && !isIndexedCollValuedNavProp)
else if (secondLastSegment is ODataKeySegment keySegment)
{
string entityTypeName = keySegment.EntityType.Name;
string getPrefix = includeListOrGetPrefix ? "Get" : null;
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
if (keySegment.IsAlternateKey)
{
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
operationName = $"{operationName}By{alternateKeyName}";
if (isIndexedCollValuedNavProp)
{
operationId = GenerateNavigationPropertyPathOperationId(path, "Get");
}
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
operationId += $".{entityTypeName}.{operationName}";
else
{
string entityTypeName = keySegment.EntityType.Name;
string getPrefix = includeListOrGetPrefix ? "Get" : null;
string operationName = $"{getPrefix}{Utils.UpperFirstChar(entityTypeName)}";
if (keySegment.IsAlternateKey)
{
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
operationName = $"{operationName}By{alternateKeyName}";
}
operationId = (entitySet != null) ? entitySet.Name : singleton.Name;
operationId += $".{entityTypeName}.{operationName}";
}
}
else if (secondLastSegment is ODataNavigationSourceSegment)
{
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.6.0-preview.7</Version>
<Version>1.6.0-preview.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>
Expand All @@ -29,6 +29,7 @@
- Adds delete operation for non-contained navigation properties only if explicitly allowed via annotation #483
- Appends parameters and fixes operation ids of navigation property paths generated via composable functions #486
- Use alternate keys in the generation of operation ids of operations and navigation property alternate paths #488
- Fixes operation ids of paths with type cast segments #492
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Loading

0 comments on commit 39214d4

Please sign in to comment.