-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Fix default empty collections when collection is optional #18080
Fix default empty collections when collection is optional #18080
Conversation
thanks for the PR. from what I can tell, looks like we need another option, e.g. containerDefaultToEmptyContainer to fallback to 6.x behavior. |
What exactly was the 6.x behavior? And why was the 6.x behavior changed? |
i think empty list was the default behaviour in 6.x it was changed to allowed
with your change, JSON payload will be something like |
But now, that is the behaviour when
But now this is the case, if you set the optional collection to
It depends on your Jackson Object Mapper configuration: |
please see the comment in #15891 (comment) no matter which way we set the default - null or empty list. some users may prefer the other way around instead. that's why i think using an option to let users choose is the only way |
Yes answer is set the the attribute to
From my point of view, it is currently possible to set any combination you want with the PR. I don't see any advantage in using a new parameter just because users find it uncool to set If there is a use case that cannot currently be implemented, then I would understand it. |
to be clear, I'm not against this fix at all. As you said, it covers pretty much all use cases which is good. we can ask users to add can you update the tests to fix https://github.com/OpenAPITools/openapi-generator/actions/runs/8245275952/job/22548958623?pr=18080? I think later I will add a rule in normalizer (e.g. setContainerToNullable: array) to set array to nullable as some other generators (e.g. C# client) have similar use cases before. |
Yes 👍 , I would just to clarify the use case for a new option.
That was my question is there an "edge" case, but from the ticket, I don't see this. I just don't understand the difference between the new option and Even if the spec comes from someone else, the option is still clear. To me the option sounds like we would bypass the original open api semantics by the generator ;). |
Personally I don't want another option either as you may seen my similar replies before (some users are overloaded with too many options) |
that's one of the directions we're going with the help of the openapi normalizer. |
@wing328 Can we make a new option (for whatever reason) in a different PR? |
Would this also be resolved by specifying a default value (of an empty array) in the specification? I can see the value of supporting this, but it does seem like the more proper solution would be to update the spec to provide a default value in the case. |
Good question. I think not, I changed nothing on this behaviour. EDIT: Created a small test added
codegen.setContainerDefaultToNull(true); out come:
So works, right? |
Yeah, that is my thinking - by providing I still think your change is valid for the scenario where the user can't change the spec, but seems like a workaround 🤷 |
But looks for
But why? a) b) So what is the workaround here? And in the end you can decide with the Jackson Property how the json looks like. |
Those are good points, I agree with you and think this doesn't need to be solved. If it's broken for |
Yes looks broken somehow for @welshm What do you think can we merge this PR. And if need a new option and fix the Set issue we make a new PR? |
Sounds reasonable to me |
I think I found the issue |
agreed with merging this one and file separate PRs to address other issues. |
likely I will file a PR this weekend to create a rule in normalizer to set nullable in array to true. |
looks good. will merge after all tests pass. thanks again for the PR. |
FYI. Filed #18128 to add a new rule in normalizer to set container to nullable. |
If the collection is optional, an empty list/set is created so as not to have null values.
This behavior can be influenced by containerSetToNull
Fix issue #15891 (comment)
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
@cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)