Skip to content

refactor: add an overloaded method for resolving required so that the field type can be utilized - #5042

Merged
daniel-kmiecik merged 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:overloaded-required-mode-resolver
Jan 27, 2026
Merged

refactor: add an overloaded method for resolving required so that the field type can be utilized#5042
daniel-kmiecik merged 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:overloaded-required-mode-resolver

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Jan 22, 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

TL;DR:
Makes it possible to easily determine the required mode for a property based upon the class type. This is done by introducing an overloaded method resolveRequiredMode that also takes a JavaType, and then making the default behavior that the application passes the already accessible propType to the method.


This is a subject I have been asked about before both in swagger-core but also in springdoc-openapi.

There exists good documentation for how to achieve the change for the default for all (define a new ModelResolver and override the resolveRequiredMode metod). But if we wanted to control it based upon the field/property type, we would have to override the entire ModelResolver and its 1000+ lines resolve-method.

With this change we can rather go back to only overriding a small, clearly defined, part of the class to achieve the behavior. I have illustrated how this can be achieved in a test.

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

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the overloaded-required-mode-resolver branch 2 times, most recently from 98cd57a to e88d9de Compare January 26, 2026 17:04
Comment thread modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java Outdated
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the overloaded-required-mode-resolver branch from e88d9de to 2cbe66b Compare January 26, 2026 19:39
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the overloaded-required-mode-resolver branch from 2cbe66b to 2831ab4 Compare January 26, 2026 19:40
@daniel-kmiecik
daniel-kmiecik merged commit a66e10f into swagger-api:master Jan 27, 2026
7 checks passed
@daniel-kmiecik

Copy link
Copy Markdown
Collaborator

@Mattias-Sehlstedt great work. Thank you for your contribution!

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.

3 participants