Repository navigation
fix: avoid stack overflow for multiple anyOf root refs - #911
Merged
Tony133 merged 2 commits intoNov 8, 2026
Merged
Conversation
…words The fast path added for fastify#724 only applies when the anyOf/oneOf has no sibling keywords and the option is exactly `{ $ref }`. Any sibling keyword next to the anyOf (a `description`, `nullable`, `properties`...) or on the option itself still merged the $ref target, which clones it and re-enters buildOneOf with new option objects that the identity-keyed cache never recognizes, overflowing the stack again. Mirror what resolveRef already does: key the merge by content (resolved $ref + the sibling keywords cloned with absolute $refs) so every clone of a recursive target reuses the same merged schema. Any option with a $ref takes this path, since resolveRef handles the option's own siblings. Regression tests: root refs with sibling keywords, refs to a non-root definition, sibling keywords on the option, and the same sibling text in two external schemas (which must not share a merge).
Tony133
force-pushed
the
fix/anyof-root-ref-stack-overflow
branch
from
November 7, 2026 17:40
107bbd3 to
b0c5ba4
Compare
Member
|
Thanks for the fix! I rebased the branch on The fast path only kicked in when the |
Tony133
approved these changes
Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a stack overflow when a schema has two or more
anyOf/oneOffields that each include{ $ref: '#' }(self-ref to the root). Merging each pure$refwith an empty sibling schema cloned the root and re-enteredbuildOneOfforever.Linked issue
Closes #724
Changes
anyOf/oneOfhas no sibling keywords and an option is a pure$ref, build the resolved target schema directly instead of merginganyOfandoneOfroot refsValidation
npm run test:unit— 663 passed, 100% coverage