-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[typescript-angular] Added support for Angular v6 (by adding support for RxJS v6) #8155
Conversation
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.
awesome, thanks for the PR! I was about to implement this as well, but you were way faster ;-)
I added some small notes that are easy to fix.
Remark: The only place where the rxjs operators imported in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache are used is here: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache#L89
And since this line is only used for Angular <4.3
, it should be safe to apply the changes I request.
"zone.js": "^0.7.6", | ||
"typescript": "^2.1.5" | ||
"typescript": "~2.7.2" |
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.
since we are requiring angular cli, constraining to "typescript": "^2.1.5"
should be fine and more flexible, especially when choosing between angular 5 or 6
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.
The problem is, with ^2.1.5, typescript 2.8.3 will be installed during the tests which is not compatible to angular core. I'll change it to >= 2.1.5 < 2.8, would that be more appropriate?
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.
yes, this sounds better
{{/useRxJS6}} | ||
{{#useRxJS6}} | ||
import { Observable } from 'rxjs'; | ||
{{/useRxJS6}} | ||
{{^useHttpClient}} | ||
import '../rxjs-operators'; |
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.
the import '../rxjs-operators';
should be moved inside the {{^useRxJS6}}{{/useRxJS6}}
block, see my general review 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.
Sorry, if I misunderstood, the rxjs-operators is imported in a {{^useHttpClient}} {{/useHttpClient}}
- I (wrongly?) thought, this meant that these imports are only used if angular is older than 4.3, and that after 4.3 they are not imported anymore.
For RxJS 6.1, the operators would need to be imported differently, if they are used - see: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#howto-convert-to-pipe-syntax .
From what I can see, actually, of the operators, throw & catch are not used by the api service, only map is. However I just found out, that at least at one point map is used, which will need to be converted to a .pipe( map( ()=> {}), ) for rxjs 6. Let me update the PR and get back to you.
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.
ah, you are right, I missed that it is in a {{^useHttpClient}}{{/useHttpClient}}
block.
you don't need to convert the .map()
to .pipe(map())
, since it is only used is here: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache#L89
And since this line is only used for Angular <4.3, it should be fine as it is
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.
My bad, I misread. You want to move it to the {{^useRxJS6}}{{/useRxJS6}}
block, which makes sense. I'll update the PR.
The .map is only used in a {{^useHttpClient}} {{/useHttpClient}}
block, so not relevant to angular 6.
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.
actually I think we shouldn't move it to the {{^useRxJS6}}{{/useRxJS6}}
block, since this would also affect Angular >=4.3
and <6
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 moving it, angular 5 test fails =(
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.
yes, that's what I thought would happen. so you can simply ignore the initial review comment that stated
the import '../rxjs-operators'; should be moved inside the {{^useRxJS6}}{{/useRxJS6}} block, see my general review comment.
@@ -34,7 +34,7 @@ | |||
"reflect-metadata": "^0.1.3", | |||
"rxjs": "^5.4.0", | |||
"zone.js": "^0.7.6", | |||
"typescript": "^2.1.5" | |||
"typescript": "~2.7.2" |
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.
this is not good, we should not require typescript 2.7
here
@@ -52,7 +52,7 @@ In your Angular project: | |||
|
|||
``` | |||
// without configuring providers | |||
import { ApiModule } from '@swagger/angular2-typescript-petstore'; | |||
import { ApiModule } from ''; |
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.
why does the package-name disappear here?
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.
I'm not sure about this one, I believe the package name should not disappear - but I was unfortunately not proficient enough to find the root cause of this. This behaviour is probably not caused by my pull request, though.
The same happens, if I run ./bin/typescript-angular-petstore-all.sh
on swagger-codegen/master
. Was it incorrect to generate all angular examples with my updated .mustache
templates?
Notabene, the same happened here: https://github.com/swagger-api/swagger-codegen/pull/8102/files#diff-ad35a6b2374dd58b5781c610802426c4
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.
@akehir I remember that the package name appears and disappears frequently, so I think it is a problem somewhere else, certainly not cause by your PR. If I generate the samples on Windows, the package name appears. Maybe this is the difference?
@@ -11,8 +11,7 @@ | |||
*/ | |||
import { Headers } from '@angular/http'; | |||
|
|||
import { Observable } from 'rxjs/Observable'; | |||
|
|||
import { Observable } from 'rxjs/Observable'; |
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.
did you re-generate the v2 sample files? this line should not change...
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.
I re-generated by using ./bin/typescript-angular-petstore-all.sh
. The padding was different in the apiInterface.mustache, I just committed a fix.
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.
looks good to me
any chances to have this change release? :) |
Seems that this issue is linked to 2.4.0 ? What is up with this.. Are we going to see progress on this anytime soon? |
@degahr these changes are included in the latest release of https://github.com/openapitools/openapi-generator |
how to pass useRxJS6 flag to the template? config-help doesn't show it |
|
doesn't work, both 2.3.1 and 3.0.0-rc1 generate |
switch to openapi, I'm using 3.0.2 and it generates
|
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if 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.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
Update the .mustache templates for Angular 6 (by checking updating RxJS to v6 where appropriate). Also added test cases for Angular 5 & Angular 6, generated tests for Angular 6.
Travis CI: https://travis-ci.org/akehir/swagger-codegen/builds
@macjohnny