Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
jekh opened this issue Jun 23, 2024 · 1 comment
Open
2 tasks
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@jekh
Copy link

jekh commented Jun 23, 2024

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

@jekh jekh added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jun 23, 2024
@drwpow drwpow added PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project labels Jun 24, 2024
@drwpow
Copy link
Contributor

drwpow commented Jun 24, 2024

Great, reproducible example, thank you! This PR would be a great simple fix if someone is able to provide one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

2 participants