-
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 and Packages #1487
Comments
@aersamkull Yes, I think that's one way to do it. Another approach (a bit more difficult) is to import the models in the Api files, e.g. Java/api.mustache#L9 |
I think the import approach is cleaner. However the syntax is different from Java. Is there a way to add Mustache Variables for a specific language? Or to modify them? type Person = ModelNamespace.Person; |
Using the Petstore example, can you please show me what the import statement looks like? |
Sorry, import statements are not an option. They are bound to modules and we should not rely on a module system, I think. Type Aliases could be used like imports in Java: //PetAPI.ts
namespace API.Access {
'use strict';
type Pet = API.Model.Pet; |
Somehow, api.d.ts is always location in API/Client folder and has wrong paths. This had to be fixed as well. I would expect it to be in the "apiPackage"-Folder |
Also we need to apply the same fix to typescript-node as well but I'm not sure which one (type aliases or fully-qualified name) is preferable in typescript-node. |
I personally prefer fully qualified names. Even though it is not very likely, we could produce name collisions with aliases. |
Yes, unit testing is something we need for Typescript Petstore client. I'll create a separate task for tracking that. |
Fix #1487, TypeScript-Angular output path wrong if apiPackage not the…
@aersamkull #1487 merged into master. Please pull the latest and let us know if you still encounter the issue. Thanks @daveholladay for the fix. |
Still an issue. Execute this command in master:
And then run npm install / test in the typescript-angular samples (you should probably delete the api folder before running the above command).
The output references don't look in the subfolders when using namespaces. The api.d.mustache is using classname to render which may not take in to account namespace.
Generates
|
@pixelshaded so the following will work?
|
No. The models exist in a completely different folder from the api if you define a model package (which is ideal since folder structure should match namespacing). They are in api/clients/petstore/models when passing modelPackage=api.clients.petstore.models |
so the following should work, right?
|
this depends. The reference path is the relative path of the file from the api.d.ts. That depends on the apiPackage if one is defined. Based on the command I gave, this would be valid:
But using this command
api.d.ts would need this
The Api classes themselves are always right next to the api.d.ts for the typescript-angular generator, so they won't need anything to be valid. |
Also, the models files include a reference path to the api.d.ts, but they also expect api.d.ts to be in the same folder. Just seems like namespaces that deviate is just not supported atm. |
Whats worse is that the api implementations don't use the fully qualified name of the type either (aka namespace is not included), so even if we resolved the reference issues, we'd still have challenges when trying to compile. |
I was generating an angular-typescript client and just wondering why are we namespacing the TypeScript classes? The TypeScript docs even has a section against Needless Namespacing. It also creates very verbose and maybe difficulties when just doing a simple |
@damienpontifex i'm not even sure how to import the generated client. |
@fzakaria I have run into the same issue. I posted my comment to gather information about providing a potential change/PR to either:
I agree with the 'Needless Namespacing' article and generally just export my classes so would be in favour of that route. |
@damienpontifex i tried to do a PR but couldn't figure out the mustache for getting it to work. |
The angular1 client needs work in the Java generator code to be able to do that. See comparison of TypeScriptAngular2ClientCodegen.java vs TypeScriptAngularClientCodegen.java in which we are able to do this in angular2 Basically more context needs to be passed into the generator to map the |
Let me know and i can test out a PR and give feedback.
I can also review the PR
Farid Zakaria
…On Sun, Jan 8, 2017 at 5:21 PM, Damien Pontifex ***@***.***> wrote:
The angular1 client needs work in the Java generator code to be able to do
that. See comparison of TypeScriptAngular2ClientCodegen.java
<https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java>
vs TypeScriptAngularClientCodegen.java
<https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java>
in which we are able to do this in angular2
Basically more context needs to be passed into the generator to map the
model. prefix for custom types. I had plans to provide a PR to also
update the angular1 client to do this, but haven't quite got to it yet. Or
more favourably to pull that logic into the AbstractTypeScriptClientCodege
n so that all TypeScript generators get this benefit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1487 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAk7jrFS5tGC5ZSVSOmkALlY_iMCE3_gks5rQYuDgaJpZM4GZ9Ic>
.
|
@damienpontifex did you get a chance to make some changes? |
@fzakaria Made some initial changes here damienpontifex/swagger-codegen@53f02fc80d8c32f52b41adb1a760ad7b3b4d5bf3 and will work on the branch 'tsc-consolidate-patterns' Still a bit of work to do, especially around the non-angular typescript generators, but angular2 has maintained all functionality and angular1 has gained the appropriate barrel modules for model and api as I believe is the desired outcome here (see the samples/client/petstore/typescript-angular for generated examples of this in the linked commit above) |
Thanks for the PR from @damienpontifex. Please pull the latest master to give it a try. |
If I use a config file for TypeScript-Angular and I set modelPackage and apiPackage to different values, I get an error. The generated api File does no longer find the models. Maybe we should use absolut Types? Eg,
services.Bla
instead of justBla
?The text was updated successfully, but these errors were encountered: