Skip to content

Commit 72e0a33

Browse files
author
Andrew Omondi
committed
Fix regression in unique openId generation.
1 parent b6c9e17 commit 72e0a33

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.7.2</Version>
18+
<Version>1.7.3</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>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
2323
<PackageReleaseNotes>
24-
- Adds action/function suffix to tag names for actions/functions operations in #642
24+
- Fix regression in unique operation id generation at #462.
2525
</PackageReleaseNotes>
2626
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
2727
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ protected override void SetBasicInfo(OpenApiOperation operation)
8181
// duplicates in entity vs entityset functions/actions
8282

8383
List<string> identifiers = new();
84+
string pathHash = string.Empty;
8485
foreach (ODataSegment segment in Path.Segments)
8586
{
8687
if (segment is ODataKeySegment keySegment)
@@ -101,6 +102,18 @@ protected override void SetBasicInfo(OpenApiOperation operation)
101102
identifiers.Add(keySegment.Identifier);
102103
}
103104
}
105+
else if (segment is ODataOperationSegment opSegment)
106+
{
107+
if (opSegment.Operation is IEdmFunction function && Context.Model.IsOperationOverload(function))
108+
{
109+
// Hash the segment to avoid duplicate operationIds
110+
pathHash = string.IsNullOrEmpty(pathHash)
111+
? opSegment.GetPathHash(Context.Settings)
112+
: (pathHash + opSegment.GetPathHash(Context.Settings)).GetHashSHA256().Substring(0, 4);
113+
}
114+
115+
identifiers.Add(segment.Identifier);
116+
}
104117
else
105118
{
106119
identifiers.Add(segment.Identifier);
@@ -109,21 +122,13 @@ protected override void SetBasicInfo(OpenApiOperation operation)
109122

110123
string operationId = string.Join(".", identifiers);
111124

112-
if (EdmOperation.IsAction())
113-
{
114-
operation.OperationId = operationId;
115-
}
116-
else
117-
{
118-
if (Path.LastSegment is ODataOperationSegment operationSegment &&
119-
Context.Model.IsOperationOverload(operationSegment.Operation))
120-
{
121-
operation.OperationId = operationId + "-" + Path.LastSegment.GetPathHash(Context.Settings);
122-
}
123-
else
124-
{
125-
operation.OperationId = operationId;
126-
}
125+
if (!string.IsNullOrEmpty(pathHash))
126+
{
127+
operation.OperationId = operationId + "-" + pathHash;
128+
}
129+
else
130+
{
131+
operation.OperationId = operationId;
127132
}
128133
}
129134

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ public void CreateOperationForComposableOverloadEdmFunctionReturnsCorrectOperati
378378

379379
if (enableOperationId)
380380
{
381-
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-6b6d", operation1.OperationId);
382-
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-2636", operation2.OperationId);
383-
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-6b6d", operation3.OperationId);
384-
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-2636", operation4.OperationId);
381+
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-c53d", operation1.OperationId);
382+
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-4d93", operation2.OperationId);
383+
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-a2b2", operation3.OperationId);
384+
Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-7bea", operation4.OperationId);
385385
}
386386
else
387387
{

0 commit comments

Comments
 (0)