Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11148
Closed
Open
Issue created Dec 17, 2021 by Administrator@rootContributor

[BUG][KOTLIN] When using fields with reserved kotlin names and type enum, generated code contains "`" instead of backtick

Created by: piotrplazienski

Description

When generating kotlin code using "kotlin-spring" generator, and one of the fields in API specs is string with enum type:

Issue:
  type: object
  properties:
    operator:
      type: string
      enum: [ One, Two ]

generated code contains backtick "`" encoded as HTML entity: `:

@field:JsonProperty("operator") val `operator`: Issue.`Operator`? = null,

Obviously, compiler has issue with that :)

openapi-generator version

5.3.0

Not regresion, I have checked 5.2.0 and 4.3.1 and all suffer from same issue. But 5.3.0 has expanded keyword list and operator and value (which we use) are escaped now. For basic fun keyword it fails the same way in all versions.

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: Issue
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Issue'
components:
  schemas:
    Issue:
      type: object
      properties:
        ok:
          type: string
          enum: [ One, Two ]
        operator:
          type: string
          enum: [ One, Two ]
        fun:
          type: string
          enum: [ One, Two ]
        value:
          type: string
          enum: [ One, Two ]
Command line used for generation

gradle plugin with options:

    configOptions.putAll(mapOf(
        "library" to "spring-boot",
        "serializationLibrary" to "jackson",
        "interfaceOnly" to "true",
        "delegatePattern" to "true",
        "useBeanValidation" to "true",
        "sourceFolder" to "src/main/kotlin",
        "enumPropertyNaming" to "original"
    ))
Steps to reproduce

generate code and open Issue.kt, it will be like:

data class Issue(
    @field:JsonProperty("ok") val ok: Issue.Ok? = null,
    @field:JsonProperty("operator") val `operator`: Issue.`Operator`? = null,
/* snip */
) {
enum class `Operator`(val value: kotlin.String) {
        @JsonProperty("One") One("One"),
        @JsonProperty("Two") Two("Two");
    }
}
Related issues/PRs
Suggest a fix/enhancement
Assignee
Assign to
Time tracking