- Added output of httpRequest files

This commit is contained in:
Ferdi Koomen 2022-01-25 12:31:24 +01:00
parent 7b4352c48f
commit c6c9d2b879
5 changed files with 19 additions and 7 deletions

View File

@ -1,10 +1,12 @@
{{>header}}
import type { BaseHttpRequest } from './BaseHttpRequest';
import type { ApiRequestOptions } from './ApiRequestOptions';
import { BaseHttpRequest } from './BaseHttpRequest';
import type { CancelablePromise } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';
import { request as __request } from './request';
export class {{HttpRequest}} extends BaseHttpRequest {
export class {{httpRequest}} extends BaseHttpRequest {
constructor(config: OpenAPIConfig) {
super(config);

View File

@ -126,8 +126,8 @@ export function registerHandlebarTemplates(root: {
apiResult: Handlebars.template(templateCoreApiResult),
cancelablePromise: Handlebars.template(templateCancelablePromise),
request: Handlebars.template(templateCoreRequest),
httpRequest: Handlebars.template(templateCoreBaseHttpRequest),
baseHttpRequest: Handlebars.template(templateCoreHttpRequest),
baseHttpRequest: Handlebars.template(templateCoreBaseHttpRequest),
httpRequest: Handlebars.template(templateCoreHttpRequest),
},
};

View File

@ -61,7 +61,7 @@ export async function writeClient(
if (exportCore) {
await rmdir(outputPathCore);
await mkdir(outputPathCore);
await writeClientCore(client, templates, outputPathCore, httpClient, indent, request);
await writeClientCore(client, templates, outputPathCore, httpClient, indent, clientName, request);
}
if (exportServices) {

View File

@ -37,7 +37,7 @@ export async function writeClientClass(
version: client.version,
models: sortModelsByName(client.models),
services: sortServicesByName(client.services),
httpRequest: 'XhrBaseRequest',
httpRequest: 'XHRHttpRequest',
});
await writeFile(resolve(outputPath, 'client.ts'), i(f(templateResult), indent));

View File

@ -3,9 +3,11 @@ import { resolve } from 'path';
import type { Client } from '../client/interfaces/Client';
import { HttpClient } from '../HttpClient';
import { Indent } from '../Indent';
import { copyFile, exists, writeFile } from './fileSystem';
import { copyFile, exists, mkdir, writeFile } from './fileSystem';
import { formatIndentation as i } from './formatIndentation';
import { isDefined } from './isDefined';
import { Templates } from './registerHandlebarTemplates';
import { writeClientClass } from './writeClientClass';
/**
* Generate OpenAPI core files, this includes the basic boilerplate code to handle requests.
@ -22,12 +24,15 @@ export async function writeClientCore(
outputPath: string,
httpClient: HttpClient,
indent: Indent,
clientName?: string,
request?: string
): Promise<void> {
const context = {
httpClient,
clientName,
server: client.server,
version: client.version,
httpRequest: 'XHRHttpRequest',
};
await writeFile(resolve(outputPath, 'OpenAPI.ts'), i(templates.core.settings(context), indent));
@ -37,6 +42,11 @@ export async function writeClientCore(
await writeFile(resolve(outputPath, 'CancelablePromise.ts'), i(templates.core.cancelablePromise(context), indent));
await writeFile(resolve(outputPath, 'request.ts'), i(templates.core.request(context), indent));
if (isDefined(clientName)) {
await writeFile(resolve(outputPath, 'BaseHttpRequest.ts'), i(templates.core.baseHttpRequest(context), indent));
await writeFile(resolve(outputPath, 'XHRHttpRequest.ts'), i(templates.core.httpRequest(context), indent));
}
if (request) {
const requestFile = resolve(process.cwd(), request);
const requestFileExists = await exists(requestFile);