Skip to content

fix: deduplicate subtypes before composing oneOf - #5332

Open
vpelikh wants to merge 1 commit into
swagger-api:3.0.0from
vpelikh:pr-dedup-subtypes
Open

vpelikh wants to merge 1 commit 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).

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.

This branch has not been deployed

No deployments
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.

1 participant