OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN] kotlin-spring is not picking up additionalModelTypeAnnotations config
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [ x] Have you provided a full/minimal spec to reproduce the issue?
- [x ] Have you validated the input using an OpenAPI validator (example)?
- [x ] Have you tested with the latest master to confirm the issue still exists?
- [x ] Have you searched for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generation of de model data classes in kotlin is not picking up de configuration of the property
configOptions.put("additionalModelTypeAnnotations", "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)")
The data classes are created without the annotation using the build.gradle.kts file
openapi-generator version
plugins {
java-library
id("org.openapi.generator") version "7.4.0"
kotlin("jvm") version "1.9.23"
}
OpenAPI declaration file content or url
Generation Details
The bug occurs when creating the model data classes. When these classes are generated then in de build folder you can check if the annotation is added on the data class. This flow works for Java classes but not for Kotlin classes. And in our case we need kotlin data classes
Steps to reproduce
openApiGenerate {
generatorName.set("kotlin-spring")
inputSpec.set("api.yml")
outputDir.set("$buildDir/generated")
configOptions.put("useSpringBoot3", "true")
configOptions.put("interfaceOnly", "true")
configOptions.put("unhandledException", "true")
configOptions.put("useOptional", "true")
configOptions.put("useTags", "true")
configOptions.put("enumPropertyNaming", "UPPERCASE")
configOptions.put("hideGenerationTimestamp", "true")
configOptions.put("serializationLibrary", "jackson")
configOptions.put("additionalModelTypeAnnotations", "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)")
}
run gradle assemble and view the model data classes. In these classes you don't see the annotation.
Alternative with only Java does work.
When you follow these step with
generatorName.set("spring")
... etc
then the java classes for the model are created with the annotation above the class
Related issues/PRs
[BUG] Openapi-generator - generating springboot model class with lombok annotation #17780
Suggest a fix
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 the provided build.gradle.kts reproduction using the kotlin-spring generator and inspect the generated model data classes in the build output. Compare the result with the spring generator, where the annotation is applied, and trace the Kotlin model-generation path. Done means additionalModelTypeAnnotations produces the requested annotation on Kotlin model classes and the behavior is covered by an appropriate generator test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100