swagger-api / swagger-api/swagger-codegen

[TS Error]: AngularJS + Typescript 3.3 + Swagger TS code generation error while importing

Open
#9,328 0 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 codegen for TS works just fine, however when we import the client lib into our generated TS client libs into our AngularJS, it fails to compile the following files with these errors. The HashMapstring* classes and Mapstringint* files I don't see being used by the actual generated APIs.

bower_components/otr-shared-libs/dist/otr-ts-client/model/HashMapstringobject.ts(15,46): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

bower_components/otr-shared-libs/dist/otr-ts-client/model/HashMapstringstring.ts(15,46): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

bower_components/otr-shared-libs/dist/otr-ts-client/model/MapstringCollectionNotificationEvent.ts(15,63): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

bower_components/otr-shared-libs/dist/otr-ts-client/model/MapstringCollectionNotificationEvent.ts(15,83): error TS2694: Namespace '"/Users/Mark/git/OTRMarketingSite/bower_components/otr-shared-libs/dist/otr-ts-client/model/models"' has no exported member 'Collection'.

bower_components/otr-shared-libs/dist/otr-ts-client/model/Mapstringint.ts(15,39): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

bower_components/otr-shared-libs/dist/otr-ts-client/model/Mapstringint.ts(15,59): error TS2694: Namespace '"/Users/Mark/git/OTRMarketingSite/bower_components/otr-shared-libs/dist/otr-ts-client/model/models"' has no exported member 'ModelInteger'.
bower_components/otr-shared-libs/dist/otr-ts-client/model/Mapstringobject.ts(15,42): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

bower_components/otr-shared-libs/dist/otr-ts-client/model/Mapstringstring.ts(15,42): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments.

Here's how we importing the file in one of your TS files.

import { CaseFinancialsControllerApi } from "../../../../bower_components/otr-shared-libs/dist/otr-ts-client/api/CaseFinancialsControllerApi";
import { PriceMatchRequest } from "../../../../bower_components/otr-shared-libs/dist/otr-ts-client/model/PriceMatchRequest";

Excluding the files in .tsconfig doesn't work obviously because these import statements are bringing in files that are failing to compile

Swagger-codegen version

3.0.5

Swagger declaration file content or url

Swagger JSON file used to generate TS client code. The JSON file should be fine.
https://otr-backend-service-us-devo.offtherecord.com/v2/api-docs

Command line used for generation

swagger-codegen generate -i https://otr-backend-service-us-devo.offtherecord.com/v2/api-docs -l typescript-angular -o /tmp/test/

Steps to reproduce

tsc --project .tsconfig

.tsconfig file

{
"compilerOptions": {
"module": "CommonJS",
"target": "es5",
"experimentalDecorators": true
},
"include": [
"./public/app/"
]
}

Question

Is there a version of TS that supports compilation of this files because perhaps the swagger codegen was generating TS code that was compliant against certain versions of the TS compiler? If not, how do we solve this

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

Reproduce the failure with the documented swagger-codegen command and the supplied Swagger URL, then run tsc --project .tsconfig. Inspect the listed generated model files and their imports; done means the generated TypeScript client compiles with the reported AngularJS and TypeScript 3.3 setup without the TS2499 or TS2694 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
angularjs, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.