forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteClientCore.ts
More file actions
28 lines (26 loc) · 1.39 KB
/
Copy pathwriteClientCore.ts
File metadata and controls
28 lines (26 loc) · 1.39 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
28
import * as path from 'path';
import type { Client } from '../client/interfaces/Client';
import { HttpClient } from '../index';
import { writeFile } from './fileSystem';
import { Templates } from './registerHandlebarTemplates';
/**
* Generate OpenAPI core files, this includes the basic boilerplate code to handle requests.
* @param client Client object, containing, models, schemas and services
* @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 httpClientLibrary Library for httpClient
*/
export async function writeClientCore(client: Client, templates: Templates, outputPath: string, httpClient: HttpClient, httpClientLibrary: string): Promise<void> {
const context = {
httpClient,
httpClientLibrary,
server: client.server,
version: client.version,
};
await writeFile(path.resolve(outputPath, 'OpenAPI.ts'), templates.core.settings(context));
await writeFile(path.resolve(outputPath, 'ApiError.ts'), templates.core.apiError({}));
await writeFile(path.resolve(outputPath, 'ApiRequestOptions.ts'), templates.core.apiRequestOptions({}));
await writeFile(path.resolve(outputPath, 'ApiResult.ts'), templates.core.apiResult({}));
await writeFile(path.resolve(outputPath, 'request.ts'), templates.core.request(context));
}