mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Shorter writing style for props passed in constructors
- Simplified header creation - Made helper scripts for test more reasable
This commit is contained in:
parent
a6fdd0aded
commit
4637325b0a
@ -8,7 +8,7 @@ Before working on a Pull Request, create an issue explaining what you want to co
|
||||
This ensures that your pull request won't go unnoticed, and that you are not contributing
|
||||
something that is not suitable for the project.
|
||||
|
||||
If you are unfamiliar with Github Pull Requests, please read the following documentation:
|
||||
If you are unfamiliar with GitHub Pull Requests, please read the following documentation:
|
||||
https://help.github.com/articles/using-pull-requests
|
||||
|
||||
**Your Pull Request must:**
|
||||
|
||||
@ -31,6 +31,7 @@ const config: Config.InitialOptions = {
|
||||
'<rootDir>/test/e2e/client.axios.spec.ts',
|
||||
'<rootDir>/test/e2e/client.babel.spec.ts',
|
||||
],
|
||||
testPathIgnorePatterns: ['<rootDir>/test/e2e/generated'],
|
||||
},
|
||||
],
|
||||
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!<rootDir>/src/**/*.d.ts', '!<rootDir>/bin', '!<rootDir>/dist'],
|
||||
|
||||
@ -6,11 +6,7 @@ import type { OpenAPIConfig } from './OpenAPI';
|
||||
|
||||
export class BaseHttpRequest {
|
||||
|
||||
protected readonly config: OpenAPIConfig;
|
||||
|
||||
constructor(config: OpenAPIConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
constructor(protected readonly config: OpenAPIConfig) {}
|
||||
|
||||
public request<T>(options: ApiRequestOptions): CancelablePromise<T> {
|
||||
throw new Error('Not Implemented');
|
||||
|
||||
@ -74,7 +74,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options, formData);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(config, options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel);
|
||||
const responseBody = getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
@ -95,4 +95,3 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
const sendRequest = async (
|
||||
const sendRequest = async <T>(
|
||||
config: OpenAPIConfig,
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
formData: FormData | undefined,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
headers: Record<string, string>,
|
||||
onCancel: OnCancel
|
||||
): Promise<AxiosResponse<any>> => {
|
||||
): Promise<AxiosResponse<T>> => {
|
||||
const source = axios.CancelToken.source();
|
||||
|
||||
const requestConfig: AxiosRequestConfig = {
|
||||
|
||||
@ -4,7 +4,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
const password = await resolve(options, config.PASSWORD);
|
||||
const additionalHeaders = await resolve(options, config.HEADERS);
|
||||
|
||||
const defaultHeaders = Object.entries({
|
||||
const headers = Object.entries({
|
||||
Accept: 'application/json',
|
||||
...additionalHeaders,
|
||||
...options.headers,
|
||||
@ -15,28 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
[key]: String(value),
|
||||
}), {} as Record<string, string>);
|
||||
|
||||
const headers = new Headers(defaultHeaders);
|
||||
|
||||
if (isStringWithValue(token)) {
|
||||
headers.append('Authorization', `Bearer ${token}`);
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
||||
const credentials = base64(`${username}:${password}`);
|
||||
headers.append('Authorization', `Basic ${credentials}`);
|
||||
headers['Authorization'] = `Basic ${credentials}`;
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
headers['Content-Type'] = options.mediaType;
|
||||
} else if (isBlob(options.body)) {
|
||||
headers.append('Content-Type', options.body.type || 'application/octet-stream');
|
||||
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
headers['Content-Type'] = 'text/plain';
|
||||
} else if (!isFormData(options.body)) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
|
||||
return headers;
|
||||
return new Headers(headers);
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const getRequestBody = (options: ApiRequestOptions): BodyInit | undefined => {
|
||||
const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
if (options.body) {
|
||||
if (options.mediaType?.includes('/json')) {
|
||||
return JSON.stringify(options.body)
|
||||
|
||||
@ -71,7 +71,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(config, options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
||||
const responseBody = await getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ export const sendRequest = async (
|
||||
config: OpenAPIConfig,
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
body: BodyInit | undefined,
|
||||
headers: Headers,
|
||||
onCancel: OnCancel
|
||||
): Promise<Response> => {
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
||||
const encoder = config.ENCODE_PATH || encodeURI;
|
||||
const encoder = config.ENCODE_PATH || encodeURI;
|
||||
|
||||
const path = options.url
|
||||
.replace('{api-version}', config.VERSION)
|
||||
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
||||
if (options.path?.hasOwnProperty(group)) {
|
||||
return encoder(String(options.path[group]));
|
||||
}
|
||||
return substring;
|
||||
});
|
||||
const path = options.url
|
||||
.replace('{api-version}', config.VERSION)
|
||||
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
||||
if (options.path?.hasOwnProperty(group)) {
|
||||
return encoder(String(options.path[group]));
|
||||
}
|
||||
return substring;
|
||||
});
|
||||
|
||||
const url = `${config.BASE}${path}`;
|
||||
if (options.query) {
|
||||
return `${url}${getQueryString(options.query)}`;
|
||||
}
|
||||
return url;
|
||||
const url = `${config.BASE}${path}`;
|
||||
if (options.query) {
|
||||
return `${url}${getQueryString(options.query)}`;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
const password = await resolve(options, config.PASSWORD);
|
||||
const additionalHeaders = await resolve(options, config.HEADERS);
|
||||
|
||||
const defaultHeaders = Object.entries({
|
||||
const headers = Object.entries({
|
||||
Accept: 'application/json',
|
||||
...additionalHeaders,
|
||||
...options.headers,
|
||||
@ -15,27 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
[key]: String(value),
|
||||
}), {} as Record<string, string>);
|
||||
|
||||
const headers = new Headers(defaultHeaders);
|
||||
|
||||
if (isStringWithValue(token)) {
|
||||
headers.append('Authorization', `Bearer ${token}`);
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
||||
const credentials = base64(`${username}:${password}`);
|
||||
headers.append('Authorization', `Basic ${credentials}`);
|
||||
headers['Authorization'] = `Basic ${credentials}`;
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
headers['Content-Type'] = options.mediaType;
|
||||
} else if (isBlob(options.body)) {
|
||||
headers.append('Content-Type', 'application/octet-stream');
|
||||
headers['Content-Type'] = 'application/octet-stream';
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
headers['Content-Type'] = 'text/plain';
|
||||
} else if (!isFormData(options.body)) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
|
||||
return new Headers(headers);
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const getRequestBody = (options: ApiRequestOptions): BodyInit | undefined => {
|
||||
const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
if (options.body) {
|
||||
if (options.mediaType?.includes('/json')) {
|
||||
return JSON.stringify(options.body)
|
||||
|
||||
@ -75,7 +75,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest(options, url, body, formData, headers, onCancel);
|
||||
const responseBody = await getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
export const sendRequest = async (
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
body: BodyInit | undefined,
|
||||
headers: Headers,
|
||||
onCancel: OnCancel
|
||||
): Promise<Response> => {
|
||||
|
||||
@ -4,7 +4,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
const password = await resolve(options, config.PASSWORD);
|
||||
const additionalHeaders = await resolve(options, config.HEADERS);
|
||||
|
||||
const defaultHeaders = Object.entries({
|
||||
const headers = Object.entries({
|
||||
Accept: 'application/json',
|
||||
...additionalHeaders,
|
||||
...options.headers,
|
||||
@ -15,27 +15,26 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
[key]: String(value),
|
||||
}), {} as Record<string, string>);
|
||||
|
||||
const headers = new Headers(defaultHeaders);
|
||||
|
||||
if (isStringWithValue(token)) {
|
||||
headers.append('Authorization', `Bearer ${token}`);
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
||||
const credentials = base64(`${username}:${password}`);
|
||||
headers.append('Authorization', `Basic ${credentials}`);
|
||||
headers['Authorization'] = `Basic ${credentials}`;
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
headers['Content-Type'] = options.mediaType;
|
||||
} else if (isBlob(options.body)) {
|
||||
headers.append('Content-Type', options.body.type || 'application/octet-stream');
|
||||
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
headers['Content-Type'] = 'text/plain';
|
||||
} else if (!isFormData(options.body)) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
|
||||
return new Headers(headers);
|
||||
};
|
||||
|
||||
@ -74,7 +74,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(config, options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
||||
const responseBody = getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ export const sendRequest = async (
|
||||
config: OpenAPIConfig,
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
formData: FormData | undefined,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
headers: Headers,
|
||||
onCancel: OnCancel
|
||||
): Promise<XMLHttpRequest> => {
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
{{#each imports}}
|
||||
import type { {{{this}}} } from '../models/{{{this}}}';
|
||||
{{/each}}
|
||||
|
||||
{{/if}}
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
{{#if @root.exportClient}}
|
||||
@ -16,9 +17,7 @@ import { request as __request } from '../core/request';
|
||||
export class {{{name}}}{{{@root.postfix}}} {
|
||||
{{#if @root.exportClient}}
|
||||
|
||||
private readonly httpRequest: BaseHttpRequest;
|
||||
|
||||
constructor(httpRequest: BaseHttpRequest) {
|
||||
constructor(private readonly httpRequest: BaseHttpRequest) {
|
||||
this.httpRequest = httpRequest;
|
||||
}
|
||||
{{/if}}
|
||||
@ -49,11 +48,10 @@ export class {{{name}}}{{{@root.postfix}}} {
|
||||
{{#if @root.exportClient}}
|
||||
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
|
||||
return this.httpRequest.request({
|
||||
{{/if}}
|
||||
{{#unless @root.exportClient}}
|
||||
{{else}}
|
||||
public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
|
||||
return __request(OpenAPI, {
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
method: '{{{method}}}',
|
||||
url: '{{{path}}}',
|
||||
{{#if parametersPath}}
|
||||
|
||||
@ -365,7 +365,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
const password = await resolve(options, config.PASSWORD);
|
||||
const additionalHeaders = await resolve(options, config.HEADERS);
|
||||
|
||||
const defaultHeaders = Object.entries({
|
||||
const headers = Object.entries({
|
||||
Accept: 'application/json',
|
||||
...additionalHeaders,
|
||||
...options.headers,
|
||||
@ -376,33 +376,31 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
[key]: String(value),
|
||||
}), {} as Record<string, string>);
|
||||
|
||||
const headers = new Headers(defaultHeaders);
|
||||
|
||||
if (isStringWithValue(token)) {
|
||||
headers.append('Authorization', \`Bearer \${token}\`);
|
||||
headers['Authorization'] = \`Bearer \${token}\`;
|
||||
}
|
||||
|
||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
||||
const credentials = base64(\`\${username}:\${password}\`);
|
||||
headers.append('Authorization', \`Basic \${credentials}\`);
|
||||
headers['Authorization'] = \`Basic \${credentials}\`;
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
headers['Content-Type'] = options.mediaType;
|
||||
} else if (isBlob(options.body)) {
|
||||
headers.append('Content-Type', options.body.type || 'application/octet-stream');
|
||||
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
headers['Content-Type'] = 'text/plain';
|
||||
} else if (!isFormData(options.body)) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
|
||||
return headers;
|
||||
return new Headers(headers);
|
||||
};
|
||||
|
||||
const getRequestBody = (options: ApiRequestOptions): BodyInit | undefined => {
|
||||
const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
if (options.body) {
|
||||
if (options.mediaType?.includes('/json')) {
|
||||
return JSON.stringify(options.body)
|
||||
@ -419,8 +417,8 @@ export const sendRequest = async (
|
||||
config: OpenAPIConfig,
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
body: BodyInit | undefined,
|
||||
headers: Headers,
|
||||
onCancel: OnCancel
|
||||
): Promise<Response> => {
|
||||
@ -509,7 +507,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(config, options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
||||
const responseBody = await getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
@ -2196,6 +2194,7 @@ exports[`v2 should generate: ./test/generated/v2/services/ComplexService.ts 1`]
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -2263,6 +2262,7 @@ exports[`v2 should generate: ./test/generated/v2/services/DefaultsService.ts 1`]
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -2702,6 +2702,7 @@ exports[`v2 should generate: ./test/generated/v2/services/ResponseService.ts 1`]
|
||||
import type { ModelThatExtends } from '../models/ModelThatExtends';
|
||||
import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends';
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -3265,7 +3266,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
const password = await resolve(options, config.PASSWORD);
|
||||
const additionalHeaders = await resolve(options, config.HEADERS);
|
||||
|
||||
const defaultHeaders = Object.entries({
|
||||
const headers = Object.entries({
|
||||
Accept: 'application/json',
|
||||
...additionalHeaders,
|
||||
...options.headers,
|
||||
@ -3276,33 +3277,31 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
|
||||
[key]: String(value),
|
||||
}), {} as Record<string, string>);
|
||||
|
||||
const headers = new Headers(defaultHeaders);
|
||||
|
||||
if (isStringWithValue(token)) {
|
||||
headers.append('Authorization', \`Bearer \${token}\`);
|
||||
headers['Authorization'] = \`Bearer \${token}\`;
|
||||
}
|
||||
|
||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
||||
const credentials = base64(\`\${username}:\${password}\`);
|
||||
headers.append('Authorization', \`Basic \${credentials}\`);
|
||||
headers['Authorization'] = \`Basic \${credentials}\`;
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
headers['Content-Type'] = options.mediaType;
|
||||
} else if (isBlob(options.body)) {
|
||||
headers.append('Content-Type', options.body.type || 'application/octet-stream');
|
||||
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
headers['Content-Type'] = 'text/plain';
|
||||
} else if (!isFormData(options.body)) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
|
||||
return headers;
|
||||
return new Headers(headers);
|
||||
};
|
||||
|
||||
const getRequestBody = (options: ApiRequestOptions): BodyInit | undefined => {
|
||||
const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
if (options.body) {
|
||||
if (options.mediaType?.includes('/json')) {
|
||||
return JSON.stringify(options.body)
|
||||
@ -3319,8 +3318,8 @@ export const sendRequest = async (
|
||||
config: OpenAPIConfig,
|
||||
options: ApiRequestOptions,
|
||||
url: string,
|
||||
body: any,
|
||||
formData: FormData | undefined,
|
||||
body: BodyInit | undefined,
|
||||
headers: Headers,
|
||||
onCancel: OnCancel
|
||||
): Promise<Response> => {
|
||||
@ -3409,7 +3408,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
||||
const headers = await getHeaders(config, options);
|
||||
|
||||
if (!onCancel.isCancelled) {
|
||||
const response = await sendRequest(config, options, url, formData, body, headers, onCancel);
|
||||
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
||||
const responseBody = await getResponseBody(response);
|
||||
const responseHeader = getResponseHeader(response, options.responseHeader);
|
||||
|
||||
@ -5676,6 +5675,7 @@ import type { ModelWithArray } from '../models/ModelWithArray';
|
||||
import type { ModelWithDictionary } from '../models/ModelWithDictionary';
|
||||
import type { ModelWithEnum } from '../models/ModelWithEnum';
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -5776,6 +5776,7 @@ exports[`v3 should generate: ./test/generated/v3/services/DefaultsService.ts 1`]
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -5976,6 +5977,7 @@ exports[`v3 should generate: ./test/generated/v3/services/FormDataService.ts 1`]
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -6039,6 +6041,7 @@ exports[`v3 should generate: ./test/generated/v3/services/MultipartService.ts 1`
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -6206,6 +6209,7 @@ exports[`v3 should generate: ./test/generated/v3/services/ParametersService.ts 1
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -6349,6 +6353,7 @@ exports[`v3 should generate: ./test/generated/v3/services/RequestBodyService.ts
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
@ -6385,6 +6390,7 @@ exports[`v3 should generate: ./test/generated/v3/services/ResponseService.ts 1`]
|
||||
import type { ModelThatExtends } from '../models/ModelThatExtends';
|
||||
import type { ModelThatExtendsExtends } from '../models/ModelThatExtendsExtends';
|
||||
import type { ModelWithString } from '../models/ModelWithString';
|
||||
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { request as __request } from '../core/request';
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('client/axios', 'v3', 'axios', false, false, 'AppClient');
|
||||
cleanup('client/axios');
|
||||
await generateClient('client/axios', 'v3', 'axios', false, false, 'AppClient');
|
||||
compileWithTypescript('client/axios');
|
||||
await server.start('client/axios');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithBabel } from './scripts/compileWithBabel';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.babel', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('client/babel', 'v3', 'fetch', true, true, 'AppClient');
|
||||
await copy('client/babel');
|
||||
cleanup('client/babel');
|
||||
await generateClient('client/babel', 'v3', 'fetch', true, true, 'AppClient');
|
||||
copyAsset('index.html', 'client/babel/index.html');
|
||||
copyAsset('main.ts', 'client/babel/main.ts');
|
||||
compileWithBabel('client/babel');
|
||||
await server.start('client/babel');
|
||||
await browser.start();
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.fetch', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('client/fetch', 'v3', 'fetch', false, false, 'AppClient');
|
||||
await copy('client/fetch');
|
||||
cleanup('client/fetch');
|
||||
await generateClient('client/fetch', 'v3', 'fetch', false, false, 'AppClient');
|
||||
copyAsset('index.html', 'client/fetch/index.html');
|
||||
copyAsset('main.ts', 'client/fetch/main.ts');
|
||||
compileWithTypescript('client/fetch');
|
||||
await server.start('client/fetch');
|
||||
await browser.start();
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('client/node', 'v3', 'node', false, false, 'AppClient');
|
||||
cleanup('client/node');
|
||||
await generateClient('client/node', 'v3', 'node', false, false, 'AppClient');
|
||||
compileWithTypescript('client/node');
|
||||
await server.start('client/node');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.xhr', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('client/xhr', 'v3', 'xhr', false, false, 'AppClient');
|
||||
await copy('client/xhr');
|
||||
cleanup('client/xhr');
|
||||
await generateClient('client/xhr', 'v3', 'xhr', false, false, 'AppClient');
|
||||
copyAsset('index.html', 'client/xhr/index.html');
|
||||
copyAsset('main.ts', 'client/xhr/main.ts');
|
||||
compileWithTypescript('client/xhr');
|
||||
await server.start('client/xhr');
|
||||
await browser.start();
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
} from 'typescript';
|
||||
|
||||
export const compileWithTypescript = (dir: string) => {
|
||||
const baseDir = `./test/e2e/generated/${dir}/`;
|
||||
const cwd = `./test/e2e/generated/${dir}/`;
|
||||
const tsconfig = {
|
||||
compilerOptions: {
|
||||
target: 'es2020',
|
||||
@ -27,8 +27,9 @@ export const compileWithTypescript = (dir: string) => {
|
||||
strict: true,
|
||||
skipLibCheck: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
experimentalDecorators: true,
|
||||
},
|
||||
include: ['./index.ts'],
|
||||
include: ['**/*.ts'],
|
||||
};
|
||||
|
||||
// Compile files to JavaScript (ES6 modules)
|
||||
@ -36,7 +37,7 @@ export const compileWithTypescript = (dir: string) => {
|
||||
const configFileResult = parseJsonConfigFileContent(
|
||||
configFile.config,
|
||||
sys,
|
||||
resolve(process.cwd(), baseDir),
|
||||
resolve(process.cwd(), cwd),
|
||||
undefined,
|
||||
'tsconfig.json'
|
||||
);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import express, { Express } from 'express';
|
||||
import { Server } from 'http';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
|
||||
let _app: Express;
|
||||
let _server: Server;
|
||||
@ -19,11 +20,16 @@ const start = async (dir: string) => {
|
||||
})
|
||||
);
|
||||
|
||||
// When we request the index then we can just return the script loader.
|
||||
// This file is copied from test/e2e/assets/script.js to the output directory
|
||||
// of the specific version and client.
|
||||
_app.use(
|
||||
'/js',
|
||||
express.static(`./test/e2e/generated/${dir}/`, {
|
||||
extensions: ['', 'js'],
|
||||
index: 'index.js',
|
||||
})
|
||||
);
|
||||
|
||||
_app.get('/', (req, res) => {
|
||||
res.send('<script src="js/script.js"></script>');
|
||||
res.sendFile(resolvePath(`./test/e2e/generated/${dir}/index.html`));
|
||||
});
|
||||
|
||||
// Register an 'echo' server for testing error codes. This will just grab the
|
||||
@ -51,7 +57,9 @@ const start = async (dir: string) => {
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
_server = _app.listen(3000, resolve);
|
||||
_server = _app.listen(3000, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v2.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v2/axios', 'v2', 'axios');
|
||||
cleanup('v2/axios');
|
||||
await generateClient('v2/axios', 'v2', 'axios');
|
||||
compileWithTypescript('v2/axios');
|
||||
await server.start('v2/axios');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithBabel } from './scripts/compileWithBabel';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v2.babel', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v2/babel', 'v2', 'fetch', true, true);
|
||||
await copy('v2/babel');
|
||||
cleanup('v2/babel');
|
||||
await generateClient('v2/babel', 'v2', 'fetch', true, true);
|
||||
copyAsset('index.html', 'v2/babel/index.html');
|
||||
copyAsset('main.ts', 'v2/babel/main.ts');
|
||||
compileWithBabel('v2/babel');
|
||||
await server.start('v2/babel');
|
||||
await browser.start();
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v2.fetch', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v2/fetch', 'v2', 'fetch');
|
||||
await copy('v2/fetch');
|
||||
cleanup('v2/fetch');
|
||||
await generateClient('v2/fetch', 'v2', 'fetch');
|
||||
copyAsset('index.html', 'v2/fetch/index.html');
|
||||
copyAsset('main.ts', 'v2/fetch/main.ts');
|
||||
compileWithTypescript('v2/fetch');
|
||||
await server.start('v2/fetch');
|
||||
await browser.start();
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v2.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v2/node', 'v2', 'node');
|
||||
cleanup('v2/node');
|
||||
await generateClient('v2/node', 'v2', 'node');
|
||||
compileWithTypescript('v2/node');
|
||||
await server.start('v2/node');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v2.xhr', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v2/xhr', 'v2', 'xhr');
|
||||
await copy('v2/xhr');
|
||||
cleanup('v2/xhr');
|
||||
await generateClient('v2/xhr', 'v2', 'xhr');
|
||||
copyAsset('index.html', 'v2/xhr/index.html');
|
||||
copyAsset('main.ts', 'v2/xhr/main.ts');
|
||||
compileWithTypescript('v2/xhr');
|
||||
await server.start('v2/xhr');
|
||||
await browser.start();
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v3/axios', 'v3', 'axios');
|
||||
cleanup('v3/axios');
|
||||
await generateClient('v3/axios', 'v3', 'axios');
|
||||
compileWithTypescript('v3/axios');
|
||||
await server.start('v3/axios');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithBabel } from './scripts/compileWithBabel';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.babel', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v3/babel', 'v3', 'fetch', true, true);
|
||||
await copy('v3/babel');
|
||||
cleanup('v3/babel');
|
||||
await generateClient('v3/babel', 'v3', 'fetch', true, true);
|
||||
copyAsset('index.html', 'v3/babel/index.html');
|
||||
copyAsset('main.ts', 'v3/babel/main.ts');
|
||||
compileWithBabel('v3/babel');
|
||||
await server.start('v3/babel');
|
||||
await browser.start();
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.fetch', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v3/fetch', 'v3', 'fetch');
|
||||
await copy('v3/fetch');
|
||||
cleanup('v3/fetch');
|
||||
await generateClient('v3/fetch', 'v3', 'fetch');
|
||||
copyAsset('index.html', 'v3/fetch/index.html');
|
||||
copyAsset('main.ts', 'v3/fetch/main.ts');
|
||||
compileWithTypescript('v3/fetch');
|
||||
await server.start('v3/fetch');
|
||||
await browser.start();
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { generate } from './scripts/generate';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.node', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v3/node', 'v3', 'node');
|
||||
cleanup('v3/node');
|
||||
await generateClient('v3/node', 'v3', 'node');
|
||||
compileWithTypescript('v3/node');
|
||||
await server.start('v3/node');
|
||||
}, 30000);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import browser from './scripts/browser';
|
||||
import { cleanup } from './scripts/cleanup';
|
||||
import { compileWithTypescript } from './scripts/compileWithTypescript';
|
||||
import { copy } from './scripts/copy';
|
||||
import { generate } from './scripts/generate';
|
||||
import { copyAsset } from './scripts/copyAsset';
|
||||
import { generateClient } from './scripts/generateClient';
|
||||
import server from './scripts/server';
|
||||
|
||||
describe('v3.xhr', () => {
|
||||
beforeAll(async () => {
|
||||
await generate('v3/xhr', 'v3', 'xhr');
|
||||
await copy('v3/xhr');
|
||||
cleanup('v3/xhr');
|
||||
await generateClient('v3/xhr', 'v3', 'xhr');
|
||||
copyAsset('index.html', 'v3/xhr/index.html');
|
||||
copyAsset('main.ts', 'v3/xhr/main.ts');
|
||||
compileWithTypescript('v3/xhr');
|
||||
await server.start('v3/xhr');
|
||||
await browser.start();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user