Skip to content

Commit 29e5209

Browse files
committed
feat(ama-sdk-schematics): remove dependencies in mock api generation (include breaking change)
1 parent 8559e3d commit 29e5209

File tree

5 files changed

+27
-63
lines changed

5 files changed

+27
-63
lines changed

packages/@ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/src/main/resources/typescriptFetch/spec/api-mock.mustache

+11-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{{#apiInfo}}
2-
import { type ApiClient, isApiClient } from '@ama-sdk/core';
3-
import { ApiFetchClient, type BaseApiFetchClientConstructor } from '@ama-sdk/core';
2+
import type { ApiClient } from '@ama-sdk/core';
43

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

7-
const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
8-
const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH});
6+
/** Mock Server default base path */
7+
export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
98

109
export interface Api {
1110
{{#apis}}
@@ -15,29 +14,17 @@ export interface Api {
1514
{{/apis}}
1615
}
1716

18-
export const myApi: Api = {
19-
{{#noEmptyLines}}{{#trimComma}}{{#apis}}
20-
{{#operations}}
21-
{{#camelize}}{{classname}}{{/camelize}}: new api.{{classname}}(MOCK_SERVER),
22-
{{/operations}}
23-
{{/apis}}{{/trimComma}}{{/noEmptyLines}}
24-
};
25-
26-
2717
/**
2818
* Retrieve mocked SDK Apis
29-
*
30-
* @param config configuration of the Api Client
19+
* @param apiClient Api Client instance
20+
* @example Default Mocked API usage
21+
* ```typescript
22+
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from './api-mock';
23+
* import { ApiFetchClient } from '@ama-sdk/client-fetch';
24+
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH }));
25+
* ```
3126
*/
32-
export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api {
33-
let apiConfigObj: ApiClient = MOCK_SERVER;
34-
if (typeof config === 'string') {
35-
apiConfigObj = new ApiFetchClient({basePath: config});
36-
} else if (isApiClient(config)) {
37-
apiConfigObj = config;
38-
} else if (config) {
39-
apiConfigObj = new ApiFetchClient(config);
40-
}
27+
export function getMockedApi(apiClient: ApiClient): Api {
4128
return {
4229
{{#noEmptyLines}}{{#trimComma}}{{#apis}}
4330
{{#operations}}

packages/@ama-sdk/schematics/schematics/typescript/shell/templates/base/package.json.template

-5
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@
6262
"peerDependenciesMeta": {
6363
"isomorphic-fetch": {
6464
"optional": true
65-
},
66-
"@ama-sdk/client-fetch": {
67-
"optional": true
6865
}
6966
},
7067
"devDependencies": {
@@ -80,7 +77,6 @@
8077
"@schematics/angular": "<%= angularVersion %>",
8178
"@commitlint/config-conventional": "<%= versions['@commitlint/config-conventional'] %>",
8279
"@ama-sdk/schematics": "<%= sdkCoreRange %>",
83-
"@ama-sdk/client-fetch": "<%= sdkCoreRange %>",
8480
"@ama-sdk/core": "<%= sdkCoreRange %>",
8581
"@o3r/eslint-config-otter": "<%= sdkCoreRange %>",
8682
"@o3r/eslint-plugin": "<%= sdkCoreRange %>",
@@ -120,7 +116,6 @@
120116
"@o3r/schematics": "<%= sdkCoreRange %>"
121117
},<% } %>
122118
"peerDependencies": {
123-
"@ama-sdk/client-fetch": "<%= sdkCoreRange %>",
124119
"@ama-sdk/core": "~<%= sdkCoreVersion %>",
125120
"isomorphic-fetch": "<%= versions['isomorphic-fetch'] %>"
126121
},

packages/@ama-sdk/showcase-sdk/package.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,15 @@
5656
},
5757
"dependencies": {
5858
"@swc/helpers": "~0.5.0",
59-
"tslib": "^2.6.2"
59+
"tslib": "^2.6.2",
60+
"@ama-sdk/client-fetch": "0.0.0-placeholder"
6061
},
6162
"peerDependenciesMeta": {
62-
"@ama-sdk/client-fetch": {
63-
"optional": true
64-
},
6563
"isomorphic-fetch": {
6664
"optional": true
6765
}
6866
},
6967
"devDependencies": {
70-
"@ama-sdk/client-fetch": "workspace:^",
7168
"@ama-sdk/core": "workspace:^",
7269
"@ama-sdk/schematics": "workspace:^",
7370
"@angular-devkit/core": "~18.2.0",
@@ -115,7 +112,6 @@
115112
"typescript": "~5.5.4"
116113
},
117114
"peerDependencies": {
118-
"@ama-sdk/client-fetch": "workspace:^",
119115
"@ama-sdk/core": "workspace:^",
120116
"isomorphic-fetch": "~3.0.0"
121117
},
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
import { ApiClient, isApiClient } from '@ama-sdk/core';
2-
import { ApiFetchClient, BaseApiFetchClientConstructor } from '@ama-sdk/client-fetch';
1+
import type { ApiClient } from '@ama-sdk/core';
32

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

6-
const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
7-
const MOCK_SERVER = new ApiFetchClient({basePath: MOCK_SERVER_BASE_PATH});
5+
/** Mock Server default base path */
6+
export const MOCK_SERVER_BASE_PATH = 'http://localhost:10010/v2';
87

98
export interface Api {
109
petApi: api.PetApi;
1110
storeApi: api.StoreApi;
1211
userApi: api.UserApi;
1312
}
1413

15-
export const myApi: Api = {
16-
petApi: new api.PetApi(MOCK_SERVER),
17-
storeApi: new api.StoreApi(MOCK_SERVER),
18-
userApi: new api.UserApi(MOCK_SERVER)
19-
};
20-
21-
2214
/**
2315
* Retrieve mocked SDK Apis
24-
* @param config configuration of the Api Client
16+
* @param apiClient Api Client instance
17+
* @example Default Mocked API usage
18+
* ```typescript
19+
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from './api-mock';
20+
* import { ApiFetchClient } from '@ama-sdk/client-fetch';
21+
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH }));
22+
* ```
2523
*/
26-
export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api {
27-
let apiConfigObj: ApiClient = MOCK_SERVER;
28-
if (typeof config === 'string') {
29-
apiConfigObj = new ApiFetchClient({basePath: config});
30-
} else if (isApiClient(config)) {
31-
apiConfigObj = config;
32-
} else if (config) {
33-
apiConfigObj = new ApiFetchClient(config);
34-
}
24+
export function getMockedApi(apiClient: ApiClient): Api {
3525
return {
36-
petApi: new api.PetApi(apiConfigObj),
37-
storeApi: new api.StoreApi(apiConfigObj),
38-
userApi: new api.UserApi(apiConfigObj)
26+
petApi: new api.PetApi(apiClient),
27+
storeApi: new api.StoreApi(apiClient),
28+
userApi: new api.UserApi(apiClient)
3929
};
4030
}

yarn.lock

-4
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,6 @@ __metadata:
719719
version: 0.0.0-use.local
720720
resolution: "@ama-sdk/showcase-sdk@workspace:packages/@ama-sdk/showcase-sdk"
721721
dependencies:
722-
"@ama-sdk/client-fetch": "workspace:^"
723722
"@ama-sdk/core": "workspace:^"
724723
"@ama-sdk/schematics": "workspace:^"
725724
"@angular-devkit/core": "npm:~18.2.0"
@@ -768,12 +767,9 @@ __metadata:
768767
typedoc: "npm:~0.26.0"
769768
typescript: "npm:~5.5.4"
770769
peerDependencies:
771-
"@ama-sdk/client-fetch": "workspace:^"
772770
"@ama-sdk/core": "workspace:^"
773771
isomorphic-fetch: ~3.0.0
774772
peerDependenciesMeta:
775-
"@ama-sdk/client-fetch":
776-
optional: true
777773
isomorphic-fetch:
778774
optional: true
779775
languageName: unknown

0 commit comments

Comments
 (0)