-
-
Notifications
You must be signed in to change notification settings - Fork 528
Deduplicate enums #1683
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
Comments
When is this planned? I need this feature, and am willing to try to implement it. |
@phk422 Thank you for implementing this feature! However, I found that it does not work - with this flag openapi-typescript command runs forever (and when the flag is removed it finished very quickly). Here is a minimal reproduction, please take a look: https://stackblitz.com/edit/vitejs-vite-8qzk9p?file=package.json |
The problem with the current implementation is that the name of the enum isn't stable. I initially provided the diff but didn't implement it due to this issue. the issue is if we add a new route that references an enum from the existing routes and the current route is alphabetically above the previous route, the enum name will change and it'll require a new change in our code to change the enum name. Can we add a non-standard prop like |
Thanks for raising! In that case, I’ll keep this ticket open and just use this to track the bug now that the feature exists. |
This is indeed an issue. I suspect it's related to CLI argument parsing. I'll investigate if there's a way to resolve it. You can try placing other optional parameters at the end, like this: openapi-typescript api/schema.yaml -o schema/schema.ts --enum --dedupe-enums This should work correctly. |
What about deduplicating enums sourced from different openapi definitions? |
Description
Hi, when using the
--enum
flag, the same enum gets generated multiple times if it's used multiple times, can we get a new flag or something to not generate duplicate enums when the keys and values of the enum match an existing enum?Proposal
A new flag that dedupes the enums will be useful. Currently, I'm patching the lib and keeping the stringified version of keys-values in a map and checking if it exists then returning instead of creating a new enum. I can create a PR to implement this feature first creating this issue to discuss how we can proceed with the naming and all
Checklist
My diff
The text was updated successfully, but these errors were encountered: