Skip to content

Commit

Permalink
deprecate(sdk-generator): default client api based mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Oct 24, 2024
1 parent b6e6c69 commit 60d3149
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { ApiFetchClient, type BaseApiFetchClientConstructor } from '@ama-sdk/cor

import * as api from '../api';

const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
/**
* Base path for the mock server
*/
export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH});

export interface Api {
Expand All @@ -15,6 +18,10 @@ export interface Api {
{{/apis}}
}

/**
* Mock APIs
* @deprecated use `getMockedApi` with {@link ApiClient} instead, will be removed in v12.
*/
export const myApi: Api = {
{{#noEmptyLines}}{{#trimComma}}{{#apis}}
{{#operations}}
Expand All @@ -23,10 +30,25 @@ export const myApi: Api = {
{{/apis}}{{/trimComma}}{{/noEmptyLines}}
};


/**
* Retrieve mocked SDK Apis
*
* @param config configuration of the Api Client
* @deprecated use `getMockedApi` with {@link ApiClient} instead, will be removed in v12.
*/
export function getMockedApi(config?: string | BaseApiFetchClientConstructor): Api;
/**
* Retrieve mocked SDK Apis
* @param apiClient Api Client instance
* @example Default Mocked API usage
* ```typescript
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from '@my/sdk/spec';
* import { ApiFetchClient } from '@ama-sdk/client-fetch';
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH }));
* ```
*/
export function getMockedApi(apiClient: ApiClient): Api;
/**
* Retrieve mocked SDK Apis
* @param config configuration of the Api Client
*/
export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api {
Expand Down
26 changes: 25 additions & 1 deletion packages/@ama-sdk/showcase-sdk/src/spec/api-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ApiFetchClient, BaseApiFetchClientConstructor } from '@ama-sdk/client-f

import * as api from '../api';

const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
/**
* Base path for the mock server
*/
export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH});

export interface Api {
Expand All @@ -12,13 +15,34 @@ export interface Api {
userApi: api.UserApi;
}

/**
* Mock APIs
* @deprecated use `getMockedApi` with {@link ApiClient} instead, will be removed in v12.
*/
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
* @deprecated use `getMockedApi` with {@link ApiClient} instead, will be removed in v12.
*/
export function getMockedApi(config?: string | BaseApiFetchClientConstructor): Api;
/**
* Retrieve mocked SDK Apis
* @param apiClient Api Client instance
* @example Default Mocked API usage
* ```typescript
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from '@my/sdk/spec';
* import { ApiFetchClient } from '@ama-sdk/client-fetch';
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH }));
* ```
*/
export function getMockedApi(apiClient: ApiClient): Api;
/**
* Retrieve mocked SDK Apis
* @param config configuration of the Api Client
Expand Down

0 comments on commit 60d3149

Please sign in to comment.