forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteClientModels.ts
More file actions
27 lines (25 loc) · 1.06 KB
/
Copy pathwriteClientModels.ts
File metadata and controls
27 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { resolve } from 'path';
import type { Model } from '../client/interfaces/Model';
import { HttpClient } from '../HttpClient';
import { writeFile } from './fileSystem';
import { format } from './format';
import { Templates } from './registerHandlebarTemplates';
/**
* Generate Models using the Handlebar template and write to disk.
* @param models Array of Models to write
* @param templates The loaded handlebar templates
* @param outputPath Directory to write the generated files to
* @param httpClient The selected httpClient (fetch, xhr or node)
* @param useUnionTypes Use union types instead of enums
*/
export async function writeClientModels(models: Model[], templates: Templates, outputPath: string, httpClient: HttpClient, useUnionTypes: boolean): Promise<void> {
for (const model of models) {
const file = resolve(outputPath, `${model.name}.ts`);
const templateResult = templates.exports.model({
...model,
httpClient,
useUnionTypes,
});
await writeFile(file, format(templateResult));
}
}