-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ama-sdk-schematics): remove dependencies in mock api generation …
…(include breaking change)
- Loading branch information
Showing
5 changed files
with
26 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,30 @@ | ||
import { ApiClient, isApiClient } from '@ama-sdk/core'; | ||
import { ApiFetchClient, BaseApiFetchClientConstructor } from '@ama-sdk/client-fetch'; | ||
import type { ApiClient } from '@ama-sdk/core'; | ||
|
||
import * as api from '../api'; | ||
|
||
const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2'; | ||
const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH}); | ||
/** Mock Server default base path */ | ||
export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2'; | ||
|
||
export interface Api { | ||
petApi: api.PetApi; | ||
storeApi: api.StoreApi; | ||
userApi: api.UserApi; | ||
} | ||
|
||
export const myApi: Api = { | ||
petApi: new api.PetApi(MOCK_SERVER), | ||
storeApi: new api.StoreApi(MOCK_SERVER), | ||
userApi: new api.UserApi(MOCK_SERVER) | ||
}; | ||
|
||
|
||
/** | ||
* Retrieve mocked SDK Apis | ||
* @param config configuration of the Api Client | ||
* @param apiClient Api Client instance | ||
* @example Default Mocked API usage | ||
* ```typescript | ||
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from '@ama-sdk/showcase-sdk/spec'; | ||
* import { ApiFetchClient } from '@ama-sdk/client-fetch'; | ||
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH })); | ||
* ``` | ||
*/ | ||
export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api { | ||
let apiConfigObj: ApiClient = MOCK_SERVER; | ||
if (typeof config === 'string') { | ||
apiConfigObj = new ApiFetchClient({basePath: config}); | ||
} else if (isApiClient(config)) { | ||
apiConfigObj = config; | ||
} else if (config) { | ||
apiConfigObj = new ApiFetchClient(config); | ||
} | ||
export function getMockedApi(apiClient: ApiClient): Api { | ||
return { | ||
petApi: new api.PetApi(apiConfigObj), | ||
storeApi: new api.StoreApi(apiConfigObj), | ||
userApi: new api.UserApi(apiConfigObj) | ||
petApi: new api.PetApi(apiClient), | ||
storeApi: new api.StoreApi(apiClient), | ||
userApi: new api.UserApi(apiClient) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters