[BUG] For `oneOf` in open api declaration file, Kotlin generator created data class with empty parameter
Bug Report Checklist
- [X] Have you provided a full/minimal spec to reproduce the issue?
- [X] Have you validated the input using an OpenAPI validator (example)?
- [X] Have you tested with the latest master to confirm the issue still exists?
- [X] Have you searched for related issues/PRs?
- [X] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
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?
@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.
Would you or your company like to sponsor the enhancement?
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.
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.