cjbooms / fabrikt

Generates Kotlin Code from OpenApi3 Specifications
Apache License 2.0
152 stars 39 forks source link

enum subtypes don't properly inherit from a defined parent type #293

Open bapatd opened 3 months ago

bapatd commented 3 months ago

We have a set of Enums implementing a common interface. But in the generated code, the Enums are not implementing the interface. Using discriminatorMapping - the type is referenced as an External Property

Sample code - The issue, in this case is Cow and Sheep classes in the client do not implement Animal

@Schema(
    description = "Animals",
    discriminatorProperty = "type",
    discriminatorMapping = [
        DiscriminatorMapping(value = "COW_FARM", schema = Cow::class),
        DiscriminatorMapping(value = "SHEEP_FARM", schema = Sheep::class),
    ],
)
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NONE,
    include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
    property = "type",
)
@JsonSubTypes(
    JsonSubTypes.Type(name = "COW_FARM", value = Cow::class),
    JsonSubTypes.Type(name = "SHEEP_FARM", value = Sheep::class),
)
interface Animal

enum class Cow : Animal {
"Moo";
}

enum class Sheep : Animal {
"Baa";
}

enum class FarmType {
"COW_FARM",
"SHEEP_FARM";
}

interface Farm {
  val type: FarmType
  val animal: Animal
}

class CowFarm : Farm {
   val type : FarmType = FarmType.COW_FARM,
   val animal: Cow 
}

class SheepFarm : Farm {
   val type : FarmType = FarmType.SHEEP_FARM,
   val animal: Sheep
}
cjbooms commented 4 weeks ago

Please provide an example OpenApi3 schema, with expected output vs actual output so we can diagnose and attempt a fix