Skip to content

fix: _isSetType now detects indirect Set implementations - #5265

Open
vpelikh wants to merge 1 commit into
swagger-api:masterfrom
vpelikh:fix/isSetType-indirect-Set-implementations
Open

fix: _isSetType now detects indirect Set implementations#5265
vpelikh wants to merge 1 commit into
swagger-api:masterfrom
vpelikh:fix/isSetType-indirect-Set-implementations

Conversation

@vpelikh

@vpelikh vpelikh commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

_isSetType in AbstractModelConverter failed to recognize indirect Set implementations such as LinkedHashSet, HashSet, and TreeSet.

The old implementation only matched an exact Set.class equality check, plus a direct interface scan via Class.getInterfaces(). Because getInterfaces() only returns directly implemented interfaces, subclasses that inherit Set behavior through a parent class (for example a custom class extending AbstractSet or a collection extending a concrete Set) were not detected, so uniqueItems was not set on the generated schema.

Change

  • Replaced Set.class.equals(cls) with Set.class.isAssignableFrom(cls) in protected boolean _isSetType(Class<?> cls).
  • Preserved the existing scala Set detection (checked via direct interfaces) to avoid pulling the scala runtime dependency.
  • Made the null case explicit (returns false).

Tests

Added IsSetTypeTest with 7 test cases:

  • null -> not a Set
  • Set interface -> Set
  • HashSet -> Set
  • LinkedHashSet -> Set
  • TreeSet -> Set
  • non-Set collections (List, ArrayList) -> not a Set
  • non-collection types (String, Integer, Map) -> not a Set

All 7 tests pass.

Replace Set.class.equals(cls) with Set.class.isAssignableFrom(cls) so that types like LinkedHashSet, HashSet, and TreeSet are correctly identified as Set types for uniqueItems schema generation.

Previously only exact Set.class matches were caught, plus direct interface checks via getInterfaces() which miss inherited Set implementations.

Add IsSetTypeTest with 7 test cases covering null, the Set interface, HashSet, LinkedHashSet, TreeSet, non-Set collections, and non-collection types.
@ewaostrowska ewaostrowska added the backlog label Aug 13, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants