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

feat(ama-sdk-schematics): remove dependencies in mock api generation #2329

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
@@ -1,14 +1,12 @@
{{#apiInfo}}
import { type ApiClient, isApiClient } from '@ama-sdk/core';
import { ApiFetchClient, type BaseApiFetchClientConstructor } from '@ama-sdk/core';
import type { ApiClient } from '@ama-sdk/core';

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

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

export interface Api {
{{#apis}}
Expand All @@ -18,24 +16,6 @@ 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}}
{{#camelize}}{{classname}}{{/camelize}}: new api.{{classname}}(MOCK_SERVER),
{{/operations}}
{{/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
Expand All @@ -46,24 +26,11 @@ export function getMockedApi(config?: string | BaseApiFetchClientConstructor): A
* 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 {
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 {
{{#noEmptyLines}}{{#trimComma}}{{#apis}}
{{#operations}}
{{#camelize}}{{classname}}{{/camelize}}: new api.{{classname}}(apiConfigObj),
{{#camelize}}{{classname}}{{/camelize}}: new api.{{classname}}(apiClient),
{{/operations}}
{{/apis}}{{/trimComma}}{{/noEmptyLines}}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
"peerDependenciesMeta": {
"isomorphic-fetch": {
"optional": true
},
"@ama-sdk/client-fetch": {
"optional": true
}
},
"devDependencies": {
Expand All @@ -80,7 +77,6 @@
"@schematics/angular": "<%= angularVersion %>",
"@commitlint/config-conventional": "<%= versions['@commitlint/config-conventional'] %>",
"@ama-sdk/schematics": "<%= sdkCoreRange %>",
"@ama-sdk/client-fetch": "<%= sdkCoreRange %>",
"@ama-sdk/core": "<%= sdkCoreRange %>",
"@o3r/eslint-config": "<%= sdkCoreRange %>",
"@o3r/eslint-plugin": "<%= sdkCoreRange %>",
Expand Down Expand Up @@ -121,7 +117,6 @@
"@o3r/schematics": "<%= sdkCoreRange %>"
},<% } %>
"peerDependencies": {
"@ama-sdk/client-fetch": "<%= sdkCoreRange %>",
"@ama-sdk/core": "~<%= sdkCoreVersion %>",
"isomorphic-fetch": "<%= versions['isomorphic-fetch'] %>"
},
Expand Down
Loading