openapi-typescript-codegen/src/utils/writeClientSchemas.ts
Ferdi Koomen 5b3348d6f9 - Added axios client
- Added function to escape path and stopped replacement of ":" character in path
2021-10-08 23:34:49 +02:00

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));
}
}