refactor: add an overloaded method for resolving required so that the field type can be utilized by Mattias-Sehlstedt · Pull Request #5042 · swagger-api/swagger-core (original) (raw)
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)