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

[typescript-angular] Added support for Angular v6 (by adding support for RxJS v6) #8155

Merged
merged 5 commits into from
May 11, 2018

Conversation

akehir
Copy link
Contributor

@akehir akehir commented May 8, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

Copy link
Contributor

@macjohnny macjohnny left a 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"
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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';
Copy link
Contributor

@macjohnny macjohnny May 9, 2018

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.

Copy link
Contributor Author

@akehir akehir May 9, 2018

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.

Copy link
Contributor

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

Copy link
Contributor Author

@akehir akehir May 9, 2018

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 =(

Copy link
Contributor

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"
Copy link
Contributor

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.7here

@macjohnny
Copy link
Contributor

@@ -52,7 +52,7 @@ In your Angular project:

```
// without configuring providers
import { ApiModule } from '@swagger/angular2-typescript-petstore';
import { ApiModule } from '';
Copy link
Contributor

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?

Copy link
Contributor Author

@akehir akehir May 9, 2018

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

Copy link
Contributor

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';
Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor

@macjohnny macjohnny left a 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

@keradus
Copy link

keradus commented Jun 26, 2018

any chances to have this change release? :)

@degahr
Copy link

degahr commented Aug 2, 2018

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?

@macjohnny
Copy link
Contributor

@degahr these changes are included in the latest release of https://github.com/openapitools/openapi-generator

@rainmanhhh
Copy link

how to pass useRxJS6 flag to the template? config-help doesn't show it

@keradus
Copy link

keradus commented Sep 22, 2018

java -jar openapi-generator-cli.jar generate -i swagger.json -l typescript-angular --additional-properties ngVersion=6

@rainmanhhh
Copy link

java -jar openapi-generator-cli.jar generate -i swagger.json -l typescript-angular --additional-properties ngVersion=6

doesn't work, both 2.3.1 and 3.0.0-rc1 generate
import { Observable } from 'rxjs/Observable';

@keradus
Copy link

keradus commented Sep 22, 2018

switch to openapi, I'm using 3.0.2 and it generates
import { Observable } from 'rxjs';

wget -nc http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.2/openapi-generator-cli-3.0.2.jar -O openapi-generator-cli.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants