OpenAPITools / OpenAPITools/openapi-generator
[BUG] Description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The generator at:
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:
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
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
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