Conversation
…enerated list in models to uninitialized list
…enerated list in models to uninitialized list
…enerated list in models to uninitialized list
…enerated list in models to uninitialized list
| // nullable or containerDefaultToNull set to true | ||
| if (cp.isNullable || containerDefaultToNull) { | ||
| // nullable or containerDefaultToNull set to true or an optional array with minItems > 0 | ||
| if (cp.isNullable || containerDefaultToNull || (cp.minItems != null && cp.minItems > 0 && !cp.getHasRequired())) { |
There was a problem hiding this comment.
Separate to a new if below. With the inlined comment. (Potentially also the Issue-Id #?)
|
You cannot change the default for everyone. Some people do not have nulls in their projects. That is why you need to consider the containerDefaultToNull property. Furthermore, I am convinced that you can easily implement your plan with a change in the open API spec. You either have to use minItems with a required property (which makes more sense in my opinion) or you have to set minItems and nullable: true, then a null array should also be generated. The last and simplest option is to use containerDefaultToNull and if something doesn't work there, fix this. Optional arrays do NOT have to be null. |
fixes #22784
@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Generate optional arrays with minItems > 0 as null in Java models instead of defaulting to empty lists. This prevents empty arrays that violate minItems and aligns the Java/Spring codegen with the OpenAPI spec. Fixes #22784.
Written for commit 92c4bc0. Summary will update on new commits.