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,11 +1,10 @@
{{#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';

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

export interface Api {
{{#apis}}
Expand All @@ -15,33 +14,21 @@ export interface Api {
{{/apis}}
}

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
* @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(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-otter": "<%= sdkCoreRange %>",
"@o3r/eslint-plugin": "<%= sdkCoreRange %>",
Expand Down Expand Up @@ -120,7 +116,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/@ama-sdk/showcase-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,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 @@ -115,7 +111,6 @@
"typescript": "~5.5.4"
},
"peerDependencies": {
"@ama-sdk/client-fetch": "workspace:^",
"@ama-sdk/core": "workspace:^",
"isomorphic-fetch": "~3.0.0"
},
Expand Down
38 changes: 14 additions & 24 deletions packages/@ama-sdk/showcase-sdk/src/spec/api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import { ApiClient, isApiClient } from '@ama-sdk/core';
import { ApiFetchClient, BaseApiFetchClientConstructor } from '@ama-sdk/client-fetch';
import type { ApiClient } from '@ama-sdk/core';

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

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

export interface Api {
petApi: api.PetApi;
storeApi: api.StoreApi;
userApi: api.UserApi;
}

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
* @param apiClient Api Client instance
* @example Default Mocked API usage
* ```typescript
* import { getMockedApi, MOCK_SERVER_BASE_PATH } from '@ama-sdk/showcase-sdk/spec';
* import { ApiFetchClient } from '@ama-sdk/client-fetch';
* const mocks = getMockedApi(new ApiFetchClient({ basePath: MOCK_SERVER_BASE_PATH }));
* ```
*/
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 {
petApi: new api.PetApi(apiConfigObj),
storeApi: new api.StoreApi(apiConfigObj),
userApi: new api.UserApi(apiConfigObj)
petApi: new api.PetApi(apiClient),
storeApi: new api.StoreApi(apiClient),
userApi: new api.UserApi(apiClient)
};
}
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ama-sdk/showcase-sdk@workspace:packages/@ama-sdk/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 @@ -768,12 +767,9 @@ __metadata:
typedoc: "npm:~0.26.0"
typescript: "npm:~5.5.4"
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
Loading