Skip to content

fix: removes loop methods from parsing context as its available in loop detector instead #2432

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

Merged
merged 1 commit into from
Jul 10, 2025
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
48 changes: 0 additions & 48 deletions src/Microsoft.OpenApi/Reader/ParsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ParsingContext
private readonly Stack<string> _currentLocation = new();
private readonly Dictionary<string, object> _tempStorage = new();
private readonly Dictionary<object, Dictionary<string, object>> _scopedTempStorage = new();
private readonly Dictionary<string, Stack<string>> _loopStacks = new();

/// <summary>
/// Extension parsers
Expand Down Expand Up @@ -219,53 +218,6 @@ public void StartObject(string objectName)
{
_currentLocation.Push(objectName);
}

/// <summary>
/// Maintain history of traversals to avoid stack overflows from cycles
/// </summary>
/// <param name="loopId">Any unique identifier for a stack.</param>
/// <param name="key">Identifier used for current context.</param>
/// <returns>If method returns false a loop was detected and the key is not added.</returns>
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
}
}

/// <summary>
/// Reset loop tracking stack
/// </summary>
/// <param name="loopid">Identifier of loop to clear</param>
internal void ClearLoop(string loopid)
{
_loopStacks[loopid].Clear();
}

/// <summary>
/// Exit from the context in cycle detection
/// </summary>
/// <param name="loopid">Identifier of loop</param>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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) { }
}
Expand Down
Loading