Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate(sdk-generator): default client api based mocks #2336

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading