Skip to content

[TS][Angular] Updating typescript-angular to export api classes #4589

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

Merged
merged 2 commits into from
Jan 21, 2017
Merged

[TS][Angular] Updating typescript-angular to export api classes #4589

merged 2 commits into from
Jan 21, 2017

Conversation

damienpontifex
Copy link
Contributor

PR checklist

  • Read the contribution guildelines.
  • Ran the shell/batch 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)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

Exporting generated api classes with typescript-angular generator. This removes the namespace wrapping as discussed in #1487

@damienpontifex
Copy link
Contributor Author

damienpontifex commented Jan 18, 2017

@fzakaria this is the discussed change for angularjs exports

@wing328 there is some duplication between the typescript-angular and typescript-angular2 generators now, which could be cleaned up in another PR if this pattern was wanting to be applied to all typescript generators. In that case, this functionality would move into AbstractTypeScriptClientCodegen but didn't want to overload this PR with unnecessary changes when it was focused on providing exports to the generated apis for angularjs.

@wing328
Copy link
Contributor

wing328 commented Jan 18, 2017

@damienpontifex thanks for the PR but the CI (travis) reports the following issue:

[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:exec (npm-test) @ TypeScriptAngularPestoreClientTests ---

> [email protected] test /home/travis/build/swagger-api/swagger-codegen/samples/client/petstore/typescript-angular
> tsc --target ES6 && node client.js

error TS6053: File 'API/Client/Category.ts' not found.
error TS6053: File 'API/Client/Order.ts' not found.
error TS6053: File 'API/Client/Pet.ts' not found.
error TS6053: File 'API/Client/PetApi.ts' not found.
error TS6053: File 'API/Client/StoreApi.ts' not found.
error TS6053: File 'API/Client/Tag.ts' not found.
error TS6053: File 'API/Client/User.ts' not found.
error TS6053: File 'API/Client/UserApi.ts' not found.
error TS6053: File 'API/Client/api.d.ts' not found.
npm ERR! Test failed.  See above for more details.

Ref: https://s3.amazonaws.com/archive.travis-ci.org/jobs/192884966/log.txt

Please take a look when you've time.

@damienpontifex
Copy link
Contributor Author

Thanks @wing328 small update required to the sample client tsconfig source files. Now passing.

@wing328
Copy link
Contributor

wing328 commented Jan 19, 2017

but didn't want to overload this PR with unnecessary changes when it was focused on providing exports to the generated apis for angularjs.

👍 I definitely prefer smaller changes for easier review.

@Vrolijkx can you please review this when you've time?

@@ -0,0 +1,9 @@
import * as api from './api/api';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason why you do the * as api import instead of import {PetApi, StoreApi,...} from './api/api';

We also made this choice at first in angular2 API's but due to problems we needed to change this later on.

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 used this as the angular2 client was doing the similar thing such as https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache#L10

Open to suggestion to change or leave as is.

An explicit import could be made. Out of interest, what were the problems you ran into?

* Do not edit the class manually.
*/

import * as models from '../model/models';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@Vrolijkx
Copy link
Contributor

Look great aligns the angular1 code more with the angular2 code. Maybe in the future, we can have some common code like the models. They are roughly the same between angular1 and angular 2 ;)

@damienpontifex
Copy link
Contributor Author

@Vrolijkx next PR from me would be a move to reducing duplicate code/templates for all typescript generators (maybe just for angular, but potentially for typescript-node also). Thanks for the review and feedback :)

Do you agree that this generated structure could also be applied to the typescript-node generator in the future?

@Vrolijkx
Copy link
Contributor

Certainly, agree they al should use the same models and structure. The only diff between them should be how the API is generated (fetch/Http angular2[observables]/Http angular1[promisses]/node) and their package.json dependencies. But I don't know how breaking this would be on the node side.

@kenisteward
Copy link
Contributor

Is it possible that we could get this merged? I think i need to start from here for #2694

@wing328 wing328 merged commit 1f0ecb5 into swagger-api:master Jan 21, 2017
@wing328
Copy link
Contributor

wing328 commented Jan 21, 2017

PR merged into master. Please pull the latest master to give it a try.

@kenisteward
Copy link
Contributor

Thanks!

@damienpontifex damienpontifex deleted the angularjs-exports branch January 22, 2017 23:50
@fzakaria
Copy link

looks great.
I'll try to run it on my own clients soon/

@wing328 wing328 changed the title Updating typescript-angular to export api classes [TS][Angular] Updating typescript-angular to export api classes Feb 20, 2017
davidgri pushed a commit to davidgri/swagger-codegen that referenced this pull request May 11, 2017
* Updating typescript-angular to export api classes

* Fixing tsconfig for typescript-angular test case
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.

5 participants