From 75d4075b60734677acc246949785ef271461e44f Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Tue, 1 Oct 2024 22:40:55 +0300 Subject: [PATCH] Account for overloaded functions in any segment --- .../Operation/EdmOperationOperationHandler.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs index 55ad88b2..ad6217e9 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs @@ -81,6 +81,7 @@ protected override void SetBasicInfo(OpenApiOperation operation) // duplicates in entity vs entityset functions/actions List identifiers = new(); + string pathHash = string.Empty; foreach (ODataSegment segment in Path.Segments) { if (segment is ODataKeySegment keySegment) @@ -101,6 +102,16 @@ protected override void SetBasicInfo(OpenApiOperation operation) identifiers.Add(keySegment.Identifier); } } + else if (segment is ODataOperationSegment opSegment) + { + if (opSegment.Operation is IEdmFunction function && Context.Model.IsOperationOverload(function)) + { + // Hash the segment to avoid duplicate operationIds + pathHash = segment.GetPathHash(Context.Settings); + } + + identifiers.Add(segment.Identifier); + } else { identifiers.Add(segment.Identifier); @@ -109,21 +120,13 @@ protected override void SetBasicInfo(OpenApiOperation operation) string operationId = string.Join(".", identifiers); - if (EdmOperation.IsAction()) + if (!string.IsNullOrEmpty(pathHash)) { - operation.OperationId = operationId; + operation.OperationId = operationId + "-" + pathHash; } else { - if (Path.LastSegment is ODataOperationSegment operationSegment && - Context.Model.IsOperationOverload(operationSegment.Operation)) - { - operation.OperationId = operationId + "-" + Path.LastSegment.GetPathHash(Context.Settings); - } - else - { - operation.OperationId = operationId; - } + operation.OperationId = operationId; } }