Bug Report Checklist
Description
Inheritance doesn't seem to be supported with kotlin-client. I would have expected a top level interface for parent classes and a child data class implementation which uses override to mark overridden values.
Also, for classes that are inherited via $allOf, it seems required properties on the child class get duplicated as optional properties. Like:
@Json(name = "c")
val c: kotlin.String,
@Json(name = "c")
val c: kotlin.String? = null
Following the OpenAPI declaration file below, the following is generated:
src/main/kotlin/org/openapitools/client/models/Parent.kt
data class Parent (
@Json(name = "a")
val a: kotlin.String,
@Json(name = "b")
val b: kotlin.String? = null
)
src/main/kotlin/org/openapitools/client/models/Child.kt
data class Child (
@Json(name = "a")
val a: kotlin.String,
@Json(name = "c")
val c: kotlin.String,
@Json(name = "b")
val b: kotlin.String? = null,
@Json(name = "d")
val d: kotlin.String? = null,
@Json(name = "c")
val c: kotlin.String? = null
)
You'll notice that not only is Parent not an interface, but within Child, property c is duplicated, once as required and secondly as optional.
I would have expected:
src/main/kotlin/org/openapitools/client/models/Parent.kt
interface Parent {
@Json(name = "a")
val a: kotlin.String
@Json(name = "b")
val b: kotlin.String?
}
src/main/kotlin/org/openapitools/client/models/Child.kt
data class Child (
@Json(name = "a")
override val a: kotlin.String,
@Json(name = "b")
override val b: kotlin.String? = null,
@Json(name = "c")
val c: kotlin.String,
@Json(name = "d")
val d: kotlin.String? = null
) : Parent
openapi-generator version
4.1.3
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "Test",
"description": "Test API",
"contact": {
"email": "[email protected]"
},
"version": "1.0.0"
},
"servers": [
{
"url": "https://192.168.1.1"
}
],
"paths": {},
"components": {
"schemas": {
"Parent": {
"required": [
"a"
],
"type": "object",
"properties": {
"a": {
"type": "string"
},
"b": {
"type": "string"
}
}
},
"Child": {
"required": [
"a",
"c"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Parent"
},
{
"type": "object",
"properties": {
"c": {
"type": "string"
},
"d": {
"type": "string"
}
}
}
]
}
},
"securitySchemes": {}
}
}
Command line used for generation
openapi-generator-cli generate -g kotlin -i API.json
Steps to reproduce
Related issues/PRs
Suggest a fix
Bug Report Checklist
Description
Inheritance doesn't seem to be supported with
kotlin-client. I would have expected a top level interface for parent classes and a child data class implementation which usesoverrideto mark overridden values.Also, for classes that are inherited via
$allOf, it seemsrequiredproperties on the child class get duplicated as optional properties. Like:Following the OpenAPI declaration file below, the following is generated:
src/main/kotlin/org/openapitools/client/models/Parent.kt
src/main/kotlin/org/openapitools/client/models/Child.kt
You'll notice that not only is
Parentnot an interface, but withinChild, propertycis duplicated, once as required and secondly as optional.I would have expected:
src/main/kotlin/org/openapitools/client/models/Parent.kt
src/main/kotlin/org/openapitools/client/models/Child.kt
openapi-generator version
4.1.3
OpenAPI declaration file content or url
{ "openapi": "3.0.1", "info": { "title": "Test", "description": "Test API", "contact": { "email": "[email protected]" }, "version": "1.0.0" }, "servers": [ { "url": "https://192.168.1.1" } ], "paths": {}, "components": { "schemas": { "Parent": { "required": [ "a" ], "type": "object", "properties": { "a": { "type": "string" }, "b": { "type": "string" } } }, "Child": { "required": [ "a", "c" ], "type": "object", "allOf": [ { "$ref": "#/components/schemas/Parent" }, { "type": "object", "properties": { "c": { "type": "string" }, "d": { "type": "string" } } } ] } }, "securitySchemes": {} } }Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix