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

Fixes operation id`s of paths with type cast segments #493

Merged
merged 4 commits into from
Feb 13, 2024
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
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
Loading