OpenAPITools / OpenAPITools/openapi-generator
[REQ][kotlin-spring] Option to disable default value generation for optional model properties
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
The kotlin-spring generator adds = null to all optional properties in data classes:
data class UserDto(
val name: String,
val email: String? = null,
val role: RoleEnum? = null
)
This causes two problems:
- Silent data loss at scale. In projects with hundreds of models, default = null lets
callers omit fields without any compiler warning. When a new field is added, every existing
call site compiles fine and the missing field goes unnoticed until production. - Incorrect behavior with some libraries. Tools like MapStruct don't handle Kotlin default
values correctly, leading to bugs in mapping logic.
Describe the solution you'd like
A config option (e.g. ommitDefaultNullValues) that omits = null defaults for optional
properties:
data class UserDto(
val name: String,
val email: String?,
val role: RoleEnum?
)
Implementation:
https://github.com/OpenAPITools/openapi-generator/pull/23077
a switch in KotlinSpringServerCodegen.java + conditional wrap in
dataClassOptVar.mustache.
Describe alternatives you've considered
- Custom templates (--template-dir): works but requires maintaining a template fork across
upgrades.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with KotlinSpringServerCodegen.java and dataClassOptVar.mustache, as identified in the issue, and review pull request 23077. Verify that the new configuration switch controls whether optional properties receive = null while preserving the existing default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, spring
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100