Skip to content

Commit cde9e0e

Browse files
committed
- Fixed export for isolatedModules
1 parent 1ef4165 commit cde9e0e

10 files changed

+212
-94
lines changed

src/templates/index.hbs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,29 @@ export { OpenAPI } from './core/OpenAPI';
1111
{{#if models}}
1212

1313
{{#each models}}
14-
export { {{{this}}} } from './models/{{{this}}}';
14+
{{#if enum}}
15+
export { {{{name}}} } from './models/{{{name}}}';
16+
{{else if enums}}
17+
export { {{{name}}} } from './models/{{{name}}}';
18+
{{else}}
19+
export type { {{{name}}} } from './models/{{{name}}}';
20+
{{/if}}
1521
{{/each}}
1622
{{/if}}
1723
{{/if}}
1824
{{#if exportSchemas}}
1925
{{#if models}}
2026

2127
{{#each models}}
22-
export { ${{{this}}} } from './schemas/${{{this}}}';
28+
export { ${{{name}}} } from './schemas/${{{name}}}';
2329
{{/each}}
2430
{{/if}}
2531
{{/if}}
2632
{{#if exportServices}}
2733
{{#if services}}
2834

2935
{{#each services}}
30-
export { {{{this}}} } from './services/{{{this}}}';
36+
export { {{{name}}} } from './services/{{{name}}}';
3137
{{/each}}
3238
{{/if}}
3339
{{/if}}

src/utils/getModelNames.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { getModelNames } from './getModelNames';
33

44
describe('getModelNames', () => {
55
it('should return sorted list', () => {
6-
const models: Model[] = [];
7-
models.push({
6+
const john: Model = {
87
export: 'interface',
98
name: 'John',
109
type: 'John',
@@ -21,8 +20,8 @@ describe('getModelNames', () => {
2120
enum: [],
2221
enums: [],
2322
properties: [],
24-
});
25-
models.push({
23+
};
24+
const jane: Model = {
2625
export: 'interface',
2726
name: 'Jane',
2827
type: 'Jane',
@@ -39,8 +38,8 @@ describe('getModelNames', () => {
3938
enum: [],
4039
enums: [],
4140
properties: [],
42-
});
43-
models.push({
41+
};
42+
const doe: Model = {
4443
export: 'interface',
4544
name: 'Doe',
4645
type: 'Doe',
@@ -57,7 +56,8 @@ describe('getModelNames', () => {
5756
enum: [],
5857
enums: [],
5958
properties: [],
60-
});
59+
};
60+
const models: Model[] = [john, jane, doe];
6161

6262
expect(getModelNames([])).toEqual([]);
6363
expect(getModelNames(models)).toEqual(['Doe', 'Jane', 'John']);

src/utils/getServiceNames.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ import { getServiceNames } from './getServiceNames';
33

44
describe('getServiceNames', () => {
55
it('should return sorted list', () => {
6-
const services: Service[] = [];
7-
services.push({
6+
const john: Service = {
87
name: 'John',
98
operations: [],
109
imports: [],
11-
});
12-
services.push({
10+
};
11+
const jane: Service = {
1312
name: 'Jane',
1413
operations: [],
1514
imports: [],
16-
});
17-
services.push({
15+
};
16+
const doe: Service = {
1817
name: 'Doe',
1918
operations: [],
2019
imports: [],
21-
});
20+
};
21+
22+
const services: Service[] = [john, jane, doe];
2223

2324
expect(getServiceNames([])).toEqual([]);
2425
expect(getServiceNames(services)).toEqual(['Doe', 'Jane', 'John']);

src/utils/sortModelsByName.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Model } from '../client/interfaces/Model';
2+
import { sortModelsByName } from './sortModelsByName';
3+
4+
describe('sortModelsByName', () => {
5+
it('should return sorted list', () => {
6+
const john: Model = {
7+
export: 'interface',
8+
name: 'John',
9+
type: 'John',
10+
base: 'John',
11+
template: null,
12+
link: null,
13+
description: null,
14+
isDefinition: true,
15+
isReadOnly: false,
16+
isRequired: false,
17+
isNullable: false,
18+
imports: [],
19+
extends: [],
20+
enum: [],
21+
enums: [],
22+
properties: [],
23+
};
24+
const jane: Model = {
25+
export: 'interface',
26+
name: 'Jane',
27+
type: 'Jane',
28+
base: 'Jane',
29+
template: null,
30+
link: null,
31+
description: null,
32+
isDefinition: true,
33+
isReadOnly: false,
34+
isRequired: false,
35+
isNullable: false,
36+
imports: [],
37+
extends: [],
38+
enum: [],
39+
enums: [],
40+
properties: [],
41+
};
42+
const doe: Model = {
43+
export: 'interface',
44+
name: 'Doe',
45+
type: 'Doe',
46+
base: 'Doe',
47+
template: null,
48+
link: null,
49+
description: null,
50+
isDefinition: true,
51+
isReadOnly: false,
52+
isRequired: false,
53+
isNullable: false,
54+
imports: [],
55+
extends: [],
56+
enum: [],
57+
enums: [],
58+
properties: [],
59+
};
60+
const models: Model[] = [john, jane, doe];
61+
62+
expect(sortModelsByName([])).toEqual([]);
63+
expect(sortModelsByName(models)).toEqual([doe, jane, john]);
64+
});
65+
});

src/utils/sortModelsByName.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Model } from '../client/interfaces/Model';
2+
3+
export function sortModelsByName(models: Model[]): Model[] {
4+
return models.sort((a, b) => {
5+
const nameA = a.name.toLowerCase();
6+
const nameB = b.name.toLowerCase();
7+
return nameA.localeCompare(nameB, 'en');
8+
});
9+
}

src/utils/sortServicesByName.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Service } from '../client/interfaces/Service';
2+
import { sortServicesByName } from './sortServicesByName';
3+
4+
describe('sortServicesByName', () => {
5+
it('should return sorted list', () => {
6+
const john: Service = {
7+
name: 'John',
8+
operations: [],
9+
imports: [],
10+
};
11+
const jane: Service = {
12+
name: 'Jane',
13+
operations: [],
14+
imports: [],
15+
};
16+
const doe: Service = {
17+
name: 'Doe',
18+
operations: [],
19+
imports: [],
20+
};
21+
22+
const services: Service[] = [john, jane, doe];
23+
24+
expect(sortServicesByName([])).toEqual([]);
25+
expect(sortServicesByName(services)).toEqual([doe, jane, john]);
26+
});
27+
});

src/utils/sortServicesByName.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Service } from '../client/interfaces/Service';
2+
3+
export function sortServicesByName(services: Service[]): Service[] {
4+
return services.sort((a, b) => {
5+
const nameA = a.name.toLowerCase();
6+
const nameB = b.name.toLowerCase();
7+
return nameA.localeCompare(nameB, 'en');
8+
});
9+
}

src/utils/writeClientIndex.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as path from 'path';
22

33
import { Client } from '../client/interfaces/Client';
44
import { writeFile } from './fileSystem';
5-
import { getModelNames } from './getModelNames';
6-
import { getServiceNames } from './getServiceNames';
75
import { Templates } from './registerHandlebarTemplates';
6+
import { sortModelsByName } from './sortModelsByName';
7+
import { sortServicesByName } from './sortServicesByName';
88

99
/**
1010
* Generate the OpenAPI client index file using the Handlebar template and write it to disk.
@@ -36,8 +36,8 @@ export async function writeClientIndex(
3636
exportSchemas,
3737
server: client.server,
3838
version: client.version,
39-
models: getModelNames(client.models),
40-
services: getServiceNames(client.services),
39+
models: sortModelsByName(client.models),
40+
services: sortServicesByName(client.services),
4141
})
4242
);
4343
}

0 commit comments

Comments
 (0)