Skip to content

[Typescript Angular] Cannot import as module #4524

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

Open
fzakaria opened this issue Jan 8, 2017 · 2 comments
Open

[Typescript Angular] Cannot import as module #4524

fzakaria opened this issue Jan 8, 2017 · 2 comments

Comments

@fzakaria
Copy link

fzakaria commented Jan 8, 2017

Description

The way in which the generated code is setup, makes it impossible to import the client if you are using a module loader.

Ideally i'd like to do:

import SomeApi from "../API/Client/SomeAPi"

The problem however is that the generated models & API are placed within a namespace that is not exported, so cannot be imported.

Swagger-codegen version

Test on master as of January 8th 2017.
Commit 81b5b78

Command line used for generation

swagger-codegen generate -i api.yaml -l typescript-angular

Steps to reproduce
  1. swagger-codegen generate -i api.yaml -l typescript-angular (any API)
  2. Create a Typescript file and attempt to import it
import SomeApi from "../API/Client/SomeApi"

export class AnotherClass {

   private api : SomeApi;

   constructor(api: SomeApi) {
       this.api = api;
   }
}
3. tsc -p (typescript compiler)
Suggest a Fix
  1. The namespace keyword should be removed from the generated files.
  2. The API should just be export default class SomeApi
  3. Each class should import the necessary model files it needs
@bushuyev
Copy link

bushuyev commented Jan 9, 2017

works when built from master but can't spot what is the difference in the generated code. The namespaces are still where they are but somehow can be compiled.

@fzakaria
Copy link
Author

fzakaria commented Jan 9, 2017

I tried master and couldn't do it.
I think this is a dupe of #1487

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

No branches or pull requests

2 participants