Skip to content

Generated API service contains uncompilable code when using observables #369

@eliaspr

Description

@eliaspr

A small issue was introduced in the in commit 9b91abe, templates/apiService.handlebars

When using the --promises false flag, the resulting type script code contains a wrongly named variable and cannot be compiled:

  /**
   * Executes an API call, returning the response body only
   */
  invoke<P, R>(fn: ApiFnRequired<P, R>, params: P, context?: HttpContext): Observable<R>;
  invoke<P, R>(fn: ApiFnOptional<P, R>, params?: P, context?: HttpContext): Observable<R>;
  invoke<P, R>(fn: ApiFnRequired<P, R> | ApiFnOptional<P, R>, params: P, context?: HttpContext): Observable<R> {
    const resp = this.invoke$Response(fn, params, context);
    return obs.pipe(map(r => r.body));
  }

This issue could be resolved by the following change in the templates/apiService.handlebars file:

Index: templates/apiService.handlebars
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/templates/apiService.handlebars b/templates/apiService.handlebars
--- a/templates/apiService.handlebars	(revision 4d6307f99679e2e3ad4e089d8c83c21608a40580)
+++ b/templates/apiService.handlebars	(date 1758438620487)
@@ -49,7 +49,7 @@
     {{#if promises}}
     return (await resp).body;
     {{else}}
-    return obs.pipe(map(r => r.body));
+    return resp.pipe(map(r => r.body));
     {{/if}}
   }
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions