OpenAPITools / OpenAPITools/openapi-generator

[BUG] [kotlin-spring] EnumConverterConfiguration fails to generate converter methdod for enum types which start with numerical value

Open
#22,362 1 comment 1 reaction 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 validated the input using an OpenAPI validator?
  • 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

The issue occurs when the enum converter functions are generated for enum names that starts with digits. Identifiers cannot start with digits in Kotlin so the generator attempts to escape the name but this creates invalid syntax in the function declaration.

openapi-generator version

Introduced in 7.15.0
https://github.com/OpenAPITools/openapi-generator/commit/bfb69388aa3c443fb3e1912ee5da702e6335a86b

OpenAPI declaration file content or url
openapi: 3.1.0
info: 
  version: 1.0.0
  title: Test api
components:
  schemas: 
    123Example:
      type: string
      enum:
        - TESTING
        - TESTING_2
        - TESTING_3

Generates:

class EnumConverterConfiguration {
	@Bean(name=["org.openapitools.configuration.EnumConverterConfiguration`123Example`Converter"])
	fun &#x60;123Example&#x60;Converter(): Converter<Kotlin.String, Model123ExampleDto> {
		return object: Converter<kotlin.String, Model123ExampleDto> {
			override fun convert(source: kotling.String): Model123ExampleDto = Model123ExampleDto.forValue(source)
		}
	}
}
Suggest a fix

Prefix function name with Model if enum name starts with a number, similar to how the model classes are named

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 by locating the kotlin-spring generation logic for EnumConverterConfiguration and reproduce the issue with the provided OpenAPI schema containing the 123Example enum. Confirm the generated Kotlin has a valid converter function declaration and that the generated code compiles.

Written by the indexing model from the issue text.

Assessment

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