Skip to content

fix: deduplicate subtypes before composing oneOf - #5332

Merged
ewaostrowska merged 2 commits into
swagger-api:3.0.0from
vpelikh:pr-dedup-subtypes
Oct 14, 2026
Merged

ewaostrowska merged 2 commits into
swagger-api:3.0.0from
vpelikh:pr-dedup-subtypes

Conversation

@vpelikh

@vpelikh vpelikh commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Thank you for contributing to swagger-core!

Please fill out the following information to help us review your PR efficiently.


Description

Identical @JsonSubTypes entries (and Jackson's AnnotationIntrospectorPair) can report the same subtype more than once. Once a polymorphic parent is composed into a oneOf (see #5320), each duplicate entry becomes a repeated $ref in the composed schema.

resolveSubtypes() now drops duplicate subtypes while preserving declaration order.

Bug fix; based on 3.0.0 and independent of #5320.

Related: #5320

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

The duplicate only becomes observable once a parent is composed into a oneOf (#5320), so the added test passes on 3.0.0 alone and only guards against the duplicate after #5320 lands.

Merge order: both orders work, but landing this before #5320 is recommended (independent, and inert on 3.0.0).

@ewaostrowska

Copy link
Copy Markdown
Contributor

Hi @vpelikh, thank you for the PR!
I have made one change here - deduplicating by Class instead of the NamedType

NamedType.equals checks the class and the name. So
@Type(Child.class, name = "a") and @Type(Child.class, name = "b")
were both kept. With #5320 this. would still gives two equal $refs in oneOf.

vpelikh and others added 2 commits October 14, 2026 12:44
Identical @JsonSubTypes entries (and Jackson's AnnotationIntrospectorPair) can
report the same subtype more than once. Once a polymorphic parent is composed
into a oneOf (see swagger-api#5320), each duplicate entry becomes a
repeated $ref in the composed schema, e.g. two $refs to the same subtype.

resolveSubtypes() now drops duplicate subtypes via a new removeDuplicateSubTypes()
helper, preserving declaration order.
@ewaostrowska
ewaostrowska merged commit 9d83dc2 into swagger-api:3.0.0 Oct 14, 2026
7 checks passed
@vpelikh
vpelikh deleted the pr-dedup-subtypes branch October 19, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants