Skip to content

[kotlin-spring] Implement skipDefaultValues in mustache templates#23077

Open
mikhailsnnt wants to merge 1 commit intoOpenAPITools:masterfrom
mikhailsnnt:kotlin-default-values-switch
Open

[kotlin-spring] Implement skipDefaultValues in mustache templates#23077
mikhailsnnt wants to merge 1 commit intoOpenAPITools:masterfrom
mikhailsnnt:kotlin-default-values-switch

Conversation

@mikhailsnnt
Copy link

@mikhailsnnt mikhailsnnt commented Mar 1, 2026

Summary

  • Add skipDefaultValues option to KotlinSpringServerCodegen and wire it into mustache templates
  • Wrap default value assignments in dataClassOptVar.mustache and dataClassReqVar.mustache with {{^skipDefaultValues}}...{{/skipDefaultValues}} guards
  • When skipDefaultValues=true, generated Kotlin data class properties no longer include = null or other default value assignments

Test plan

  • Added testSkipDefaultValues test in KotlinSpringServerCodegenTest that generates petstore models with the flag enabled and asserts = null is absent
  • Test passes: mvn test -pl modules/openapi-generator -Dtest=KotlinSpringServerCodegenTest#testSkipDefaultValues

Summary by cubic

Adds a skipDefaultValues option to KotlinSpringServerCodegen to omit default assignments in generated data classes. When enabled, properties no longer include "= null" or other defaults.

  • New Features

    • Added skipDefaultValues switch to KotlinSpringServerCodegen.
    • Updated dataClassOptVar.mustache and dataClassReqVar.mustache to guard default assignments with skipDefaultValues.
  • Migration

    • Enable by setting skipDefaultValues=true in additionalProperties or via the generator switch.
    • Default behavior is unchanged when the option is not set.

Written for commit 9aecb8f. Summary will update on new commits.

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 4 files

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.

1 participant