OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.45k stars 6.49k forks source link

Different handling of java Optional for models and APIs #17675

Open arandth opened 8 months ago

arandth commented 8 months ago

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?

arandth commented 8 months ago

Please note that I found a workaround: I simply invoked the generator twice (one call for API only (use-optional=true), the other one for the models only (use-optional=false). That works fine, even when invoked with the openapi-generator-maven-plugin

yasstec commented 4 months ago

Still facing the same issue in openapi-generator 7.5.0

UnleashSpirit commented 4 months ago

Hello, we really need this distinction. The PR https://github.com/OpenAPITools/openapi-generator/pull/17202, was made for its own purposes and as we can see in the thread, a lot of people are bothered by this MAJOR change. (even if I understand the arguments)

So I love the idea of ​​two "useOptionals", one for the API and one for the model. The work around works, but when you call many other RESTApis, doubling the generation becomes cumbersome and a waste of time. We still can use the openApiNullable, but it's hard to find in documentation and not sure it's 100% the same behaviour that before