swagger-api / swagger-api/swagger-codegen-generators
Kotlin inheritance is broken when using Enums
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
swagger-core currently generates enums inlined. I've opened a corresponding bug to be able to pull these classes out into their own enum referenced object which seems to be supported in OAS3, https://github.com/swagger-api/swagger-core/issues/3124.
Either way, the kotlin-client generator is currently generating non-compilable Kotlin code.
For example, this is what's derived from swagger-core:
{
"openapi" : "3.0.1",
"info" : {
"title" : "Test",
"contact" : {
"email" : "support@test.com"
},
"version" : "1.0"
},
"paths" : {},
"components" : {
"schemas" : {
"Parent" : {
"type" : "object",
"properties" : {
"enumeration" : {
"type" : "string",
"enum" : [ "TEST" ]
}
}
},
"Child" : {
"type" : "object",
"properties" : {},
"allOf" : [ {
"$ref" : "#/components/schemas/Parent"
} ]
}
}
}
}
When generating the Kotlin model classes with swagger-codegen, this generates exploded classes because Kotlin data classes cannot be inherited. The issue is the Child's reference to the Enumeration class which does not exist.
Parent.kt
/**
*
* @param enumeration
*/
data class Parent (
val enumeration: Parent.Enumeration? = null
) {
/**
*
* Values: TEST
*/
enum class Enumeration(val value: kotlin.String){
TEST("TEST");
}
}
Child.kt
/**
*
*/
data class Child (
val enumeration: Child.Enumeration? = null
) {
}
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 kotlin-client generator and compare the generated Parent.kt and Child.kt models shown in the issue. Reproduce the schema, trace how inherited properties and inline enums are rendered, and verify that the generated Kotlin classes compile without an unresolved Child.Enumeration reference.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100