-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix/annotated type caching 5003 #5005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/annotated type caching 5003 #5005
Conversation
…e equality Signed-off-by: potato <[email protected]>
|
Hi @juntae6942, Thank you for your quick response to this issue :) we do appreciate it a lot. This should fix the problem of polymorphic schemas caching. There are few approaches that could be taken here, but I need decision from the team. Please hold on for now with the topic. I will inform you whenever there's any decision. Thanks again for your contribution! |
d8efab6 to
3f6791c
Compare
…isSubtype property in AnnotatedType and add tests
3f6791c to
51cb682
Compare
|
@juntae6942, |
|
Hi ewaostrowska, Ah, I see you've already pushed a commit using the isSubtype flag. That makes perfect sense, and the approach looks good! 👍 Thanks for taking care of the fix! Is there anything else needed from my end for this? |
|
@juntae6942 no, I don't think anything anything more from your side is needed :) thanks for contributing! |
|
ewaostrowska, Thanks for the quick feedback! I really appreciate it. |
Closes: #5003
Description
This PR fixes a regression bug that causes an AnnotatedType cache collision when a polymorphic type is resolved in two different contexts: once as a 'property' (e.g., direct return type) and once as a 'subtype' (e.g., from @JsonSubTypes).
The regression was introduced when equals()/hashCode() began normalizing context annotations but did not properly account for flags like schemaProperty or propertyName. This caused both 'property' and 'subtype' resolutions to merge into the same cache entry, leading to an incomplete schema (the subtype-specific fragment was skipped).
This fix addresses the issue in two parts:
AnnotatedType.java: equals() and hashCode() are updated to correctly compare the schemaProperty flag. The propertyName is now also conditionally compared only when schemaProperty is true, aligning equals and hashCode logic.
ModelResolver.java: resolveSubtypes() is updated to explicitly set schemaProperty(true) when creating an AnnotatedType for a class discovered via @JsonSubTypes.
This combination ensures that the 'property' context (schemaProperty=false) and 'subtype' context (schemaProperty=true) generate distinct cache keys, resolving the collision.
Fixes: ## Type of Change
Checklist
Screenshots / Additional Context
This fix can be verified using the reproduction project provided in the bug report: https://github.com/benjaminknauer/swagger-2-2-39-polymorphism-bug-example
With this patch applied, the BuggySchemaIntegrationTest in that project passes successfully.
The new unit tests added to AnnotatedTypeTest.java specifically validate the new equals/hashCode logic for all schemaProperty and propertyName scenarios to prevent future regressions.