Skip to content

fix: _isSetType now detects indirect Set implementations - #5265

Merged
ewaostrowska merged 1 commit into
swagger-api:masterfrom
vpelikh:fix/isSetType-indirect-Set-implementations
Aug 26, 2026
Merged

fix: _isSetType now detects indirect Set implementations#5265
ewaostrowska merged 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.

@ewaostrowska ewaostrowska added the backlog label Aug 13, 2026 — with Claude
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 force-pushed the fix/isSetType-indirect-Set-implementations branch from bcd59f3 to cdd3d25 Compare August 26, 2026 09:31
@ewaostrowska

Copy link
Copy Markdown
Contributor

Thank you @vpelikh for providing this PR, looks like it should help with the Set classification

@ewaostrowska
ewaostrowska merged commit c7d7736 into swagger-api:master Aug 26, 2026
7 checks passed
@vpelikh
vpelikh deleted the fix/isSetType-indirect-Set-implementations branch August 26, 2026 13:26
vpelikh pushed a commit to vpelikh/swagger-core that referenced this pull request Aug 28, 2026
Resolve conflicts from upstream 2.x sync onto the vpelikh 4.x fork:

- .github/dependabot.yml: keep fork 'master' target-branch; adopt upstream
  'allow' rules (semver-minor/patch plus dependency-check-maven major).
- pom.xml: keep fork's 4.x dependency versions (dependency-check-maven
  13.0.0, slf4j 2.0.18, jetty 12.1.12, etc.); drop upstream's
  commons-lang-version (commons-lang3 removed from the fork).
- .github/workflows/prepare-release.yml and modules/swagger-project-jakarta/
  pom.xml: retain fork deletions (already removed on the fork).

Upstream code fix '_isSetType now detects indirect Set implementations'
(swagger-api#5265) is auto-merged into AbstractModelConverter.
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