Skip to content

Enum option cannot generate enums if values are not valid property names #1722

Closed
@jekh

Description

@jekh

Description

When there are multiple keys that cannot be represented as properties, the generated enum converts them all to _, which makes it impossible to use those values in the enum.

Name Version
openapi-typescript 7.0.0
Node.js 20
OS + version Linux

Reproduction

A decent example is the Intercom OpenAPI spec: https://github.com/intercom/Intercom-OpenAPI/blob/main/descriptions/2.11/api.intercom.io.yaml

When generating types using:

openapi-typescript ./api.intercom.io.yaml --enum -o ./intercom.d.ts

It results in an enum that looks like this:

export enum Single_filter_search_requestOperator {
    _ = "=",
    _ = "!=",
    IN = "IN",
    NIN = "NIN",
    _ = "<",
    _ = ">",
    _ = "~",
    _ = "!~",
    _ = "^",
    $ = "$"
}

Expected result

Quoted key names if they are not valid javascript properties. For example, something like this:

export enum Single_filter_search_requestOperator {
    "=" = "=",
    "!=" = "!=",
    IN = "IN",
    NIN = "NIN",
    "<" = "<",
    ">" = ">",
    "~" = "~",
    "!~" = "!~",
    "^" = "^",
    $ = "$"
}

Checklist

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!bugSomething isn't workinggood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-tsRelevant to the openapi-typescript library

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions