GeezerVison is showing github.com — fix: skip resolveSubtypes for sealed classes with @Schema(oneOf) by vpelikh · Pull Request #5322 · swagger-api/swagger-core
Conversation
vpelikh
commented
Sep 18, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Why this PR
A Java sealed class 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 intended oneOf and a redundant/wrong allOf, producing schemas that fail validation and confuse consumers.
Problem
- Jackson 3 auto-detects subtypes of Java
sealed classes (the compiler records PermittedSubclasses).
- When a sealed class also declared
@Schema(oneOf = ...), resolveSubtypes() added unwanted allOf references on top of the explicit oneOf.
- The result was an invalid schema (composition keywords misused) and spurious references.
Change
In ModelResolver.resolve(), skip resolveSubtypes() 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 extra allOf is redundant and removed.
Result: sealed classes with @Schema(oneOf) now generate clean polymorphic schemas without duplicate allOf references.
Related: #4991
Type of Change
- 🐛 Bug fix
- ✨ New feature
- ♻️ Refactor (non-breaking change)
- 🧪 Tests
- 📝 Documentation
- 🧹 Chore (build or tooling)
Checklist
- I have added/updated tests as needed
- I have added/updated documentation where applicable
- The PR title is descriptive
- The code builds and passes tests locally
- I have linked related issues (if any)
Screenshots / Additional Context
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
vpelikh
changed the title
Skip resolveSubtypes for sealed classes with @Schema(oneOf)
fix: skip resolveSubtypes for sealed classes with @Schema(oneOf)
Sep 24, 2026
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.