Repository navigation
fix: skip resolveSubtypes for sealed classes with @Schema(oneOf) - #5322
Merged
daniel-kmiecik merged 4 commits intoSep 24, 2026
Merged
daniel-kmiecik merged 4 commits into
daniel-kmiecik merged 4 commits into
Conversation
Jackson 3 auto-detects subtypes of Java sealed classes. When a sealed class also declared @Schema(oneOf = ...), resolveSubtypes() added unwanted allOf references to the subtypes on top of the explicit oneOf. Skip resolveSubtypes() for sealed classes that declare @Schema(oneOf); the oneOf handling already builds the correct polymorphic schema with a discriminator. Adds SealedClassOneOfTest which fails without the fix (unwanted allOf on subtypes) and passes with it.
daniel-kmiecik
approved these changes
Sep 24, 2026
2 tasks done
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.
Why this PR
A Java
sealedclass is polymorphic by the language: with@Schema(oneOf = ...)the user already declares the target subtypes explicitly. On Jackson 3, sealed classes also get their subtypes auto-detected, so swagger-core ended up generating both the user's intendedoneOfand a redundant/wrongallOf, producing schemas that fail validation and confuse consumers.Problem
sealedclasses (the compiler recordsPermittedSubclasses).@Schema(oneOf = ...),resolveSubtypes()added unwantedallOfreferences on top of the explicitoneOf.Change
In
ModelResolver.resolve(), skipresolveSubtypes()when the resolved type is a sealed class that declares@Schema(oneOf = ...). The@Schema(oneOf)handling already builds the correct polymorphic schema with a discriminator, so the extraallOfis redundant and removed.Result: sealed classes with
@Schema(oneOf)now generate clean polymorphic schemas without duplicateallOfreferences.Related: #4991
Type of Change
Checklist
Screenshots / Additional Context