Skip to content

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

@natto-code

Description

@natto-code

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
bfb6938

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions