Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 of 6 tasks
c1tru55 opened this issue Dec 5, 2024 · 0 comments
Open
4 of 6 tasks

Comments

@c1tru55
Copy link

c1tru55 commented Dec 5, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant