-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[BUG] [Typescript] Impossible to use enum options #14569
Comments
Can we please label this issue as breaking change without fallback in v7, @wing328 ? I don't really see the reason for this change though. If you want to use an option, you can just use the string, e.g. "EQ". Typescript will correctly make sure that only allowed options are used and assigning dynamic strings to such literal string unions is also prevented. One advantage of enums is the possibility of runtime checking. When enums with the same values are defined in multiple APIs, string literals can be used in both places, while the material enums cannot. Whether that is a good thing or not depends on the specific use case. We will override the template here, but maybe this should be togglable with a generator argument? |
This seems to be a step backwards. As @bodograumann commented, string union properties are much more idiomatic and nicer to work with in Typescript than string enums. As you can see in this section of the diff from the PR: https://github.com/OpenAPITools/openapi-generator/pull/14663/files#diff-093571dbeb012904d7da944caca6939594eae68044e29bb75b0584146fd02cda
now needs to be written as:
which makes client code much harder to write and work with. This should definitely be an option, and probably off by default :-( |
I came here looking to maybe submit a PR to change enum handling from string enums to string unions in the "typescript-rxjs" generator, because it would make our client much nicer and perhaps many others. I guess I won't attempt that, if you're going in the other direction on this generator. Why are there 11 different "typescript*" generators, and how am I meant to pick between them? They appear to handle union types differently and handle enums differently. |
The "typescript" generator without any suffix is a rewrite and was supposed to replace all the others, but it seems there is not much pressure to actually do that now (@TiFu ?). Regarding the enums I didn't get any feedback on my comment above from the maintainers, but it shouldn't be too hard to introduce a attribute to toggle between literal strings and enum objects. |
Thanks for your reply
An abandoned attempt at https://xkcd.com/927/ ? I can't see any documentation about what each of the 11 is for or why I might choose one over the other. If the "typescript (experimental)" generator is intended as a replacement for all the others, I might have expected it to have a summary of that goal in its docs, along with some discussion of the problems it intends to solve and why the other 10 are unsuitable. As far as I can tell, the primary difference seems intended to be which HTTP client library is bundled by default. However, they do also differ significantly in how they handle "AllOf" combined classes and enums, so I find this situation very frustrating. |
Yeah that reference is kinda apt. If you like I can work with you to bring the literal string enums back. Alternatively I can give you the template override that we are using to get it locally. |
@bodograumann is correct. I had started this a few years back - with the goal of replacing all the code duplication. There even is an issue that documents this: #802 including motivation and the rough architectural plan. With personal stuff taking over more and more of my time (such as a full-time job ;) truly missing the life of a college student haha), progress on this also stopped. Of course it's open source so if anyone feels like adding to this, they can always pick up where I have left off. |
@bodograumann |
That would be greatly appreciated, @ksvirkou-hubspot ! |
#18531 |
Still waiting on the next release. But I think it should be fine :-) |
Bug Report Checklist
Description
I can't use any option of the enum
openapi-generator version
6.2.1
OpenAPI declaration file content or url
Generation Details
generate -i *.json -g typescript -o /dir --skip-validate-spec --additional-properties usePromises=true,supportsES6=true,platform=node
Related issues/PRs
#13509
Suggest a fix
The text was updated successfully, but these errors were encountered: