swagger-api / swagger-api/swagger-codegen

[Typescript Angular] Cannot import as module

Open
#4,524 2 comments 0 reactions 0 assignees View on GitHub

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.