OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#9,950 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When generating enums from the swagger definition, null options get turned into string instead of staying plain null. The issue is when i select the null option it actually a string and not null thus i can't send it to the backend w/o setting it to null.

openapi-generator version

5.0.0

OpenAPI declaration file content or url
"reason": {
    "type": "string",
        "enum": [
            "one",
            "two",
            null
        ],
    "nullable": true
}, 
Steps to reproduce

run generator with swagger file containing the enum above
openapi-generator-cli generate -g typescript-angular -o ./openapi --additional-properties disallowAdditionalPropertiesIfNotPresent=false,ngVersion=10.2.4,fileNaming=kebab-case -i

This should produce an enum like

export type ReasonEnum = 'one' | 'two' | 'null';
export const ReasonEnum = {
        One: 'one' as ReasonEnum,
        Two: 'two' as ReasonEnum,
        Null: 'null' as ReasonEnum
};
Related issues/PRs

a similar bug has bin reported back in 2019 https://github.com/OpenAPITools/openapi-generator/issues/1997

Suggest a fix

The produced enum should convert null like (not a string, just plain null)

Null: null as ReasonEnum

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 with the openapi-generator-cli generate entry point using the provided OpenAPI declaration and the typescript-angular generator. Inspect the generated ReasonEnum and trace how the null enum value is rendered; done means the generated type and constant preserve null as a plain null rather than the string 'null'.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.