OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Kotlin] Sibling properties are ignored
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?
Description
Spec with allOf inheritance and sibling properties is not generated correctly in kotlin.
Version
$ openapi-generator-cli version
5.3.0
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "title",
"version": "v1"
},
"paths": {},
"components": {
"schemas": {
"Generic": {
"type": "object",
"properties": {
"a": {
"type": "string"
}
}
},
"Derived": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Generic"
}
],
"properties": {
"b": {
"type": "string"
}
}
}
}
}
}
Output vs Expected Output
openapi-generator-cli generate -g kotlin -i swagger.json
which results with
data class Derived (
@Json(name = "a")
val a: kotlin.String? = null
)
however, I would expect
data class Derived (
@Json(name = "a")
override val a: kotlin.String? = null,
@Json(name = "b")
val b: kotlin.String? = null
) : Generic
Related issues/PRs
Most related issues (e.g. #4171) use a spec where properties are elements in allOf array. However, Swashbuckle.AspNetCore generates a spec where properties are a sibling object which is a perfectly syntax as claimed by the that lib maintainers.
What's at fault?
Generating java models with
openapi-generator-cli generate -g java -i swagger.json
works perfectly fine with the same spec. It seems that the problem is with the kotlin generator itself.
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
Reproduce the issue with the supplied OpenAPI declaration and openapi-generator-cli generate -g kotlin -i swagger.json, then compare the generated Derived model with the expected output. Trace the Kotlin generator path responsible for allOf inheritance and sibling properties; done means the generated model includes both a and b, the override, and the Generic inheritance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100