[BUG] Kotlin-Client should support inheritance/$allOf bug with child required properties
Created by: mtraynham
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
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": "foo@bar.com"
},
"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