Skip to content

--enum flag doesn't convert empty string enums correctly #2807

Description

@ToadKing

openapi-typescript version

7.13.0

Node.js version

26.1.0

OS + version

Linux

Description

If an enum has an empty string as an expected value, the generated TypeScript enum is invalid code since it tries to assign it to an empty label.

Reproduction

Run openapi-typescript --enum on this file:

{
    "openapi": "3.1.0",
    "info": {
        "title": "Test",
        "summary": "Test",
        "description": "Test",
        "version": "0.1.0",
        "license": {
            "name": "MIT",
            "identifier": "MIT"
        }
    },
    "servers": [
        {
            "url": "https://bexample.com"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "summary": "Test",
                "operationId": "test",
                "security": [
                    {}
                ],
                "parameters": [
                    {
                        "name": "type",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "enum": [
                                "",
                                "foo",
                                "bar"
                            ],
                            "type": "string",
                            "default": "",
                            "title": "Type"
                        }
                    }
                ]
            }
        }
    }
}

Expected result

The enums generated are valid TypeScript. Get this instead:

export enum PathsTestGetParametersQueryType {
     = "",
    foo = "foo",
    bar = "bar"
}

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions