Repository navigation
Conversation
Schema pairs compared without a $ref on both sides skip the deferred cache guard in computeDeferredDiff. When resolveComposedSchema merges an allOf member into the wrapping schema, a cycle between composed schemas can lead back into the same pair with no reference left to check, and the descent recursed until the stack overflowed, looping through ComposedSchemaDiffResult.diff -> RealizedChanged.flatMap -> SchemaDiff.computeDeferredDiff as in the report. Track the identity of the schema pair being compared on the current path in RecursiveSchemaSet and stop when a pair is re-entered. The guard is path-scoped, so sibling occurrences of the same pair are still diffed and output for specs without such cycles is unchanged. Fixes OpenAPITools#788 Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Add a fixture pair with two sibling properties whose allOf branches revisit the same merged Entry/Child schema pair, and assert the change inside the pair is reported for both branches, so a globally retained pair cache would fail the suite. Signed-off-by: Vadim Lazuk <vadimlazuk5@gmail.com>
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.
Fixes #788
Diagnosis
A composed schema cycle that survives without a
$refoverflows the stack.SchemaDiff#resolveComposedSchemamerges anallOfmember's properties into the wrapping schema and then clears theallOf, so when the cycle is entered through an inline composed schema (for example a response schemaallOf: [$ref Entry], withEntryandChildreferencing each other throughallOf-wrapped properties), the recursion is followed with no reference left to check. The existing reference-based guards never fire on such a path:DeferredSchemaCache#getOrAddSchemais only consulted when both sides carry a$ref, and nothing puts those refs intoRecursiveSchemaSet, so the visited refs thatresolveComposedSchemachecks stay empty.The descent then loops along exactly the cycle from the issue's stack trace:
I reproduced this end to end with two small specs: the CLI built from master throws
java.lang.StackOverflowErroron them, while the CLI built from this branch prints a change report and writes the HTML file.Fix
computeDeferredDiffnow guards the branch that falls through the cache on the identity of the(left, right)schema pair. The pair is recorded inRecursiveSchemaSet(the set that already carries the reference keys) beforecomputeDiffForRealand removed after it returns; when a pair is already being compared higher up the current path, the descent stops with an empty result. The guard is path-scoped, so occurrences of the same pair in sibling positions are still diffed and the output for specs without such cycles does not change.Tests
cyclic_composed_1.yaml/cyclic_composed_2.yaml: anEntry<->Childcycle reached through an inlineallOfresponse schema. Comparing the spec against itself reports no changes, and a property type change inside the cycle (child.name, string -> integer) is still reported as backward incompatible. Both comparisons threwStackOverflowErrorbefore the change.cyclic_composed_deep_1.yaml/cyclic_composed_deep_2.yaml: an eight-level acyclicallOfchain, proving deep paths are still followed end to end and a change at the bottom is still detected../mvnw testpasses for all modules (core 274 tests, 0 failures).Related: #928 proposes a similar identity-based guard for cycles that carry no
$ref.Signed-off-by: Inf1mum vadimlazuk5@gmail.com
Summary by cubic
Fixes
StackOverflowErroron composed schema cycles that don't carry a$ref, resolving #788. WhenresolveComposedSchemamerges anallOfmember into the wrapping schema, a cycle is descended with no reference left to check, so the reference-based recursion guards never fire.computeDeferredDiffnow stops when the same(left, right)schema pair is re-entered on the current path, tracked by identity inRecursiveSchemaSet. The guard is path-scoped, so sibling occurrences of the same pair are still diffed and output for specs without such cycles is unchanged.Tests
Entry/Childpair reached through an inlineallOfresponse schema, an eight-level acyclicallOfchain, and a fixture whose two sibling properties revisit the same merged cyclic pair to confirm changes are still reported in both branches.Written for commit 1ff8ed3. Summary will update on new commits.