Skip to content

Commit b2d8096

Browse files
committed
- Added e2e test
- Cleanup of new export client logic
1 parent 5f58982 commit b2d8096

16 files changed

+1007
-301
lines changed

jest.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const config: Config.InitialOptions = {
2525
'<rootDir>/test/e2e/v3.node.spec.ts',
2626
'<rootDir>/test/e2e/v3.axios.spec.ts',
2727
'<rootDir>/test/e2e/v3.babel.spec.ts',
28+
'<rootDir>/test/e2e/client.fetch.spec.ts',
29+
'<rootDir>/test/e2e/client.xhr.spec.ts',
30+
'<rootDir>/test/e2e/client.node.spec.ts',
31+
'<rootDir>/test/e2e/client.axios.spec.ts',
32+
'<rootDir>/test/e2e/client.babel.spec.ts',
2833
],
2934
},
3035
],

src/openApi/v2/parser/getServices.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ describe('getServices', () => {
2626
});
2727

2828
expect(services).toHaveLength(1);
29-
expect(services[0].name).toEqual('');
29+
expect(services[0].name).toEqual('Default');
3030
});
3131
});

src/openApi/v3/parser/getServices.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ describe('getServices', () => {
2626
});
2727

2828
expect(services).toHaveLength(1);
29-
expect(services[0].name).toEqual('');
29+
expect(services[0].name).toEqual('Default');
3030
});
3131
});

src/templates/client.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class {{{clientName}}} {
2020

2121
private readonly request: BaseHttpRequest;
2222

23-
constructor(config?: OpenAPIConfig, HttpRequest: HttpRequestConstructor = {{{httpRequest}}}) {
23+
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = {{{httpRequest}}}) {
2424
this.request = new HttpRequest({
2525
BASE: config?.BASE ?? '{{{server}}}',
2626
VERSION: config?.VERSION ?? '{{{version}}}',

src/templates/index.hbs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{{>header}}
2-
{{#if @root.exportCore}}
32

3+
{{#if @root.exportClient}}
4+
export { AppClient } from './client';
5+
{{/if}}
6+
{{#if @root.exportCore}}
47
export { ApiError } from './core/ApiError';
8+
{{#if @root.exportClient}}
9+
export { BaseHttpRequest } from './core/BaseHttpRequest';
10+
{{/if}}
511
export { CancelablePromise, CancelError } from './core/CancelablePromise';
612
export { OpenAPI } from './core/OpenAPI';
713
export type { OpenAPIConfig } from './core/OpenAPI';

src/utils/writeClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export const writeClient = async (
108108
exportServices,
109109
exportModels,
110110
exportSchemas,
111-
postfix
111+
postfix,
112+
clientName
112113
);
113114
}
114115
};

src/utils/writeClientClass.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Client } from '../client/interfaces/Client';
22
import { HttpClient } from '../HttpClient';
33
import { Indent } from '../Indent';
4-
import { mkdir, rmdir, writeFile } from './fileSystem';
4+
import { writeFile } from './fileSystem';
55
import type { Templates } from './registerHandlebarTemplates';
66
import { writeClientClass } from './writeClientClass';
77

@@ -38,8 +38,6 @@ describe('writeClientClass', () => {
3838

3939
await writeClientClass(client, templates, './dist', HttpClient.FETCH, 'AppClient', Indent.SPACE_4, '');
4040

41-
expect(rmdir).toBeCalled();
42-
expect(mkdir).toBeCalled();
4341
expect(writeFile).toBeCalled();
4442
});
4543
});

src/utils/writeClientIndex.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { resolve } from 'path';
22

33
import type { Client } from '../client/interfaces/Client';
44
import { writeFile } from './fileSystem';
5+
import { isDefined } from './isDefined';
56
import { Templates } from './registerHandlebarTemplates';
67
import { sortModelsByName } from './sortModelsByName';
78
import { sortServicesByName } from './sortServicesByName';
@@ -19,6 +20,7 @@ import { sortServicesByName } from './sortServicesByName';
1920
* @param exportModels Generate models
2021
* @param exportSchemas Generate schemas
2122
* @param postfix Service name postfix
23+
* @param clientName Custom client class name
2224
*/
2325
export const writeClientIndex = async (
2426
client: Client,
@@ -29,7 +31,8 @@ export const writeClientIndex = async (
2931
exportServices: boolean,
3032
exportModels: boolean,
3133
exportSchemas: boolean,
32-
postfix: string
34+
postfix: string,
35+
clientName?: string
3336
): Promise<void> => {
3437
const templateResult = templates.index({
3538
exportCore,
@@ -42,6 +45,7 @@ export const writeClientIndex = async (
4245
version: client.version,
4346
models: sortModelsByName(client.models),
4447
services: sortServicesByName(client.services),
48+
exportClient: isDefined(clientName),
4549
});
4650

4751
await writeFile(resolve(outputPath, 'index.ts'), templateResult);

0 commit comments

Comments
 (0)