Skip to content

[BUG][KOTLIN-SPRING] Constructor call generated for interface supertypes if using inheritance/discriminator #8366

@notizklotz

Description

@notizklotz

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

Sample spec

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions