Skip to content

Commit

Permalink
feat: cleanup deprecated items in api-mock of SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdo-1A committed Jan 28, 2025
1 parent 5154a6b commit 8167696
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 69 deletions.
3 changes: 1 addition & 2 deletions packages/@ama-sdk/core/src/clients/api-fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ export class ApiFetchClient implements ApiClient {
exception = new ResponseJSONParseError(e.message || 'Fail to parse response body', (response && response.status) || 0, body, { apiName, operationId, url, origin });
}

// eslint-disable-next-line no-console -- `console.error` is supposed to be the default value if the `options` argument is not provided, can be removed in Otter v12.
const reviver = getResponseReviver(revivers, response, operationId, { disableFallback: this.options.disableFallback, log: console.error });
const reviver = getResponseReviver(revivers, response, operationId, { disableFallback: this.options.disableFallback });

Check warning on line 187 in packages/@ama-sdk/core/src/clients/api-fetch-client.ts

View check run for this annotation

Codecov / codecov/patch

packages/@ama-sdk/core/src/clients/api-fetch-client.ts#L187

Added line #L187 was not covered by tests
const replyPlugins = this.options.replyPlugins
? this.options.replyPlugins.map((plugin) => plugin.load<T>({
dictionaries: root && root.dictionaries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,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 +28,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
1 change: 0 additions & 1 deletion packages/@o3r-training/showcase-sdk/src/spec/api-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
} from '@ama-sdk/client-fetch';
import {
ApiClient,
isApiClient,
} from '@ama-sdk/core';
import * as api from '../api';

Expand Down
7 changes: 6 additions & 1 deletion packages/@o3r-training/training-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"default": "./structure/src.json"
},
"./structure/spec.json": {
"default": "./structure/src.json"
"default": "./structure/spec.json"
},
".": {
"main": "./cjs/index.js",
Expand Down Expand Up @@ -63,11 +63,15 @@
"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": "~19.0.0",
Expand Down Expand Up @@ -119,6 +123,7 @@
"yaml-eslint-parser": "^1.2.2"
},
"peerDependencies": {
"@ama-sdk/client-fetch": "workspace:^",
"@ama-sdk/core": "workspace:^",
"isomorphic-fetch": "~3.0.0"
},
Expand Down
40 changes: 8 additions & 32 deletions packages/@o3r-training/training-sdk/src/spec/api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type ApiClient, isApiClient } from '@ama-sdk/core';
import { ApiFetchClient, type BaseApiFetchClientConstructor } from '@ama-sdk/core';

import {
ApiFetchClient,
} from '@ama-sdk/client-fetch';
import type {
ApiClient,
} from '@ama-sdk/core';
import * as api from '../api';

/**
Expand All @@ -13,20 +16,6 @@ export interface Api {
dummyApi: api.DummyApi;
}

/**
* Mock APIs
* @deprecated use `getMockedApi` with {@link ApiClient} instead, will be removed in v12.
*/
export const myApi: Api = {
dummyApi: new api.DummyApi(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
Expand All @@ -37,21 +26,8 @@ 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 {
dummyApi: new api.DummyApi(apiConfigObj)
dummyApi: new api.DummyApi(apiClient)
};
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6944,6 +6944,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@o3r-training/training-sdk@workspace:packages/@o3r-training/training-sdk"
dependencies:
"@ama-sdk/client-fetch": "workspace:^"
"@ama-sdk/core": "workspace:^"
"@ama-sdk/schematics": "workspace:^"
"@angular-devkit/core": "npm:~19.0.0"
Expand Down Expand Up @@ -6996,9 +6997,12 @@ __metadata:
typescript-eslint: "npm:~8.21.0"
yaml-eslint-parser: "npm:^1.2.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 8167696

Please sign in to comment.