OpenAPITools / OpenAPITools/openapi-generator

[BUG][KOTLIN] Generated enum class name contains "`" instead of backticks when named using reserved kotlin words

Open
#11,839 1 comment 8 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

Description

Generator: "kotlin-spring".
Generated enum class name contains "`" instead of backtick "`" for enums named using reserved kotlin words.

openapi-generator version

5.2.1, 5.3.0, 5.4.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Kotlin Issue
  version: "1.0"
paths:
  /issue:
    get:
      tags:
      - Issue
      responses:
        '200':
          description: Computer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Computer'
components:
  schemas:
    Computer:
      type: object
      properties:
        interface:
          type: string
          description: Computer interface
          example: USB
          enum:
          - USB
          - HDMI
Generation Details

gradle plugin configured as follows (simplified):

tasks.register<GenerateTask>("generateApi") {
    configOptions.put("dateLibrary", "java8")
    configOptions.put("serializationLibrary", "jackson")
    configOptions.put("gradleBuildFile", "false")
    configOptions.put("enumPropertyNaming", "original")
    configOptions.put("interfaceOnly", "true")
    configOptions.put("exceptionHandler", "false")
    configOptions.put("useTags", "true")
}

Steps to reproduce

Generate code and open Computer.kt. Simplified content:

data class Computer(
  @field:JsonProperty("interface") val `interface`: Computer.`Interface`,
) {
  enum class &#x60;Interface&#x60;(val value: kotlin.String) {
  
    @JsonProperty("USB") USB("USB"),  
    @JsonProperty("HDMI") HDMI("HDMI");  
  }
}
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/11148
https://github.com/OpenAPITools/openapi-generator/issues/11304

Suggest a fix

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-spring generation from the OpenAPI declaration in the issue and inspect the generated Computer.kt output. Trace how the reserved property name interface leads to the nested enum name, then verify that the generated enum class uses Kotlin backticks rather than the literal ` text.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.