fix(model-resolver): retain identical recursive properties#5232
Open
bender316 wants to merge 1 commit into
Open
fix(model-resolver): retain identical recursive properties#5232bender316 wants to merge 1 commit into
bender316 wants to merge 1 commit into
Conversation
Swagger's ModelConverterContextImpl uses AnnotatedType to track types currently being processed to prevent infinite loops. However, AnnotatedType equality previously ignored the parent schema. This caused properties with identical signatures (same type, name, annotations) but belonging to different parent classes to be incorrectly treated as a recursion cycle, returning a null schema and dropping the property entirely. This commit updates AnnotatedType's equals() and hashCode() to include the parent schema's name when checking equality for schema properties. This guarantees identical properties in different classes are tracked independently, while still properly catching true self-referential cycles.
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.
Pull Request
Description
This PR fixes a bug where recursive properties are silently dropped from the generated OpenAPI schema if they happen to share the exact same name and annotations as a property in their wrapper class.
Root cause:
The cycle detection cache (
processedTypes) inModelConverterContextImplusesAnnotatedTypeto prevent infinite recursion. Previously,AnnotatedType.equals()did not check theparentclass for schema properties. As a result, when it encountered a child property with the exact same signature as a previously processed wrapper property, it mistakenly treated it as a self-referential cycle and dropped it.Fix:
Updated
AnnotatedType.equals()andhashCode()to conditionally include theparentclass name whenschemaProperty == true. This correctly differentiates identically-annotated properties across different classes while preserving the cycle guard for truly self-referential loops.Fixes: #5231
Fixes: #5226
Type of Change
Checklist
Screenshots / Additional Context
RecursivePropertyMissingTest.javato prevent future regressions.ArrayOfSubclassTest_expected30.json) that was previously masking this bug by falsely asserting that the property should be omitted.