From 1df8cac076c95e9ec7b06906cf9456e0a9ba6d09 Mon Sep 17 00:00:00 2001 From: Kilian Panot Date: Wed, 24 Jul 2024 17:25:26 +0900 Subject: [PATCH] fix(apis-manager): allow Api Interface to retrieve and set configs --- packages/@o3r/apis-manager/README.md | 2 +- .../@o3r/apis-manager/src/apis-manager/api-manager.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/@o3r/apis-manager/README.md b/packages/@o3r/apis-manager/README.md index b944a2897e..2e76eadec2 100644 --- a/packages/@o3r/apis-manager/README.md +++ b/packages/@o3r/apis-manager/README.md @@ -182,7 +182,7 @@ class MyClass { } doSomething() { - this.apiManager.setConfiguration(new ApiFetchClient(), ExampleApi); // <- override configuration of Example API + this.apiManager.setConfiguration(new ApiFetchClient(), ExampleApi.apiName); // <- override configuration of Example API const exampleApi = this.apiFactoryService.getApi(ExampleApi, true); // <- retrieve example API with the new configuration (and refresh the cache) } diff --git a/packages/@o3r/apis-manager/src/apis-manager/api-manager.ts b/packages/@o3r/apis-manager/src/apis-manager/api-manager.ts index d31c1ebcae..8c29424b0c 100644 --- a/packages/@o3r/apis-manager/src/apis-manager/api-manager.ts +++ b/packages/@o3r/apis-manager/src/apis-manager/api-manager.ts @@ -1,4 +1,4 @@ -import type { ApiClient } from '@ama-sdk/core'; +import type { Api, ApiClient } from '@ama-sdk/core'; /** * Api manager is responsible to provide an api configuration to a service factory, so that it could instantiate an API @@ -31,8 +31,8 @@ export class ApiManager { * Retrieve a configuration for a specific API * @param api API to get the configuration for */ - public getConfiguration(api?: string): ApiClient { - return api && this.apiConfigurations[api] || this.defaultConfiguration; + public getConfiguration(api?: string | Api): ApiClient { + return api && this.apiConfigurations[typeof api === 'string' ? api : api.apiName] || this.defaultConfiguration; } /** @@ -40,9 +40,9 @@ export class ApiManager { * @param apiClient API configuration to override to the given api * @param api API name to override, the default configuration will be used if not specified */ - public setConfiguration(apiClient: ApiClient, api?: string): void { + public setConfiguration(apiClient: ApiClient, api?: string | Api): void { if (api) { - this.apiConfigurations[api] = apiClient; + this.apiConfigurations[typeof api === 'string' ? api : api.apiName] = apiClient; } else { this.defaultConfiguration = apiClient; }