Skip to content

[BUG][Kotlin] Parent class has incorrect collection property type List instead of Set #22696

@Rocker93

Description

@Rocker93
Description

Kotlin generator generates incorrect

openapi-generator version

7.18.0

OpenAPI declaration file content or url

Shortened schemas

{
      "InheritedOption" : {
        "required" : [ "types" ],
        "type" : "object",
        "allOf" : [ {
          "$ref" : "#/components/schemas/BaseOption"
        } ]
      },
      "BaseOption" : {
        "required" : [ "types"],
        "type" : "object",
        "properties" : {
          "types" : {
            "uniqueItems" : true,
            "type" : "array",
            "items" : {
              "$ref" : "#/components/schemas/SomeObject"
            }
          },
    }
}
Generation Details

InheritedOption does not actually override the base type, as it doesn't share the same collection type. It should generate Set in the parent as well. Now it causes compilation failure.

data class InheritedOption(

    @get:JsonProperty("types")
    override val types: kotlin.collections.Set<BaseOption>,
}

@JsonIgnoreProperties(
  value = ["type"], // ignore manually set type, it will be automatically generated by Jackson during serialization
  allowSetters = true // allows the type to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes(
    JsonSubTypes.Type(value = InheritedOption::class, name = "InheritedOption"),
)

interface BaseOption {

    @get:JsonProperty("types")
    val types: kotlin.collections.List<BaseType>
}

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