-
Notifications
You must be signed in to change notification settings - Fork 6k
[Feature][Angular] request param enum as literal unions #7366
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
[Feature][Angular] request param enum as literal unions #7366
Conversation
|
@wing328 could you include this PR in 2.3.1 please? |
|
the code of this PR could also be moved to |
|
@macjohnny i can agree with you there. I also approve of this change. |
|
@kenisteward would you mind reviewing the code? |
|
would anyone of the technical comitee mind please reviewing the code? cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @wing328 @bedag-moo |
|
Nice improvement :-) Might this be beneficial for all typescript generators? If so, the super class AbstractTypeScriptClientCodegen might be a better home for this code. |
|
@bedag-moo this feature could easily be made available to all typescript generators by moving the code to |
|
I think we should be able to find out whether it would be accepted, since their authors are all in the technical committee :-) Personally, I am happy either way, I just thought now we be a good time to decide where we put this code. |
|
Wasn't this already implemented in #6233? Also note, that there was quite a long discussion about literal unions in this PR after it was merged. |
|
@TiFu this is different. #6233 was the typescript code representation of what the enum will be in model code. This PR sets those would be values in the service code instead of things like String so we have strong types for calling service names. Note: in the descirption it shows this becomes so now would throw a compiler error which helps the developer know the server won't accept that value. I think all the clients would benefit from this. My only thing about the code was I believe enum values can't be anything but numbers or string so the check for Date/DateTime shouldn't be needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenisteward ah totally overlooked that. I thought that was already added in the other PR.
PR looks good to me. Just one code style improvement and one question due to the version bump in the samples.
Moving this to all generators would be a good idea.
| */ | ||
| private String numericEnumValuesToEnumTypeUnion(List<Number> values) { | ||
| List<String> stringValues = new ArrayList<>(); | ||
| for (Object value: values) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Style: Change Object to Number? This would make it clearer that it's used for numbers only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TiFu done
| @@ -1 +1 @@ | |||
| 2.3.0 No newline at end of file | |||
| 2.3.1-SNAPSHOT No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because someone forgot to update the samples? Are you sure that your branch is based on current master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenisteward @TiFu the branch is based on the master of some 5 days ago, but I will rebase and generate the code again.
kenisteward
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After doing more in depth review, I think I can confidently say this shouldn't negatively affect the clients if this is put into the base AbstractTypescript class. I would just ask that at least one more on the technical committee confirm with me that moving this up one level won't break other clients.
| @@ -1 +1 @@ | |||
| 2.3.0 No newline at end of file | |||
| 2.3.1-SNAPSHOT No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@kenisteward concerning the allowed types of enums: It seems that So far I found one limitation of the enum implementation: When using without specifying e.g. |
|
there is an issue when generating models with which results in The problem is that should be in order to use the generated enum types instead of directly typing it as a literal union of the allowed values. Somehow this needs to be fixed by allowing to distinguish between model properties and API client request parameters. Anyone's got an idea? |
|
@kenisteward @Vrolijkx @TiFu @sebastianhaas @taxpon |
|
@SamuelBeliveau do you have an idea for the issue described here #7366 (comment) ? |
|
here is my proposal to resolve the issue: I also updated the https://github.com/macjohnny/swagger-codegen/tree/feature/7365-typescript-request-param-enum branch, which should now also work correctly, allowing to have this feature for all typescript clients. what do you guys think about it? |
|
I filed a new PR #7433 for the general implementation of this feature for all TypeScript clients |
|
closing this one in favor of #7433 |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
Allows request params of type enum to be represented as enum in the generated angular client code.
Before:
after:
fixes #7365