Skip to content

Issue 22784#22840

Open
kingofdisasterr wants to merge 4 commits intoOpenAPITools:masterfrom
kingofdisasterr:issue_22784
Open

Issue 22784#22840
kingofdisasterr wants to merge 4 commits intoOpenAPITools:masterfrom
kingofdisasterr:issue_22784

Conversation

@kingofdisasterr
Copy link

@kingofdisasterr kingofdisasterr commented Jan 28, 2026

fixes #22784

@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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.

  • Bug Fixes
    • Optional array properties with minItems > 0 now generate as uninitialized (@nullable List) rather than new ArrayList<>().
    • Added OpenAPI 3.1 sample and SpringCodegen test to verify the behavior.
    • Updated petstore sample (AnyTypeTest) to remove default empty list initialization.

Written for commit 92c4bc0. Summary will update on new commits.

@kingofdisasterr
Copy link
Author

@wing328 i had to open a new PR since i messed up with this one: #22794

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

// 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())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate to a new if below. With the inlined comment. (Potentially also the Issue-Id #?)

@MelleD
Copy link
Contributor

MelleD commented Mar 2, 2026

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.
Depending on how you set up your ObjectMapper, empty arrays are also optional values. Perhaps this is also an option for you. There are many good descriptions of why null arrays and empty arrays have the same semantic meaning in REST API. Normally, you don't need more than 2 states in REST API (except for patch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Java][Spring][SpringBoot] optional array with 'minItems' set, fails validation

3 participants