OpenAPITools / OpenAPITools/openapi-generator

[BUG] Kotlin generator

Open
#5,600 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Kotlin
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description
  1. In DeviceRenderOptions.kt, We have enum class SdkUiType(val value: kotlin.Array<kotlin.String>) which is probably because of using Handlebars {{ stuff }} instead of {{{ stuff }}}.
  2. In DeviceRenderOptions.kt, Enum class SdkUiType takes in an array instead of a String as an input even though schema specifies strings.
  3. In PaymentMethodsRequest we have val additionalData: AnyOfLessThanAdditionalDataCommonCommaAdditionalData3DSecureGreaterThan? = null which tries to be the representation of anyOf. It's clearly wrong as such class does not even exist and actually generated classes AdditionalDataCommon and AdditionalData3DSecure have no connection in it.
openapi-generator version

4.2.3

OpenAPI declaration file content or url

codegen_failure.yaml.zip

Command line used for generation

openapi-generator generate -Dmodels -g kotlin-server -i codegen_failure.yaml -o /tmp/openapi/kotlin-server/

Steps to reproduce
  1. Run command line generation,
  2. Observe that Kotlin classes are invalid Kotlin.
Related issues/PRs
Suggest a fix
  1. Fix Handlebars templates. I think this is done is some issue that I cannot find.
  2. Take in strings instead of an array.
  3. Ideally the case would be represented in Kotlin as a sealed class AnyOfPaymentMethodsRequestAdditionalData with those subclasses.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached codegen_failure.yaml.zip and run the documented openapi-generator command for kotlin-server. Inspect the generated DeviceRenderOptions.kt and PaymentMethodsRequest, then trace the Handlebars templates producing the escaped enum type, array-valued string enum, and invalid anyOf type. Done means the generated Kotlin classes compile and represent the schema correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, kotlin
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.