You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using multi-level inheritance, the kotlin-spring generator produces non-compiling code.
> Task :compileKotlin FAILED
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (21, 1): Function 'component1' generated for the data class conflicts with member of supertype 'Dog'
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (21, 1): Function 'component2' generated for the data class conflicts with member of supertype 'Dog'
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (21, 1): Function 'component3' generated for the data class conflicts with member of supertype 'Dog'
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (31, 32): 'breed' in 'Dog' is final and cannot be overridden
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (32, 5): This type is final, so it cannot be inherited from
e: .../src/main/kotlin/org/openapitools/model/BigDog.kt: (32, 5): This type has a constructor, and thus must be initialized here
It's especially unfortunate because Java does support this. We must use mechanisms that work across Java & Kotlin and therefore we have to go with the least common denominator preventing us from using multi-level polymorphism.
Similar issue has been submitted for Java a long time ago: #3058.
Suggest a fix
Unfortunately Kotlin doesn't support data class inheritance.
So the options I can think of:
generate an interface hierarchy and use data classes for the "leaf" DTOs: e.g. interfaces: IAnimal, IDog : IAnimal, data classes: Cat : IAnimal, Dog: IDog, BigDog: IDog not very pretty but most times you work with the DTOs.
move away from data classes - use regular classes, however this would prevent usage of data class capabilities (e.g. copy) which I personally find very useful
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When using multi-level inheritance, the
kotlin-spring
generator produces non-compiling code.It's especially unfortunate because Java does support this. We must use mechanisms that work across Java & Kotlin and therefore we have to go with the least common denominator preventing us from using multi-level polymorphism.
openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Similar issue has been submitted for Java a long time ago: #3058.
Suggest a fix
Unfortunately Kotlin doesn't support data class inheritance.
So the options I can think of:
IAnimal
,IDog : IAnimal
, data classes:Cat : IAnimal
,Dog: IDog
,BigDog: IDog
not very pretty but most times you work with the DTOs.copy
) which I personally find very usefulThe text was updated successfully, but these errors were encountered: