From 18a8cbeeb00ee39e5bbdaabdde097ee9f8a75668 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 10 Jul 2025 09:03:47 -0400 Subject: [PATCH] fix: removes loop methods from parsing context as its available in loop detector instead --- .../Reader/ParsingContext.cs | 48 ------------------- .../PublicApi/PublicApi.approved.txt | 2 - 2 files changed, 50 deletions(-) diff --git a/src/Microsoft.OpenApi/Reader/ParsingContext.cs b/src/Microsoft.OpenApi/Reader/ParsingContext.cs index d86829261..504014152 100644 --- a/src/Microsoft.OpenApi/Reader/ParsingContext.cs +++ b/src/Microsoft.OpenApi/Reader/ParsingContext.cs @@ -19,7 +19,6 @@ public class ParsingContext private readonly Stack _currentLocation = new(); private readonly Dictionary _tempStorage = new(); private readonly Dictionary> _scopedTempStorage = new(); - private readonly Dictionary> _loopStacks = new(); /// /// Extension parsers @@ -219,53 +218,6 @@ public void StartObject(string objectName) { _currentLocation.Push(objectName); } - - /// - /// Maintain history of traversals to avoid stack overflows from cycles - /// - /// Any unique identifier for a stack. - /// Identifier used for current context. - /// If method returns false a loop was detected and the key is not added. - public bool PushLoop(string loopId, string key) - { - if (!_loopStacks.TryGetValue(loopId, out var stack)) - { - stack = new(); - _loopStacks.Add(loopId, stack); - } - - if (!stack.Contains(key)) - { - stack.Push(key); - return true; - } - else - { - return false; // Loop detected - } - } - - /// - /// Reset loop tracking stack - /// - /// Identifier of loop to clear - internal void ClearLoop(string loopid) - { - _loopStacks[loopid].Clear(); - } - - /// - /// Exit from the context in cycle detection - /// - /// Identifier of loop - public void PopLoop(string loopid) - { - if (_loopStacks[loopid].Count > 0) - { - _loopStacks[loopid].Pop(); - } - } - private void ValidateRequiredFields(OpenApiDocument doc, string version) { if ((version.is2_0() || version.is3_0()) && (doc.Paths == null) && RootNode is not null) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index a12c2ee9d..e79b6754e 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -2012,8 +2012,6 @@ namespace Microsoft.OpenApi.Reader public Microsoft.OpenApi.OpenApiDocument Parse(System.Text.Json.Nodes.JsonNode jsonNode, System.Uri location) { } public T? ParseFragment(System.Text.Json.Nodes.JsonNode jsonNode, Microsoft.OpenApi.OpenApiSpecVersion version, Microsoft.OpenApi.OpenApiDocument openApiDocument) where T : Microsoft.OpenApi.IOpenApiElement { } - public void PopLoop(string loopid) { } - public bool PushLoop(string loopId, string key) { } public void SetTempStorage(string key, object? value, object? scope = null) { } public void StartObject(string objectName) { } }