openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][KOTLIN] kotlin-spring is not picking up additionalModelTypeAnnotations config

Open ebleeker opened this issue 1 year ago • 1 comments

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

ebleeker avatar Apr 11 '24 11:04 ebleeker

Hello, any update on this?

aldex32 avatar May 07 '24 10:05 aldex32