OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#16,679 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

The generator at:

https://github.com/OpenAPITools/openapi-generator/blob/v6.0.1/modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache

uses a return type of Observable<{}> if returnType is not specified. This conflicts with the Observable<any> return type in the implementation file for the same condition:

https://github.com/OpenAPITools/openapi-generator/blob/v6.0.1/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache

I don't know if this causes any direct problems with the code generated as default, but the difference is surely not deliberate.

This does cause a problem when modifying the apiInterface.mustache to generate abstract class instead of interface. Using abstract class makes it possible to implement patterns such as

https://medium.com/javascript-everyday/config-based-service-implementation-in-angular-ff39ac2a7f04

ie, if generated code is something like

abstract class NewServiceInterface
{
  abstract doThing(): Observable<{}>;
}

class NewService implements NewServiceInterface
{

  doThing(): Observable<any>
  {
    return of([42]);
  }
}

then

    const ns : NewServiceInterface = new NewService();
    ns.doThing().subscribe(response => {
      console.log("RE", response, response.map((v:number) => v*2));
    });

gives this error:

error TS2339: Property 'map' does not exist on type '{}'.

34       console.log("RE", response, response.map((v:number) => v*2));
                                              ~~~

Changing the interface line to

abstract doThing(): Observable<any>;

resolves the issue.

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

Compare the return types in modules/openapi-generator/src/main/resources/typescript-angular/apiInterface.mustache and api.service.mustache when returnType is unspecified. Reproduce the abstract-class example to confirm the type mismatch, then verify that generated TypeScript uses a consistent return type and no longer produces the reported property error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.