00d03656ef
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
/* 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<P, R> = (http: HttpClient, rootUrl: string, params?: P, context?: HttpContext) => Observable<StrictHttpResponse<R>>;
|
|
export type ApiFnRequired<P, R> = (http: HttpClient, rootUrl: string, params: P, context?: HttpContext) => Observable<StrictHttpResponse<R>>;
|
|
|
|
/**
|
|
* 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<P, R>(fn: ApiFnRequired<P, R>, params: P, context?: HttpContext): Promise<R>;
|
|
invoke<P, R>(fn: ApiFnOptional<P, R>, params?: P, context?: HttpContext): Promise<R>;
|
|
async invoke<P, R>(fn: ApiFnRequired<P, R> | ApiFnOptional<P, R>, params: P, context?: HttpContext): Promise<R> {
|
|
const resp = this.invoke$Response(fn, params, context);
|
|
return (await resp).body;
|
|
}
|
|
|
|
/**
|
|
* Executes an API call, returning the entire response
|
|
*/
|
|
invoke$Response<P, R>(fn: ApiFnRequired<P, R>, params: P, context?: HttpContext): Promise<StrictHttpResponse<R>>;
|
|
invoke$Response<P, R>(fn: ApiFnOptional<P, R>, params?: P, context?: HttpContext): Promise<StrictHttpResponse<R>>;
|
|
invoke$Response<P, R>(fn: ApiFnRequired<P, R> | ApiFnOptional<P, R>, params: P, context?: HttpContext): Promise<StrictHttpResponse<R>> {
|
|
const obs = fn(this.http, this.rootUrl, params, context)
|
|
.pipe(
|
|
filter(r => r instanceof HttpResponse),
|
|
map(r => r as StrictHttpResponse<R>));
|
|
return firstValueFrom(obs);
|
|
}
|
|
}
|