Skip to content

Commit 29d8710

Browse files
committed
You can run npm run sample to test the generation
1 parent 52fbebe commit 29d8710

File tree

13 files changed

+645
-1
lines changed

13 files changed

+645
-1
lines changed

generated/core/ApiError.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type { ApiRequestOptions } from './ApiRequestOptions';
5+
import type { ApiResult } from './ApiResult';
6+
7+
export class ApiError extends Error {
8+
public readonly url: string;
9+
public readonly status: number;
10+
public readonly statusText: string;
11+
public readonly body: any;
12+
public readonly request: ApiRequestOptions;
13+
14+
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
15+
super(message);
16+
17+
this.name = 'ApiError';
18+
this.url = response.url;
19+
this.status = response.status;
20+
this.statusText = response.statusText;
21+
this.body = response.body;
22+
this.request = request;
23+
}
24+
}

generated/core/ApiRequestOptions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export type ApiRequestOptions = {
5+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
6+
readonly url: string;
7+
readonly path?: Record<string, any>;
8+
readonly cookies?: Record<string, any>;
9+
readonly headers?: Record<string, any>;
10+
readonly query?: Record<string, any>;
11+
readonly formData?: Record<string, any>;
12+
readonly body?: any;
13+
readonly mediaType?: string;
14+
readonly responseHeader?: string;
15+
readonly errors?: Record<number, string>;
16+
};

generated/core/ApiResult.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export type ApiResult = {
5+
readonly url: string;
6+
readonly ok: boolean;
7+
readonly status: number;
8+
readonly statusText: string;
9+
readonly body: any;
10+
};

generated/core/CancelablePromise.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export class CancelError extends Error {
5+
6+
constructor(message: string) {
7+
super(message);
8+
this.name = 'CancelError';
9+
}
10+
11+
public get isCancelled(): boolean {
12+
return true;
13+
}
14+
}
15+
16+
export interface OnCancel {
17+
readonly isResolved: boolean;
18+
readonly isRejected: boolean;
19+
readonly isCancelled: boolean;
20+
21+
(cancelHandler: () => void): void;
22+
}
23+
24+
export class CancelablePromise<T> implements Promise<T> {
25+
readonly [Symbol.toStringTag]!: string;
26+
27+
private _isResolved: boolean;
28+
private _isRejected: boolean;
29+
private _isCancelled: boolean;
30+
private readonly _cancelHandlers: (() => void)[];
31+
private readonly _promise: Promise<T>;
32+
private _resolve?: (value: T | PromiseLike<T>) => void;
33+
private _reject?: (reason?: any) => void;
34+
35+
constructor(
36+
executor: (
37+
resolve: (value: T | PromiseLike<T>) => void,
38+
reject: (reason?: any) => void,
39+
onCancel: OnCancel
40+
) => void
41+
) {
42+
this._isResolved = false;
43+
this._isRejected = false;
44+
this._isCancelled = false;
45+
this._cancelHandlers = [];
46+
this._promise = new Promise<T>((resolve, reject) => {
47+
this._resolve = resolve;
48+
this._reject = reject;
49+
50+
const onResolve = (value: T | PromiseLike<T>): void => {
51+
if (this._isResolved || this._isRejected || this._isCancelled) {
52+
return;
53+
}
54+
this._isResolved = true;
55+
this._resolve?.(value);
56+
};
57+
58+
const onReject = (reason?: any): void => {
59+
if (this._isResolved || this._isRejected || this._isCancelled) {
60+
return;
61+
}
62+
this._isRejected = true;
63+
this._reject?.(reason);
64+
};
65+
66+
const onCancel = (cancelHandler: () => void): void => {
67+
if (this._isResolved || this._isRejected || this._isCancelled) {
68+
return;
69+
}
70+
this._cancelHandlers.push(cancelHandler);
71+
};
72+
73+
Object.defineProperty(onCancel, 'isResolved', {
74+
get: (): boolean => this._isResolved,
75+
});
76+
77+
Object.defineProperty(onCancel, 'isRejected', {
78+
get: (): boolean => this._isRejected,
79+
});
80+
81+
Object.defineProperty(onCancel, 'isCancelled', {
82+
get: (): boolean => this._isCancelled,
83+
});
84+
85+
return executor(onResolve, onReject, onCancel as OnCancel);
86+
});
87+
}
88+
89+
public then<TResult1 = T, TResult2 = never>(
90+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
91+
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
92+
): Promise<TResult1 | TResult2> {
93+
return this._promise.then(onFulfilled, onRejected);
94+
}
95+
96+
public catch<TResult = never>(
97+
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
98+
): Promise<T | TResult> {
99+
return this._promise.catch(onRejected);
100+
}
101+
102+
public finally(onFinally?: (() => void) | null): Promise<T> {
103+
return this._promise.finally(onFinally);
104+
}
105+
106+
public cancel(): void {
107+
if (this._isResolved || this._isRejected || this._isCancelled) {
108+
return;
109+
}
110+
this._isCancelled = true;
111+
if (this._cancelHandlers.length) {
112+
try {
113+
for (const cancelHandler of this._cancelHandlers) {
114+
cancelHandler();
115+
}
116+
} catch (error) {
117+
console.warn('Cancellation threw an error', error);
118+
return;
119+
}
120+
}
121+
this._cancelHandlers.length = 0;
122+
this._reject?.(new CancelError('Request aborted'));
123+
}
124+
125+
public get isCancelled(): boolean {
126+
return this._isCancelled;
127+
}
128+
}

generated/core/OpenAPI.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type { ApiRequestOptions } from './ApiRequestOptions';
5+
6+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
7+
type Headers = Record<string, string>;
8+
9+
export type OpenAPIConfig = {
10+
BASE: string;
11+
VERSION: string;
12+
WITH_CREDENTIALS: boolean;
13+
CREDENTIALS: 'include' | 'omit' | 'same-origin';
14+
TOKEN?: string | Resolver<string>;
15+
USERNAME?: string | Resolver<string>;
16+
PASSWORD?: string | Resolver<string>;
17+
HEADERS?: Headers | Resolver<Headers>;
18+
ENCODE_PATH?: (path: string) => string;
19+
};
20+
21+
export const OpenAPI: OpenAPIConfig = {
22+
BASE: '',
23+
VERSION: '1.0.0',
24+
WITH_CREDENTIALS: false,
25+
CREDENTIALS: 'include',
26+
TOKEN: undefined,
27+
USERNAME: undefined,
28+
PASSWORD: undefined,
29+
HEADERS: undefined,
30+
ENCODE_PATH: undefined,
31+
};

0 commit comments

Comments
 (0)