swagger-api / swagger-api/swagger-codegen
[Typescript Angular] Cannot import as module
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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 81b5b78fc2ac27070500667d139870fe63ab0012
Command line used for generation
swagger-codegen generate -i api.yaml -l typescript-angular
Steps to reproduce
- swagger-codegen generate -i api.yaml -l typescript-angular (any API)
- 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
- The namespace keyword should be removed from the generated files.
- The API should just be
export default class SomeApi - Each class should import the necessary model files it needs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reported typescript-angular generation command with any API, then inspect the generated API and model files involved in the import failure. Verify the namespace and export behavior with the TypeScript compiler using the reproduction shown in the issue. Done means the generated client can be imported as a module and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100