Skip to content
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-fetch generated code BaseAPI class doesn't compile #9459

Open
CluEleSsUK opened this issue May 23, 2019 · 8 comments
Open

typescript-fetch generated code BaseAPI class doesn't compile #9459

CluEleSsUK opened this issue May 23, 2019 · 8 comments

Comments

@CluEleSsUK
Copy link

Description

The generated BaseAPI has a non-nullable field Configuration, but it is conditionally assigned in the constructor, resulting in a TS2564 Property 'configuration' has no initializer and is not definitely assigned in the constructor.

Also, in the RequiredError below, the value name has the same issue. It seems to use a semicolon instead of an = symbol

Swagger-codegen version

2.3.1 using version 1.0.44 parser (due to the bundled parser not following refs correctly as has been detailed on another issue)

Swagger declaration file content or url

Any yaml produces it, but here's an abridged version for referenced
If you post the code inline, please wrap it with

swagger: "2.0"
info:
  description: API for VK
  version: "1.0.0"
  title: Blah
tags:
  - name: Miscellaneous
    description: A collection of endpoints for miscellaneous technical tasks

paths:


  '/actuator/health':
    get:
      tags:
        - Miscellaneous
      produces:
        - application/json
      responses:
        200:
          description: Service is health
        503:
          description: Service is unavailable

schemes:
  - http
Command line used for generation

maven plugin

Steps to reproduce

maven install, then try and use a typescript compiler or see the generated output

Related issues/PRs

Nope

Suggest a fix/enhancement

Within the following file: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache,

Either make configuration nullable , or provide a default one.
Change the colon to an equals in RequiredError.

@CluEleSsUK
Copy link
Author

I have raised a PR with my suggested changes here:
#9460

@Fenopiu
Copy link

Fenopiu commented Jul 9, 2019

The problem is still there and even the brew one doesn't compile installing the swagger-codegen v 2.4.6.
It writes some very old Typescript style that is no more supported in TS >= 3 (probable even some TS2 version have the same problem because it is a JS approach more than a TS approach).
Example with the suggested Petstore API:

export class BaseAPI {
    protected configuration: Configuration;

    constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = portableFetch) {
        if (configuration) {
            this.configuration = configuration;
            this.basePath = configuration.basePath || this.basePath;
        }
    }
};

The configuration variable has not always an assignment in the constructor.

export class RequiredError extends Error {
    name: "RequiredError"
    constructor(public field: string, msg?: string) {
        super(msg);
    }
}

The name variable has clearly no instantiation nor assignment.

So the api.ts doesn't compile.

@CluEleSsUK
Copy link
Author

Unfortunately, looking at the top contributors here, none of them seem to be committing this year :( I fear my PR to fix this will not get merged for a while (as it's sat there for a while already!). Any advice as to whom I could tag to get this merged?

@CluEleSsUK
Copy link
Author

@mhardorf @leonyu do either of you guys have merge access? could you possibly take a look?

@akd-io
Copy link

akd-io commented May 14, 2020

I've run into this problem today. Anyone know anything about the status on this?
Do you remember how you solved it, @CluEleSsUK?

@CluEleSsUK
Copy link
Author

Ended up using https://github.com/OpenAPITools/openapi-generator instead, but you could pull my fork and build locally to get it to work

@nathanstitt
Copy link

5.4.0 seems to correct this.

I'd been locked to 5.1.1 due to this bug, but just upgraded to 5.4.0 and was able to compile TS without errors.

@onlyanegg
Copy link

@nathanstitt , are you talking about openapi-generator? Or am I missing something. The latest swagger-codegen seems to be 3.0.34

https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.34

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

5 participants