From 398b66727a7ab96e6cccbff6d73213a1fec2dcaf Mon Sep 17 00:00:00 2001 From: Rui Nogueira <121642811+QuietNatu@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:46:11 +0100 Subject: [PATCH] fix(angular): add request overloads based on observe property (#1633) --- packages/angular/src/index.ts | 11 ++++++- .../src/api/endpoints/pets/pets.service.ts | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index 4aca4c1e3..0558dfca7 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -27,6 +27,8 @@ const ANGULAR_DEPENDENCIES: GeneratorDependency[] = [ { name: 'HttpHeaders' }, { name: 'HttpParams' }, { name: 'HttpContext' }, + { name: 'HttpResponse', alias: 'AngularHttpResponse' }, // alias to prevent naming conflict with msw + { name: 'HttpEvent' }, ], dependency: '@angular/common/http', }, @@ -212,7 +214,14 @@ const generateImplementation = ( hasSignal: false, }); - return ` ${operationName}(\n ${toObjectString( + const propsDefinition = toObjectString(props, 'definition'); + const overloads = isRequestOptions + ? `${operationName}(\n ${propsDefinition} options?: Omit & { observe?: 'body' }\n ): Observable; + ${operationName}(\n ${propsDefinition} options?: Omit & { observe?: 'response' }\n ): Observable>; + ${operationName}(\n ${propsDefinition} options?: Omit & { observe?: 'events' }\n ): Observable>;` + : ''; + + return ` ${overloads}${operationName}(\n ${toObjectString( props, 'implementation', )} ${ diff --git a/samples/angular-app/src/api/endpoints/pets/pets.service.ts b/samples/angular-app/src/api/endpoints/pets/pets.service.ts index c9689bdaf..a668b2094 100644 --- a/samples/angular-app/src/api/endpoints/pets/pets.service.ts +++ b/samples/angular-app/src/api/endpoints/pets/pets.service.ts @@ -7,8 +7,10 @@ import { HttpClient } from '@angular/common/http'; import type { HttpContext, + HttpEvent, HttpHeaders, HttpParams, + HttpResponse as AngularHttpResponse, } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -51,6 +53,21 @@ export class PetsService { /** * @summary Create a pet */ + createPets( + createPetsBody: CreatePetsBody, + version?: number, + options?: Omit & { observe?: 'body' }, + ): Observable; + createPets( + createPetsBody: CreatePetsBody, + version?: number, + options?: Omit & { observe?: 'response' }, + ): Observable>; + createPets( + createPetsBody: CreatePetsBody, + version?: number, + options?: Omit & { observe?: 'events' }, + ): Observable>; createPets( createPetsBody: CreatePetsBody, version: number = 1, @@ -61,6 +78,21 @@ export class PetsService { /** * @summary Info for a specific pet */ + showPetById( + petId: string, + version?: number, + options?: Omit & { observe?: 'body' }, + ): Observable; + showPetById( + petId: string, + version?: number, + options?: Omit & { observe?: 'response' }, + ): Observable>; + showPetById( + petId: string, + version?: number, + options?: Omit & { observe?: 'events' }, + ): Observable>; showPetById( petId: string, version: number = 1,