openapi-typescript-codegen/src/utils/writeClientModels.ts
2020-03-04 11:53:56 +01:00

20 lines
752 B
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { Model } from '../client/interfaces/Model';
import { Templates } from './readHandlebarsTemplates';
import { format } from './format';
/**
* 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.
*/
export function writeClientModels(models: Model[], templates: Templates, outputPath: string): void {
models.forEach(model => {
const file = path.resolve(outputPath, `${model.name}.ts`);
const templateResult = templates.model(model);
fs.writeFileSync(file, format(templateResult));
});
}