OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Kotlin] Enum with 'null' case no longer generate valid code
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 provided a full/minimal spec to reproduce the issue?
- 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
Starting from OpenAPI Generator release 7.9.0, a schema with a single enum case named "null" no longer generate compilable code.
The enum class generated do not include the case named:
@JsonClass(generateAdapter = false)
enum class NullValueKO(val value: kotlin.String) {
/**
* Override [toString()] to avoid using the enum variable name as the value, and instead use
* the actual value defined in the API spec file.
*
* This solves a problem when the variable name and its value are different, and ensures that
* the client sends the correct enum values to the server always.
*/
override fun toString(): kotlin.String = value
companion object {
[...]
In 7.8.0 the enum class generated was:
enum class NullValue(val value: kotlin.String) {
@JsonProperty(value = "null")
`null`("null");
/**
* Override [toString()] to avoid using the enum variable name as the value, and instead use
* the actual value defined in the API spec file.
*
* This solves a problem when the variable name and its value are different, and ensures that
* the client sends the correct enum values to the server always.
*/
override fun toString(): kotlin.String = value
[...]
openapi-generator version
This a regression starting from 7.9.0 up to 7.13.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Test NullValue enum case generation
version: 1.0.0
paths:
components:
schemas:
NullValueKO:
type: string
enum:
- Null
nullable: true
NullValueOK:
type: string
enum:
- MyNull
nullable: true
Generation Details
This is the command line used to generate the code:
openapi-generator generate -i input/nullvalue.yaml -g kotlin -a library=retrofit2 -o output/kotlin --skip-validate-spec
Steps to reproduce
Use the provide command line given in "Generation Details" and the yaml from "OpenAPI declaration file content or url"
Related issues/PRs
Suggest a fix
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 with input/nullvalue.yaml and run the documented openapi-generator command using the kotlin generator and retrofit2 library. Compare the generated NullValueKO enum with the 7.8.0 example; done means the enum includes the null case and produces compilable Kotlin code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100