GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@vpelikh vpelikh commented Sep 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
vpelikh and others added 2 commits September 18, 2026 23:21
@vpelikh
Skip resolveSubtypes for sealed classes with @Schema(oneOf)
5b6504c
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
Merge branch '3.0.0' into pr-21-skip-resolve-subtypes-sealed-oneof
f41f5c9
@vpelikh vpelikh changed the title Skip resolveSubtypes for sealed classes with @Schema(oneOf) fix: skip resolveSubtypes for sealed classes with @Schema(oneOf) Sep 24, 2026
daniel-kmiecik added 2 commits September 24, 2026 13:09
@daniel-kmiecik
Merge branch '3.0.0' into pr-21-skip-resolve-subtypes-sealed-oneof
da60db3
@daniel-kmiecik
Merge branch '3.0.0' into pr-21-skip-resolve-subtypes-sealed-oneof
4954ae3
daniel-kmiecik
daniel-kmiecik approved these changes Sep 24, 2026
View reviewed changes
@daniel-kmiecik
daniel-kmiecik merged commit e66aae6 into swagger-api:3.0.0 Sep 24, 2026
6 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vpelikh
vpelikh deleted the pr-21-skip-resolve-subtypes-sealed-oneof branch October 19, 2026 06:05
@jochenberger jochenberger mentioned this pull request Nov 23, 2026
[Bug]: Sealed class with @JsonSubTypes and @Schema(oneOf) loses its inherited properties (regression from #5322) #5422
Open
2 tasks done
@Birthright50 Birthright50 mentioned this pull request Nov 26, 2026
[Bug]: NPE in resolveSubtypes for EnumSet schema properties on JDK 26+ #5426
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@daniel-kmiecik daniel-kmiecik daniel-kmiecik approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@vpelikh @daniel-kmiecik
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.