OpenAPITools / OpenAPITools/openapi-generator

[BUG][KOTLIN] Enum generation not compiling

Open
#14,017 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • 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

When an enum with the same name as the class name that it resides in is generated, the generator produces an output that does not compile.

openapi-generator version

generator version 6.2.1

OpenAPI declaration file content or url

link to the json gist

Generation Details
generatorName: kotlin
outputDir: generated/src/main/kotlin
library: jvm-okhttp4
inputSpec: modules/openapi-generator/src/test/resources/helloWorld.json
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
  serializationLibrary: jackson
  apiSuffix: SafeClient
  enumPropertyNaming: PascalCase
  sortModelPropertiesByRequiredFlag: true
  sortParamsByRequiredFlag: true
  packageName: com.hello.world.generated

Steps to reproduce
  1. Generate the source using the provided generation details and schema above
  2. Navigate to the HelloWorldGreeting.kt file
  3. Notice the compilation error on the enum member variable named helloWorldGreeting
@field:JsonProperty("HelloWorldGreeting")
    val helloWorldGreeting: HelloWorldGreeting.HelloWorldGreeting? = null  // <-- compilation error on qualified enum
  1. removing the class name qualifier works
@field:JsonProperty("HelloWorldGreeting")
    val helloWorldGreeting: HelloWorldGreeting? = null  // <-- no compilation error on non-qualified enum
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/13496

Suggest a fix

Our theory is that there is an issue with the mustache generation template

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

Reproduce the Kotlin generation using the linked schema and the shown generation details, then inspect the generated HelloWorldGreeting.kt and the Java template path in templateDir. Compare the qualified and unqualified enum references and trace how the Kotlin model template renders them. Done means the generated source compiles for this same-name enum case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
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.