[FIX][KOTLIN][SPRING] mark @param:JsonProperty as required in generated models when required in open api spec

Merged
SV
2mo ago
+119-101

Fixes a kotlin-spring regression introduced in v7.24.0 (by #24036), where required primitive properties could be silently defaulted when missing in request JSON.

Related issue

Fixes #24753

What changed

  • Updated required kotlin-spring model vars to emit:
    • @param:JsonProperty("...", required = true)
  • Added/updated kotlin-spring generator tests to assert:
    • required vars use @param:JsonProperty(..., required = true)
    • optional vars still use plain @param:JsonProperty("...")

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.

@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10)


Summary by cubic

Restores required-property validation in generated Kotlin Spring models. Previously (since v7.24.0), missing required primitives could be silently defaulted because constructor params used plain @param:JsonProperty; now required vars emit @param:JsonProperty(..., required = true) so Jackson fails on missing fields.

  • Behavior: required vars add required = true on @param:JsonProperty; optional vars remain unchanged. Aligns with existing @get:JsonProperty(..., required = true).
  • Diff hotspots: dataClassReqVar.mustache template updated; tests added to assert required/optional behavior; samples regenerated.
  • Migration: regenerate kotlin-spring server models to restore missing-field failures. No runtime/config changes.