Skip to content

fix(schema-model): improve logic for resolving circular refs and use when removing readonly fields#810

Draft
vaibhavrajsingh2001 wants to merge 6 commits into
mainfrom
fix/circular-refs-in-remove-readonly-fields
Draft

fix(schema-model): improve logic for resolving circular refs and use when removing readonly fields#810
vaibhavrajsingh2001 wants to merge 6 commits into
mainfrom
fix/circular-refs-in-remove-readonly-fields

Conversation

@vaibhavrajsingh2001
Copy link
Copy Markdown
Contributor

@vaibhavrajsingh2001 vaibhavrajsingh2001 commented Mar 6, 2026

Summary

Some specs with circular refs in Schema Objects were failing parsing.
Reason: removeFieldsFromSchemaObject previously relied on JSON.parse(JSON.stringify) cloning, which fails for circular refs.

Changes:

  • if stringify fails in removeFieldsFromSchemaObject then resolve circular refs
  • implement a DFS stack based approach to resolve circular refs, as the old Set+JSON replacer approach only avoids revisiting repeated refs but still depends on recursive serialization and was causing max call-stack reached errors
    • iteratively traverses the object graph using an explicit DFS stack,
    • tracks seen objects with WeakMap,
    • drops repeated/circular references to produce a safe tree-shaped clone.
  • add tests for circular refs in removeFieldsFromSchemaObject

Portal verification PR: https://github.com/kong-konnect/portal/pull/2097

@vaibhavrajsingh2001 vaibhavrajsingh2001 self-assigned this Mar 6, 2026
@vaibhavrajsingh2001 vaibhavrajsingh2001 requested a review from a team as a code owner March 6, 2026 10:45
@vaibhavrajsingh2001
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Member

@adamdehaven adamdehaven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find what's actually throwing the error and properly catch it. It looks like there are still 500 errors during SSR in the portal

@vaibhavrajsingh2001 vaibhavrajsingh2001 marked this pull request as draft March 6, 2026 17:05
@kongponents-bot
Copy link
Copy Markdown
Collaborator

Install the preview package from this PR

@kong/spec-renderer@pr-810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants