OpenAPITools / OpenAPITools/openapi-generator
[BUG] [KOTLIN] simple data type of arrays is lost on implementing classes or discriminator interfaces
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating data classes of an interface declaring properties having an array of primitive types, the resulting type of the list resolves to kotlin.Any and the code doesn't compile.
Same happens for discriminator interfaces.
openapi-generator version
7.5.0
OpenAPI declaration file content or url
https://gist.github.com/toggm/f8ea4f221a49ccb34b082fe1585b78b3
Generation Details
openapi-generator-cli 7.5.0
commit : cce4139
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
Generated data class or interface is ok:
data class Interface(
@Schema(example = "null", description = "")
@get:JsonProperty("stringArrayProperty") val stringArrayProperty: kotlin.collections.List<kotlin.String>? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("booleanArrayProperty") val booleanArrayProperty: kotlin.collections.List<kotlin.Boolean>? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("objectArrayProperty") val objectArrayProperty: kotlin.collections.List<MyObject>? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("type") val type: kotlin.String? = null
Generated data class for MyImpl lost type information:
data class MyImpl1(
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("stringArrayProperty") val stringArrayProperty: kotlin.collections.List<kotlin.Any>? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("booleanArrayProperty") val booleanArrayProperty: kotlin.collections.List<kotlin.Any>? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("objectArrayProperty") val objectArrayProperty: kotlin.collections.List<MyObject>? = null,
Same for discriminator interface:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes(
JsonSubTypes.Type(value = MyImpl1::class, name = "impl1")
)
interface DiscriminatorInterface{
@get:Schema(example = "null", description = "")
val title: kotlin.String?
@get:Schema(example = "null", description = "")
val stringArrayProperty: kotlin.collections.List<kotlin.Any>?
@get:Schema(example = "null", description = "")
val booleanArrayProperty: kotlin.collections.List<kotlin.Any>?
@get:Schema(example = "null", description = "")
val objectArrayProperty: kotlin.collections.List<MyObject>?
@get:Schema(example = "null", description = "")
val type: kotlin.String?
}
Steps to reproduce
Related issues/PRs
Suggest a fix
Didn't find workaround so far.
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 by reproducing the generated Kotlin models from the linked OpenAPI declaration with openapi-generator-cli 7.5.0, comparing the interface output with MyImpl1 and the discriminator interface. Trace the Kotlin generator path responsible for inherited array properties; done means primitive array element types remain String or Boolean instead of kotlin.Any and the generated code compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100