Skip to content

[BUG] Discriminator classes don't implement parent interface (in Kotlin generator) #20260

@c1tru55

Description

@c1tru55

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
openapi-generator version

7.10.0

OpenAPI declaration file content or url
components:
  schemas:
   Car.CommandInput.jsonld-Input:
      oneOf:
        - $ref: '#/components/schemas/DrivingModeSetCommandInput.jsonld-Input'
        - $ref: '#/components/schemas/PowerModeSetCommandInput.jsonld-Input'
        ...
        - $ref: '#/components/schemas/TemperatureDownCommandInput.jsonld-Input'
      discriminator:
        propertyName: command
        mapping:
          driving_mode_set: '#/components/schemas/DrivingModeSetCommandInput.jsonld-Input'
          power_mode_set: '#/components/schemas/PowerModeSetCommandInput.jsonld-Input'
          ...
          temperature_down: '#/components/schemas/TemperatureDownCommandInput.jsonld-Input'
    DrivingModeSetCommandInput.jsonld-Input:
      type: object
      description: ''
      deprecated: false
      required:
        - command
      properties:
        command:
          default: driving_mode_set
          example: driving_mode_set
          type: string
          enum:
            - driving_mode_set
        commandOptions:
          type: object
          properties:
            drivingMode:
              type: string
              enum:
                - eco
                - comfort
                - performance
                - outing
                - snow
                - individual
          additionalProperties: false
          required:
            - drivingMode
    PowerModeSetCommandInput.jsonld-Input:
      type: object
      description: ''
      deprecated: false
      required:
        - command
      properties:
        command:
          default: power_mode_set
          example: power_mode_set
          type: string
          enum:
            - power_mode_set
        commandOptions:
          type: object
          properties:
            powerMode:
              type: string
              enum:
                - intelligent
                - electric
                - fuel
                - save_mode
          additionalProperties: false
          required:
            - powerMode
    ...
    TemperatureDownCommandInput.jsonld-Input:
      type: object
      description: ''
      deprecated: false
      required:
        - command
      properties:
        command:
          default: temperature_down
          example: temperature_down
          type: string
          enum:
            - temperature_down
        commandOptions:
          type: object
          properties:
            step:
              type: number
              format: float
              minimum: 1
              maximum: 14
              multipleOf: 0.5
          additionalProperties: false
          required:
            - step
          default:
            step: 1
          example:
            step: 1
Generation Details
# tried with and without --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true
openapi-generator-cli generate -i openapi.json -g kotlin -c config.yaml --global-property apiTests=false,apiDocs=false,modelTests=false,modelDocs=false -o output
# config.yaml
additionalProperties:
  library: multiplatform
  dateLibrary: kotlinx-datetime
  sourceFolder: src/main/kotlin
  useCoroutines: true
Steps to reproduce

command above generates parent interface + children data classes, but it doesn't implements this interface. also for some reasons parent interface has some default values from its last child (see commends in code below):

// CarCommandInputjsonldInput.kt
/**
 *                                                       // <---why do these empy lines needed?
 *
 * @param command 
 * @param commandOptions 
 */
                                                         // <---why do these empy lines needed?

interface CarCommandInputjsonldInput {

    @SerialName(value = "command") @Required val command: CarCommandInputjsonldInput.Command
    @SerialName(value = "commandOptions") val commandOptions: TemperatureDownCommandInputJsonldInputCommandOptions? // <----- why last child type is used here???
    /**
     *                                                   // <---why do these empy lines needed?
     *
     * Values: temperature_down
     */
    @Serializable
    enum class Command(val value: kotlin.String) {
        @SerialName(value = "temperature_down") temperature_down("temperature_down"); // <----- why last child type is used here???
    }

}


// DrivingModeSetCommandInputjsonldInput.kt
/**
 * 
 *
 * @param command 
 * @param commandOptions 
 */
@Serializable

data class DrivingModeSetCommandInputjsonldInput (

    @SerialName(value = "command") @Required val command: DrivingModeSetCommandInputjsonldInput.Command = Command.driving_mode_set,

    @SerialName(value = "commandOptions") val commandOptions: DrivingModeSetCommandInputJsonldInputCommandOptions? = null

) {

    /**
     * 
     *
     * Values: driving_mode_set
     */
    @Serializable
    enum class Command(val value: kotlin.String) {
        @SerialName(value = "driving_mode_set") driving_mode_set("driving_mode_set");
    }

}


// PowerModeSetCommandInputjsonldInput.kt
/**
 * 
 *
 * @param command 
 * @param commandOptions 
 */
@Serializable

data class PowerModeSetCommandInputjsonldInput (

    @SerialName(value = "command") @Required val command: PowerModeSetCommandInputjsonldInput.Command = Command.power_mode_set,

    @SerialName(value = "commandOptions") val commandOptions: PowerModeSetCommandInputJsonldInputCommandOptions? = null

) {

    /**
     * 
     *
     * Values: power_mode_set
     */
    @Serializable
    enum class Command(val value: kotlin.String) {
        @SerialName(value = "power_mode_set") power_mode_set("power_mode_set");
    }

}
Related issues/PRs

#19928

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions