Skip to content

fix: resolveSubtypes() return value is dead code and model.setDiscrim… - #5338

Merged
ewaostrowska merged 1 commit into
swagger-api:masterfrom
CommanderGeek:fix/5333-remove-dead-resolveSubtypes-return-2.x
Nov 27, 2026
Merged

ewaostrowska merged 1 commit into
swagger-api:masterfrom
CommanderGeek:fix/5333-remove-dead-resolveSubtypes-return-2.x

Conversation

@CommanderGeek

Copy link
Copy Markdown
Contributor

…inator(null) is a no-op

…or reset (#5333)

resolveSubtypes() always returned false because its local counter was never incremented, so the caller always ran model.setDiscriminator(null). That call had no effect: the model has no discriminator at that point and the discriminator is set exclusively by resolveDiscriminator() right afterwards.

Make resolveSubtypes() void and drop both setDiscriminator(null) branches. No change in generated schemas.

Pull Request

Thank you for contributing to swagger-core!

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


Description

ModelResolver.resolveSubtypes(...) always returned false because its local count was never incremented, so the caller always ran model.setDiscriminator(null). That call had no effect: at that point the model has no
discriminator yet, and the discriminator is set only by resolveDiscriminator(...), which runs right afterwards.

This PR removes the dead code (option 2 from the issue):

  • resolveSubtypes(...) now returns void; the unused count and return count != 0 are removed
  • the no-op model.setDiscriminator(null) branches are removed
  • a short comment explains why no discriminator reset is needed

The call order stays the same and resolveDiscriminator(...) still runs every time, so the generated schemas don't change.

Fixes: #5333

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

No new tests, since generated output is unchanged. The full mvn install passes, including all module tests.
Companion PR for the other branch: #5337

…inator(null) is a no-op

…or reset (swagger-api#5333)

resolveSubtypes() always returned false because its local counter was never
incremented, so the caller always ran model.setDiscriminator(null). That call
had no effect: the model has no discriminator at that point and the
discriminator is set exclusively by resolveDiscriminator() right afterwards.

Make resolveSubtypes() void and drop the setDiscriminator(null) branch.
No change in generated schemas.
@ewaostrowska
ewaostrowska force-pushed the fix/5333-remove-dead-resolveSubtypes-return-2.x branch from 0e03b3d to 11495c0 Compare November 27, 2026 11:17
@ewaostrowska
ewaostrowska merged commit 3eebb73 into swagger-api:master Nov 27, 2026
7 checks passed
@ewaostrowska

Copy link
Copy Markdown
Contributor

Hi @CommanderGeek! Thanks for porting it to master as well

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.

[Bug]: resolveSubtypes() return value is dead code and model.setDiscriminator(null) is a no-op

2 participants