OpenAPITools / OpenAPITools/openapi-generator

[REQ] Enable to Set null to enum value

Open
#13,217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Hello. We're using openapi-generator for defining our interface.
We want to allow null to enum values.

animal:
    type: string
    nullable: true
    enum: 
        - "1"
        - "2"
        - null
     x-enum-varnames:
        - "CAT"
        - "DOG"
        - "HORSE"

generated code

enum class Animal(val value: kotlin.String) {
     @JsonProperty("1") CAT("1"),
     @JsonProperty("2") DOG("2"),
     @JsonProperty("null") HORSE("null"),
}

Describe the solution you'd like

we want something like

enum class Animal(val value: kotlin.String) {
     @JsonProperty("1") CAT("1"),
     @JsonProperty("2") DOG("2"),
     @JsonProperty(null) HORSE(null),
}

Describe alternatives you've considered

replace "null" to null by hand...

Additional context

If this feature can be supported, I am eager to make pull request
(however, I'm not sure where to fix by now...)

Thanks.

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 tracing how the OpenAPI schema's nullable enum is represented during Kotlin enum generation. Compare the requested generated Kotlin output with the current handling of the null enum value, then add coverage for the provided Animal schema and verify that the generated annotation and enum value preserve null rather than the string "null".

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.