Skip to content

Commit 03c8902

Browse files
committed
write services/models indices
1 parent b3691fd commit 03c8902

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

src/utils/writeClientCore.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ describe('writeClientCore', () => {
3838
expect(writeFile).toBeCalledWith('/ApiRequestOptions.ts', 'apiRequestOptions');
3939
expect(writeFile).toBeCalledWith('/ApiResult.ts', 'apiResult');
4040
expect(writeFile).toBeCalledWith('/request.ts', 'request');
41+
expect(writeFile).toBeCalledWith('/index.ts', 'index');
4142
});
4243
});

src/utils/writeClientCore.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ export async function writeClientCore(client: Client, templates: Templates, outp
2525
await writeFile(resolve(outputPath, 'ApiRequestOptions.ts'), templates.core.apiRequestOptions({}));
2626
await writeFile(resolve(outputPath, 'ApiResult.ts'), templates.core.apiResult({}));
2727
await writeFile(resolve(outputPath, 'request.ts'), templates.core.request(context));
28+
const indexFile = resolve(outputPath, 'index.ts');
29+
await writeFile(
30+
indexFile,
31+
templates.index({
32+
exportCore: true,
33+
exportServices: false,
34+
exportModels: false,
35+
exportSchemas: false,
36+
corePath: '.',
37+
})
38+
);
2839

2940
if (request) {
3041
const requestFile = resolve(process.cwd(), request);

src/utils/writeClientModels.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ describe('writeClientModels', () => {
4747
await writeClientModels(models, templates, '/', HttpClient.FETCH, false);
4848

4949
expect(writeFile).toBeCalledWith('/MyModel.ts', 'model');
50+
expect(writeFile).toBeCalledWith('/index.ts', 'index');
5051
});
5152
});

src/utils/writeClientModels.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HttpClient } from '../HttpClient';
55
import { writeFile } from './fileSystem';
66
import { format } from './format';
77
import { Templates } from './registerHandlebarTemplates';
8+
import { sortModelsByName } from './sortModelsByName';
89

910
/**
1011
* Generate Models using the Handlebar template and write to disk.
@@ -24,4 +25,17 @@ export async function writeClientModels(models: Model[], templates: Templates, o
2425
});
2526
await writeFile(file, format(templateResult));
2627
}
28+
const indexFile = resolve(outputPath, 'index.ts');
29+
await writeFile(
30+
indexFile,
31+
templates.index({
32+
exportCore: false,
33+
exportServices: false,
34+
exportModels: true,
35+
exportSchemas: false,
36+
useUnionTypes,
37+
models: sortModelsByName(models),
38+
modelsPath: '.',
39+
})
40+
);
2741
}

src/utils/writeClientServices.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { resolve } from 'path';
1+
import { resolve, relative } from 'path';
22

33
import type { Service } from '../client/interfaces/Service';
44
import { HttpClient } from '../HttpClient';
55
import { writeFile } from './fileSystem';
66
import { format } from './format';
77
import { Templates } from './registerHandlebarTemplates';
8+
import { sortServicesByName } from './sortServicesByName';
89

910
const VERSION_TEMPLATE_STRING = 'OpenAPI.VERSION';
1011

@@ -39,4 +40,17 @@ export async function writeClientServices(
3940
});
4041
await writeFile(file, format(templateResult));
4142
}
43+
const indexFile = resolve(outputPath, 'index.ts');
44+
await writeFile(
45+
indexFile,
46+
templates.index({
47+
exportCore: false,
48+
exportServices: true,
49+
exportModels: false,
50+
exportSchemas: false,
51+
useUnionTypes,
52+
services: sortServicesByName(services),
53+
servicesPath: '.',
54+
})
55+
);
4256
}

0 commit comments

Comments
 (0)