fix: allow allOf diamond under a discriminator parent
With legacyDiscriminatorBehavior=false (java, go, csharp...) spec from #13714 fails with Stack overflow hit when looking for Type, an infinite loop starting and ending at ResponseDetails was seen. UpdateDetails is allOf CreationDetails and ResponseDetails is allOf both, so getAllOfDescendants reaches ResponseDetails second time from UpdateDetails and throws, but its a diamond, not a loop. #17905 is same shape
Now repeat throws only when child is current schema or one of its allOf ancestors (real cycle), other repeats are skipped. Real cycle (A allOf [Type, B], B allOf [A]) still throws, also when its schemas are first reached thru diferent parents. Repeat check also compares schema name now, mapping name differs from it with x-discriminator-value. Added test in DefaultCodegenTest, regenerated all samples: no changes
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
Commit all changed files../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Summary by cubic
Fixes stack overflow when allOf schemas form a diamond under a discriminator parent. With legacyDiscriminatorBehavior=false, schemas like UpdateDetails (allOf CreationDetails) and ResponseDetails (allOf both) previously triggered the infinite-loop check even though the relationship is a diamond, not a cycle.
The traversal now remembers which schema each descendant was first reached from and skips repeats reached through other parents (diamonds). It only raises the infinite-loop error when the descendant is the current schema or one of its ancestors, and isAllOfAncestorOrSelf walks every allOf ancestor path so real cycles (e.g., CycleA allOf CycleB, CycleB allOf CycleA) still throw even when a schema is first reached through a different parent. The repeat check now compares schema names instead of mapping names, since x-discriminator-value can differ.