OpenAPITools / OpenAPITools/openapi-generator
[BUG] kotlin-spring, spring-boot code generator creates invalid enums
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Generated enum case is unusable:
enum class RequiredActions(val value: kotlin.String) {
@JsonProperty("update_user_locale") updateUserLocale("update_user_locale"),
@JsonProperty("CONFIGURE_TOTP") cONFIGURETOTP("CONFIGURE_TOTP"),
@JsonProperty("VERIFY_EMAIL") vERIFYEMAIL("VERIFY_EMAIL"),
@JsonProperty("UPDATE_PASSWORD") uPDATEPASSWORD("UPDATE_PASSWORD"),
@JsonProperty("UPDATE_PROFILE") uPDATEPROFILE("UPDATE_PROFILE")
}
Using RequiredActions.valueOf will of course fail when trying to translate something like CONFIGURE_TOTP to cONFIGURETOTP.
openapi-generator version
6.0.0
OpenAPI declaration file content or url
in an object as property:
requiredActions:
type: array
items:
type: string
enum:
- update_user_locale
- CONFIGURE_TOTP
- VERIFY_EMAIL
- UPDATE_PASSWORD
- UPDATE_PROFILE
Generation Details
openApiGenerate {
// https://openapi-generator.tech/docs/generators/kotlin-spring
generatorName.set("kotlin-spring")
library.set("spring-boot")
inputSpec.set(openAPISpecFile)
outputDir.set("$buildDir/$openAPIGenOutBase")
packageName.set(openAPIBasePackage)
apiPackage.set("$openAPIBasePackage.api")
invokerPackage.set("$openAPIBasePackage.client")
modelPackage.set("$openAPIBasePackage.model")
modelNameSuffix.set("Dto")
typeMappings.set(
mapOf(
"DateTime" to "Instant"
)
)
importMappings.set(
mapOf(
"Instant" to "java.time.Instant"
)
)
configOptions.set(
mapOf(
"useBeanValidation" to "true",
"delegatePattern" to "true",
"useTags" to "true",
"exceptionHandler" to "false",
"gradleBuildFile" to "false",
"reactive" to "false",
"serviceInterface" to "false",
"sortModelPropertiesByRequiredFlag" to "true",
"sortParamsByRequiredFlag" to "true",
"swaggerAnnotations" to "true",
)
)
}
Steps to reproduce
- create simple object containing the property above.
- use kotlin-spring, spring-boot generator to create kotlin code
Suggest a fix
Keep upper/lower case as it is.
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 running the supplied OpenAPI enum and kotlin-spring/spring-boot generation configuration against version 6.0.0. Trace the generator's enum-name handling and verify that generated constants preserve the declared casing, so values such as CONFIGURE_TOTP can be resolved with valueOf.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring-boot
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100