Skip to content

Commit

Permalink
feat(ama-sdk-schematics): remove dependencies in mock api generation …
Browse files Browse the repository at this point in the history
…(include breaking change)
  • Loading branch information
kpanot committed Nov 29, 2024
1 parent 3a6a2d7 commit f07531a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 51 deletions.
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
5 changes: 0 additions & 5 deletions packages/@o3r-training/showcase-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@
"tslib": "^2.6.2"
},
"peerDependenciesMeta": {
"@ama-sdk/client-fetch": {
"optional": true
},
"isomorphic-fetch": {
"optional": true
}
},
"devDependencies": {
"@ama-sdk/client-fetch": "workspace:^",
"@ama-sdk/core": "workspace:^",
"@ama-sdk/schematics": "workspace:^",
"@angular-devkit/core": "~18.2.0",
Expand Down Expand Up @@ -116,7 +112,6 @@
"typescript-eslint": "~8.12.2"
},
"peerDependencies": {
"@ama-sdk/client-fetch": "workspace:^",
"@ama-sdk/core": "workspace:^",
"isomorphic-fetch": "~3.0.0"
},
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7024,7 +7024,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@o3r-training/showcase-sdk@workspace:packages/@o3r-training/showcase-sdk"
dependencies:
"@ama-sdk/client-fetch": "workspace:^"
"@ama-sdk/core": "workspace:^"
"@ama-sdk/schematics": "workspace:^"
"@angular-devkit/core": "npm:~18.2.0"
Expand Down Expand Up @@ -7075,12 +7074,9 @@ __metadata:
typescript: "npm:~5.5.4"
typescript-eslint: "npm:~8.12.2"
peerDependencies:
"@ama-sdk/client-fetch": "workspace:^"
"@ama-sdk/core": "workspace:^"
isomorphic-fetch: ~3.0.0
peerDependenciesMeta:
"@ama-sdk/client-fetch":
optional: true
isomorphic-fetch:
optional: true
languageName: unknown
Expand Down

0 comments on commit f07531a

Please sign in to comment.