OpenAPITools / OpenAPITools/openapi-generator
Different handling of java Optional for models and APIs
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I was trying to update from openapi-generator 7.1.0 to 7.2.0. That causes problems due to a changed handling of useOptional. In 7.1.0, only methods in API's were treated (not attributes of the generated model classes.)
With 7.2.0 that obviously changed, suddenly also the generated model classes have Optional fields (if they are not marked as required). One might argue that this is the correct behavior of the generator, but on the other hand it prevents us from updating - it would be a very hard work to change the implementation in either all APIs or all model classes.
So what we would need is to destinguish between APIs and models (such as "useOptionalInApi" / "useOptionalInModel" or similar). Is that already possible?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the useOptional setting is applied during Java generation for API methods and model attributes. Compare the generated APIs and model classes between versions 7.1.0 and 7.2.0, then determine how separate API and model controls could be exposed. Done means users can select Optional handling independently without changing unrelated generated code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100