OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.76k stars 6.56k forks source link

[BUG] For `oneOf` in open api declaration file, Kotlin generator created data class with empty parameter #16422

Open kamal-github opened 1 year ago

kamal-github commented 1 year ago

Bug Report Checklist

Description

In case of oneOf in open api declaration file. The generated code is containing data class with empty parameter for Kotlin generator.

import ccs.model.AccountIdByFacilityConfiguration
import ccs.model.AccountIdByServiceConfiguration

import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName
import kotlinx.serialization.Contextual

/**
 * 
 *
 */
@Serializable

data class CarrierContractBaseAccountIdConfigurationAccountIdConfigurations (
 // Must have at least parameter for primary constructor.
)
openapi-generator version

7.0.0

OpenAPI declaration file content or url
account_id_configurations:
  oneOf:
    - type: array
      description: Account Id configurations for delivery.
      items:
        $ref: '#/components/schemas/AccountIdByServiceConfiguration'
    - type: array
      description: Account Id configurations for delivery.
      items:
        $ref: '#/components/schemas/AccountIdByFacilityConfiguration'
Generation Details

./gradlew assemble

Steps to reproduce
Related issues/PRs
Suggest a fix
wing328 commented 1 year ago

I don't think Kotlin supports oenOf yet. Java client generator has better support for oneOf and you can give it a try to see if the oneOf implementation looks to you.

If it does, would you like to contribute a PR to implement oneOf support in the Kotlin client generator?

kamal-github commented 1 year ago

@wing328 @jimschubert Is there any chance or plan that Kotlin generators(esp. with jvm-ktor librabrt) also supports this features in near future? I checked with go, it seem to be working fine.

wing328 commented 1 year ago

Would you or your company like to sponsor the enhancement?

david-kubecka commented 6 months ago

I've run into a similar issue. In my case the input spec is

    BadRequestError_errors:
      type: object
      properties:
        parameters:
          type: object
          additionalProperties:
            oneOf:
            - type: string
              description: The actual value of the parameter.
            - type: array
              description: The array with the collection of parameter values.
              items:
                type: string

and the generated kotlin classes are

data class BadRequestErrorErrors (
    @field:JsonProperty("parameters")
    val parameters: kotlin.collections.Map<kotlin.String, BadRequestErrorErrorsParametersValue>? = null
)

data class BadRequestErrorErrorsParametersValue ()

I've also tried to generate the java classes but they are basically the same, except of course there's no data modifier. So while the generated Java code compiles I wouldn't claim that it's correct because it completely ignores the values of the parameters object.

david-kubecka commented 5 months ago

Note: Digging a little bit deeper I realized that this is in fact a regression because it stopped working (both for Koltin and Java) in 7.0.0 while it worked in 6.6.0.