-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] [Java] Java generator initialize non-required collections with empty collection #14875
Comments
have you tried setting the |
Yes, this option makes all collections initialize as null, but default behavior expected empty collection in requred ones.
|
Also, I want to add that "spring" generator, for example, works as expected: required ones generated with empty collection, non-required with null. |
Having the same issues when we upgrade to 6.3.0 and 6.4.0. It works fine in 6.2.1 and below. |
Hi all, can you please test #14961 when you've time? I did a test with the spec provided in this issue and the result looks good:
|
Hi. Thanks! #14961 works perfectly in my case. |
@eivbjorkelund thanks for confirming the fix 🙏 |
the fix has been merged and will be included in the upcoming 6.5.0 release |
I have this exactly same issue in the version 6.6.0. A collection field marked as 'required' in the Open API definition is initialized as null. I can confirm that until version 6.2.1 it is working as expected. |
@fastluca please open a new issue with a spec to reproduce the issue. |
Bug Report Checklist
Description
After upgrading openapi generator 5.1.1 -> 6.3.0 our integration tests was broken. Reason that API expected null as a init value of the non-required collection property in the pojo classes, but new version initialize it with empty collection (like required ones).
Expected:
Actual:
Also, generator don't respect
@Nullable
annotation, but works as expected if you addnullable: true
in spec to the propertyopenapi-generator version
6.2.1, 6.3.0, 6.4.0
OpenAPI declaration file content or url
Generation Details
Used Java 11 with gradle
Steps to reproduce
Related issues/PRs
This one provides toggle to set null as default for all collections (required and non-required). But no solution to keep null only for non-required as in previous versions.
#1861
Suggest a fix
For me I just made this workaround in openapi/Java/pojo.mustache.
Changed this
To this
The text was updated successfully, but these errors were encountered: