Skip to content

Commit

Permalink
deprecate(sdk-generator): default client api based mocks (#2336)
Browse files Browse the repository at this point in the history
## Proposed change

<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that is required for this change. -->

deprecate the default client api based mocks in SDK generated mocks

## Related issues

- 🚀 Feature #2117

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
kpanot authored Oct 24, 2024
2 parents b6e6c69 + 60d3149 commit 6be9ef7
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 6be9ef7

Please sign in to comment.