OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-spring] EnumConverterConfiguration fails to generate converter methdod for enum types which start with numerical value
Nobody has claimed this yet.
- 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 `123Example`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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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