Skip to content

[kotlin-spring, java-spring] - gate @JsonSetter on openApiNullable for optional non-nullable fields#23993

Open
Picazsoo wants to merge 2 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/add-@JsonSetter(nulls-=-Nulls.FAIL)-only-for-openApiNullable
Open

[kotlin-spring, java-spring] - gate @JsonSetter on openApiNullable for optional non-nullable fields#23993
Picazsoo wants to merge 2 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/add-@JsonSetter(nulls-=-Nulls.FAIL)-only-for-openApiNullable

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #23976 by making @JsonSetter generation respect the openApiNullable decision agreed in the issue discussion.

Summary of changes

  • For optional, non-nullable properties (required: false, nullable: false):

    • openApiNullable=false now generates @JsonSetter(nulls = Nulls.SKIP), so explicit JSON null is ignored and existing/default values are protected.
    • openApiNullable=true keeps/generates @JsonSetter(nulls = Nulls.FAIL), so explicit JSON null is rejected for stricter PATCH-style semantics.
  • The Kotlin Spring generator was updated to stop unconditionally emitting Nulls.FAIL for optional non-nullable fields.

  • Java Spring was aligned for the openApiNullable=false case by adding @JsonSetter(nulls = Nulls.SKIP) to generated setters, including the required Jackson imports. This is especially important for optional non-nullable attributes with defaults where it was possible to overwrite the expected default.

  • Tests and sample outputs were updated to cover:

    • Kotlin Spring behavior with and without openApiNullable
    • default-value protection via Nulls.SKIP
    • Jackson 3 import behavior
    • regenerated Kotlin Spring and Java Spring samples
  • Kotlin Spring documentation for openApiNullable was expanded to explain the new strict-vs-lenient null handling behavior.

    Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. - tagging: @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) and @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02)

It would be really good to get some java-spring feedback for the Nulls.SKIP for optional non-nullable.


Summary by cubic

Gated @JsonSetter generation for optional, non-nullable fields in Kotlin Spring and Java Spring based on openApiNullable. Restores lenient handling when openApiNullable=false and keeps strict null rejection when openApiNullable=true.

  • Bug Fixes
    • Optional non-nullable fields now respect openApiNullable: openApiNullable=false@JsonSetter(nulls = Nulls.SKIP); openApiNullable=true@JsonSetter(nulls = Nulls.FAIL).
    • Java Spring now emits @JsonSetter(nulls = Nulls.SKIP) for the same case. Added JsonSetter/Nulls imports from com.fasterxml.jackson.annotation and updated templates, tests, and samples.
    • Updated Kotlin Spring docs for openApiNullable to clarify strict-null behavior and requirements.

Written for commit 0f44be5. Summary will update on new commits.

Review in cubic

…for optional non-nullable fields

   For optional + non-nullable properties (required: false, nullable: false):
   - openApiNullable=false → @JsonSetter(nulls = Nulls.SKIP): silently ignores
     explicit JSON null, protecting any defined default from being overridden
   - openApiNullable=true → @JsonSetter(nulls = Nulls.FAIL): rejects explicit
     JSON null, enforcing the non-nullable contract (useful for PATCH semantics)

   Previously, Nulls.FAIL was unconditionally generated for all optional
   non-nullable fields regardless of openApiNullable, causing a breaking change
   for users on openApiNullable=false.

   Java Spring now also emits @JsonSetter(nulls = Nulls.SKIP) for the same case
   (previously it emitted nothing).

   Fixes OpenAPITools#23976

   Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo Picazsoo marked this pull request as ready for review June 10, 2026 23:09
@Picazsoo Picazsoo marked this pull request as draft June 10, 2026 23:09
@Picazsoo Picazsoo marked this pull request as ready for review June 10, 2026 23:39
@Picazsoo Picazsoo marked this pull request as draft June 10, 2026 23:40

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 281 files

Note: This PR contains a large number of files. cubic only reviews up to 100 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

@Picazsoo Picazsoo marked this pull request as ready for review June 10, 2026 23:47
@Picazsoo

Copy link
Copy Markdown
Contributor Author

Tagging you @mfunda-cen59049 for review as agreed upon.

@mfunda-cen59049 mfunda-cen59049 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for providing a fix for the issue so quickly. I went over the code changes and this will help a lot with our current use-case.

@Picazsoo Picazsoo changed the title fix(kotlin-spring, java-spring): gate @JsonSetter on openApiNullable … [kotlin-spring, java-spring] - gate @JsonSetter on openApiNullable … Jun 11, 2026
@Picazsoo Picazsoo changed the title [kotlin-spring, java-spring] - gate @JsonSetter on openApiNullable … [kotlin-spring, java-spring] - gate @JsonSetter on openApiNullable for optional non-nullable fields Jun 11, 2026
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][Kotlin] JsonSetter(nulls = Nulls.FAIL) generated even with openApiNullable = false

2 participants