Skip to content

refactor: add DiscriminatorResolver for handling discriminator properties in schemas - #5250

Open
Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:discriminator-utils
Open

refactor: add DiscriminatorResolver for handling discriminator properties in schemas#5250
Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:discriminator-utils

Conversation

@Mattias-Sehlstedt

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

Moves Discriminator resolving logic into a separate Utils class.

A commonly requested feature is to extend the discriminator introspection. There exists a PR for this, but I would find it easier to reason about any change if the logic was isolated from the larger monster that is ModelResolver. This so that ModelResolver is not cluttered with more subdomain (managing discriminators) logic, and that the ModelResolver is instead only responsible for exposing an area of these subdomains if there is a reason to provide a helpful extension point.

I.e., Utils provide stateless logic for subdomains of handling specifications, and the ModelResolver mainly combine these smaller parts into something larger.

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)

@ewaostrowska

Copy link
Copy Markdown
Contributor

Hi @Mattias-Sehlstedt! Thank you for working on improving the code in Swagger Core once again.
We appreciate a lot any intent to make the Model Resolver any smaller :) That's definitely something that needs to be done.

One issue that I see with this refactor is that it is creating a new public API and it seems unintentional. DiscriminatorUtils is public, and both methods are public static methods. Once released, consumers may treat these methods as supported API, creating future compatibility obligations.

The DiscriminatorUtils in this form does not establish a strong public use case. I would keep it internal.

Please consider moving it in the io.swagger.v3.core.jackson package and making it package-private.

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor Author

I have moved it to the jackson package and made it package private. I have also added a private constructor to align it with the already existing "utils" class there (JAXBAnnotationsHelper). Should it be renamed to Helper too? I personally find Utils to be the more common and descriptive naming pattern.

The other common pattern is to utilize JavaDoc to explicitly state that the signature is volatile/subject to change/internal. But I could not find that the project has done that before so a bit odd to start with it now.

@ewaostrowska ewaostrowska added the backlog label Jul 23, 2026 — with Claude
@ewaostrowska
ewaostrowska force-pushed the discriminator-utils branch from d2df2c2 to e5a5513 Compare July 29, 2026 13:45
@ewaostrowska

Copy link
Copy Markdown
Contributor

@Mattias-Sehlstedt thank you for carrying out these changes. Since the project does not use JavaDoc annotations I do not see any reason to introduce it here. I would argue that even Resolver instead of Util would make sense here, but I am fine with merging it as it is.

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor Author

I agree with the suggestion of changing it to Resolver and have adjusted to that. It makes it clearer that the ModelResolver is itself a resolver of resolvers that handle sub-subjects.

It also aligns well with the fact that there already is one such complex area that has been isolated to its own Resolver (TypeNameResolver).

@Mattias-Sehlstedt Mattias-Sehlstedt changed the title refactor: add DiscriminatorUtils for handling discriminator properties in schemas refactor: add DiscriminatorResolver for handling discriminator properties in schemas Jul 29, 2026
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