OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN-SPRING] Constructor call generated for interface supertypes if using inheritance/discriminator
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
If the parent of a type is generated as interface the subtype is generated with a constructor call to the parent interface which doesn't compile:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes(
JsonSubTypes.Type(value = SubtypeA::class, name = "subtypeA"),
JsonSubTypes.Type(value = SubtypeB::class, name = "subtypeB")
)
interface ParentSchema{
val id: kotlin.String
val type: DiscriminatingType
}
data class SubtypeA(
@get:NotNull
@field:JsonProperty("id") override val id: kotlin.String,
@get:NotNull
@field:Valid
@field:JsonProperty("type") override val type: DiscriminatingType,
@field:JsonProperty("subtypeAproperty") val subtypeAproperty: kotlin.Int? = null
) : ParentSchema(){
}
Note: ParentSchema(). The () prevent compilation
openapi-generator version
openapi-generator-maven-plugin:5.0.0
OpenAPI declaration file content or url
Related issues/PRs
Similar: #3587
Suggest a fix
I worked around it by removing the () from dataClass.mustache. This wouldn't work if the parent is a class.
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 dataClass.mustache and the linked sample OpenAPI specification, then generate the Kotlin Spring models to reproduce the ParentSchema interface case. Compare the generated subtype declaration for interface and class parents; done means the interface case no longer emits ParentSchema() and the generated Kotlin compiles without breaking class inheritance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100