Skip to content
Open
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
15 changes: 15 additions & 0 deletions json_schema_for_humans/schema/intermediate_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ def _resolve_ref(
found_reference = resolved_references[referenced_schema_path].get(anchor_part)
reference_users[referenced_schema_path][anchor_part].append(current_node)

# Check for circular reference by walking up the parent chain
# If we find the same reference path being built, we have a cycle
parent_node = current_node.parent
while parent_node:
if (parent_node.file == referenced_schema_path and
"/".join(parent_node.path_to_element) == anchor_part):
# Found circular reference - create a link instead of infinite recursion
current_node.is_displayed = False
if found_reference:
return found_reference, found_reference
else:
# Create a placeholder that indicates circular reference
return None, None
parent_node = parent_node.parent

if found_reference and found_reference != current_node:
if config.link_to_reused_ref:
return _find_ref(
Expand Down
Loading