/* eslint-disable */ /* Code generated by ng-openapi-gen DO NOT EDIT. */ import { Injectable } from '@angular/core'; import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; import { Observable, firstValueFrom } from 'rxjs'; import { filter, map } from 'rxjs/operators'; import { ApiConfiguration } from './api-configuration'; import { StrictHttpResponse } from './strict-http-response'; export type ApiFnOptional = (http: HttpClient, rootUrl: string, params?: P, context?: HttpContext) => Observable>; export type ApiFnRequired = (http: HttpClient, rootUrl: string, params: P, context?: HttpContext) => Observable>; /** * Helper service to call API functions directly */ @Injectable({ providedIn: 'root' }) export class Api { constructor( private config: ApiConfiguration, private http: HttpClient ) { } private _rootUrl?: string; /** * Returns the root url for API operations. If not set directly here, * will fallback to `ApiConfiguration.rootUrl`. */ get rootUrl(): string { return this._rootUrl || this.config.rootUrl; } /** * Sets the root URL for API operations */ set rootUrl(rootUrl: string) { this._rootUrl = rootUrl; } /** * Executes an API call, returning the response body only */ invoke(fn: ApiFnRequired, params: P, context?: HttpContext): Promise; invoke(fn: ApiFnOptional, params?: P, context?: HttpContext): Promise; async invoke(fn: ApiFnRequired | ApiFnOptional, params: P, context?: HttpContext): Promise { const resp = this.invoke$Response(fn, params, context); return (await resp).body; } /** * Executes an API call, returning the entire response */ invoke$Response(fn: ApiFnRequired, params: P, context?: HttpContext): Promise>; invoke$Response(fn: ApiFnOptional, params?: P, context?: HttpContext): Promise>; invoke$Response(fn: ApiFnRequired | ApiFnOptional, params: P, context?: HttpContext): Promise> { const obs = fn(this.http, this.rootUrl, params, context) .pipe( filter(r => r instanceof HttpResponse), map(r => r as StrictHttpResponse)); return firstValueFrom(obs); } }