mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
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 Schemas 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, node or axios)
|
|
* @param useUnionTypes Use union types instead of enums
|
|
*/
|
|
export async function writeClientSchemas(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.schema({
|
|
...model,
|
|
httpClient,
|
|
useUnionTypes,
|
|
});
|
|
await writeFile(file, format(templateResult));
|
|
}
|
|
}
|