openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][KOTLIN] Override is missing when parent entity has enum

Open ivanvasheka-intellias opened this issue 2 years ago • 1 comments

Description

When generating polymorphic entities using OAS 3.0, child entities do not add the override keyword to the enum that is present in both, parent and child entities.

openapi-generator version

6.3.0

Generation Details

Consider having a structure like this:

{
  "openapi": "3.0.1",
  "components": {
    "schemas": {
      "ChildA": {
        "required": [
          "enum"
        ],
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/Parent"
          },
          {
            "type": "object",
            "properties": {
              "enum": {
                "$ref": "#/components/schemas/Enum",
                "default": "ChildA"
              }
            }
          }
        ]
      },
      "Parent": {
        "required": [
          "enum"
        ],
        "type": "object",
        "properties": {
          "enum": {
            "$ref": "#/components/schemas/Enum"
          },
          "discriminator": {
            "propertyName": "enum",
            "mapping": {
              "ChildA": "#/components/schemas/ChildA",
              "ChildB": "#/components/schemas/ChildB"
            }
          }
        },
        "Enum": {
          "enum": [
            "ChildA",
            "ChildB"
          ],
          "type": "string"
        }
      }
    }
  }
}

After generation we got these models:

data class ChildA (

    @Json(name = "enum")
    val enum: Enum? = null,

    @Json(name = "parentProperty")
    override val parentProperty: ParentProperty? = null

) : Parent

The enum field must have override keyword, like other parent properties have. And enum property must have default value set like this: override val enum: Enum? = Enum.ChildA,

ivanvasheka-intellias avatar Apr 07 '23 11:04 ivanvasheka-intellias

Is there any upgrades?

Slava96 avatar May 30 '25 10:05 Slava96