Skip to content

[BUG] Description #9950

Open
Open
@Deitsch

Description

@Deitsch
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 #1997

Suggest a fix

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

Null: null as ReasonEnum

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions