Skip to content

Commit

Permalink
fix(apis-manager): allow Api Interface to retrieve and set configs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot authored Jul 24, 2024
2 parents 8765cf4 + 1df8cac commit d724bf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@o3r/apis-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions packages/@o3r/apis-manager/src/apis-manager/api-manager.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,18 +31,18 @@ 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;
}

/**
* Set or override API configuration
* @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;
}
Expand Down

0 comments on commit d724bf1

Please sign in to comment.