Skip to content

Commit 529a475

Browse files
authored
♻️ Migrate frontend client generation from openapi-typescript-codegen to @hey-api/openapi-ts (#1151)
1 parent 7d7b318 commit 529a475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1616
-1795
lines changed

frontend/package-lock.json

Lines changed: 94 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "tsc && vite build",
99
"lint": "biome check --apply-unsafe --no-errors-on-unmatched --files-ignore-unknown=true ./",
1010
"preview": "vite preview",
11-
"generate-client": "openapi --input ./openapi.json --useOptions --useUnionTypes --output ./src/client --client axios --exportSchemas true"
11+
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios --exportSchemas true"
1212
},
1313
"dependencies": {
1414
"@chakra-ui/icons": "2.1.1",
@@ -27,13 +27,13 @@
2727
},
2828
"devDependencies": {
2929
"@biomejs/biome": "1.6.1",
30+
"@hey-api/openapi-ts": "^0.34.1",
3031
"@tanstack/router-devtools": "1.19.1",
3132
"@tanstack/router-vite-plugin": "1.19.0",
3233
"@types/node": "20.10.5",
3334
"@types/react": "^18.2.37",
3435
"@types/react-dom": "^18.2.15",
3536
"@vitejs/plugin-react-swc": "^3.5.0",
36-
"openapi-typescript-codegen": "0.25.0",
3737
"typescript": "^5.2.2",
3838
"vite": "^5.0.13"
3939
}
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
/* generated using openapi-typescript-codegen -- do no edit */
2-
/* istanbul ignore file */
3-
/* tslint:disable */
4-
/* eslint-disable */
51
import type { ApiRequestOptions } from './ApiRequestOptions';
62
import type { ApiResult } from './ApiResult';
73

84
export class ApiError extends Error {
9-
public readonly url: string;
10-
public readonly status: number;
11-
public readonly statusText: string;
12-
public readonly body: any;
13-
public readonly request: ApiRequestOptions;
5+
public readonly url: string;
6+
public readonly status: number;
7+
public readonly statusText: string;
8+
public readonly body: unknown;
9+
public readonly request: ApiRequestOptions;
1410

15-
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
16-
super(message);
11+
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
12+
super(message);
1713

18-
this.name = 'ApiError';
19-
this.url = response.url;
20-
this.status = response.status;
21-
this.statusText = response.statusText;
22-
this.body = response.body;
23-
this.request = request;
24-
}
25-
}
14+
this.name = 'ApiError';
15+
this.url = response.url;
16+
this.status = response.status;
17+
this.statusText = response.statusText;
18+
this.body = response.body;
19+
this.request = request;
20+
}
21+
}
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
/* generated using openapi-typescript-codegen -- do no edit */
2-
/* istanbul ignore file */
3-
/* tslint:disable */
4-
/* eslint-disable */
51
export type ApiRequestOptions = {
6-
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
7-
readonly url: string;
8-
readonly path?: Record<string, any>;
9-
readonly cookies?: Record<string, any>;
10-
readonly headers?: Record<string, any>;
11-
readonly query?: Record<string, any>;
12-
readonly formData?: Record<string, any>;
13-
readonly body?: any;
14-
readonly mediaType?: string;
15-
readonly responseHeader?: string;
16-
readonly errors?: Record<number, string>;
17-
};
2+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3+
readonly url: string;
4+
readonly path?: Record<string, unknown>;
5+
readonly cookies?: Record<string, unknown>;
6+
readonly headers?: Record<string, unknown>;
7+
readonly query?: Record<string, unknown>;
8+
readonly formData?: Record<string, unknown>;
9+
readonly body?: any;
10+
readonly mediaType?: string;
11+
readonly responseHeader?: string;
12+
readonly errors?: Record<number, string>;
13+
};
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
/* generated using openapi-typescript-codegen -- do no edit */
2-
/* istanbul ignore file */
3-
/* tslint:disable */
4-
/* eslint-disable */
5-
export type ApiResult = {
6-
readonly url: string;
7-
readonly ok: boolean;
8-
readonly status: number;
9-
readonly statusText: string;
10-
readonly body: any;
11-
};
1+
export type ApiResult<TData = any> = {
2+
readonly body: TData;
3+
readonly ok: boolean;
4+
readonly status: number;
5+
readonly statusText: string;
6+
readonly url: string;
7+
};
Lines changed: 118 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,126 @@
1-
/* generated using openapi-typescript-codegen -- do no edit */
2-
/* istanbul ignore file */
3-
/* tslint:disable */
4-
/* eslint-disable */
51
export class CancelError extends Error {
6-
7-
constructor(message: string) {
8-
super(message);
9-
this.name = 'CancelError';
10-
}
11-
12-
public get isCancelled(): boolean {
13-
return true;
14-
}
2+
constructor(message: string) {
3+
super(message);
4+
this.name = 'CancelError';
5+
}
6+
7+
public get isCancelled(): boolean {
8+
return true;
9+
}
1510
}
1611

1712
export interface OnCancel {
18-
readonly isResolved: boolean;
19-
readonly isRejected: boolean;
20-
readonly isCancelled: boolean;
13+
readonly isResolved: boolean;
14+
readonly isRejected: boolean;
15+
readonly isCancelled: boolean;
2116

22-
(cancelHandler: () => void): void;
17+
(cancelHandler: () => void): void;
2318
}
2419

2520
export class CancelablePromise<T> implements Promise<T> {
26-
#isResolved: boolean;
27-
#isRejected: boolean;
28-
#isCancelled: boolean;
29-
readonly #cancelHandlers: (() => void)[];
30-
readonly #promise: Promise<T>;
31-
#resolve?: (value: T | PromiseLike<T>) => void;
32-
#reject?: (reason?: any) => void;
33-
34-
constructor(
35-
executor: (
36-
resolve: (value: T | PromiseLike<T>) => void,
37-
reject: (reason?: any) => void,
38-
onCancel: OnCancel
39-
) => void
40-
) {
41-
this.#isResolved = false;
42-
this.#isRejected = false;
43-
this.#isCancelled = false;
44-
this.#cancelHandlers = [];
45-
this.#promise = new Promise<T>((resolve, reject) => {
46-
this.#resolve = resolve;
47-
this.#reject = reject;
48-
49-
const onResolve = (value: T | PromiseLike<T>): void => {
50-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
51-
return;
52-
}
53-
this.#isResolved = true;
54-
this.#resolve?.(value);
55-
};
56-
57-
const onReject = (reason?: any): void => {
58-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
59-
return;
60-
}
61-
this.#isRejected = true;
62-
this.#reject?.(reason);
63-
};
64-
65-
const onCancel = (cancelHandler: () => void): void => {
66-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
67-
return;
68-
}
69-
this.#cancelHandlers.push(cancelHandler);
70-
};
71-
72-
Object.defineProperty(onCancel, 'isResolved', {
73-
get: (): boolean => this.#isResolved,
74-
});
75-
76-
Object.defineProperty(onCancel, 'isRejected', {
77-
get: (): boolean => this.#isRejected,
78-
});
79-
80-
Object.defineProperty(onCancel, 'isCancelled', {
81-
get: (): boolean => this.#isCancelled,
82-
});
83-
84-
return executor(onResolve, onReject, onCancel as OnCancel);
85-
});
86-
}
87-
88-
get [Symbol.toStringTag]() {
89-
return "Cancellable Promise";
90-
}
91-
92-
public then<TResult1 = T, TResult2 = never>(
93-
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
94-
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
95-
): Promise<TResult1 | TResult2> {
96-
return this.#promise.then(onFulfilled, onRejected);
97-
}
98-
99-
public catch<TResult = never>(
100-
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
101-
): Promise<T | TResult> {
102-
return this.#promise.catch(onRejected);
103-
}
104-
105-
public finally(onFinally?: (() => void) | null): Promise<T> {
106-
return this.#promise.finally(onFinally);
107-
}
108-
109-
public cancel(): void {
110-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
111-
return;
112-
}
113-
this.#isCancelled = true;
114-
if (this.#cancelHandlers.length) {
115-
try {
116-
for (const cancelHandler of this.#cancelHandlers) {
117-
cancelHandler();
118-
}
119-
} catch (error) {
120-
console.warn('Cancellation threw an error', error);
121-
return;
122-
}
123-
}
124-
this.#cancelHandlers.length = 0;
125-
this.#reject?.(new CancelError('Request aborted'));
126-
}
127-
128-
public get isCancelled(): boolean {
129-
return this.#isCancelled;
130-
}
131-
}
21+
private _isResolved: boolean;
22+
private _isRejected: boolean;
23+
private _isCancelled: boolean;
24+
readonly cancelHandlers: (() => void)[];
25+
readonly promise: Promise<T>;
26+
private _resolve?: (value: T | PromiseLike<T>) => void;
27+
private _reject?: (reason?: unknown) => void;
28+
29+
constructor(
30+
executor: (
31+
resolve: (value: T | PromiseLike<T>) => void,
32+
reject: (reason?: unknown) => void,
33+
onCancel: OnCancel
34+
) => void
35+
) {
36+
this._isResolved = false;
37+
this._isRejected = false;
38+
this._isCancelled = false;
39+
this.cancelHandlers = [];
40+
this.promise = new Promise<T>((resolve, reject) => {
41+
this._resolve = resolve;
42+
this._reject = reject;
43+
44+
const onResolve = (value: T | PromiseLike<T>): void => {
45+
if (this._isResolved || this._isRejected || this._isCancelled) {
46+
return;
47+
}
48+
this._isResolved = true;
49+
if (this._resolve) this._resolve(value);
50+
};
51+
52+
const onReject = (reason?: unknown): void => {
53+
if (this._isResolved || this._isRejected || this._isCancelled) {
54+
return;
55+
}
56+
this._isRejected = true;
57+
if (this._reject) this._reject(reason);
58+
};
59+
60+
const onCancel = (cancelHandler: () => void): void => {
61+
if (this._isResolved || this._isRejected || this._isCancelled) {
62+
return;
63+
}
64+
this.cancelHandlers.push(cancelHandler);
65+
};
66+
67+
Object.defineProperty(onCancel, 'isResolved', {
68+
get: (): boolean => this._isResolved,
69+
});
70+
71+
Object.defineProperty(onCancel, 'isRejected', {
72+
get: (): boolean => this._isRejected,
73+
});
74+
75+
Object.defineProperty(onCancel, 'isCancelled', {
76+
get: (): boolean => this._isCancelled,
77+
});
78+
79+
return executor(onResolve, onReject, onCancel as OnCancel);
80+
});
81+
}
82+
83+
get [Symbol.toStringTag]() {
84+
return "Cancellable Promise";
85+
}
86+
87+
public then<TResult1 = T, TResult2 = never>(
88+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
89+
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
90+
): Promise<TResult1 | TResult2> {
91+
return this.promise.then(onFulfilled, onRejected);
92+
}
93+
94+
public catch<TResult = never>(
95+
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
96+
): Promise<T | TResult> {
97+
return this.promise.catch(onRejected);
98+
}
99+
100+
public finally(onFinally?: (() => void) | null): Promise<T> {
101+
return this.promise.finally(onFinally);
102+
}
103+
104+
public cancel(): void {
105+
if (this._isResolved || this._isRejected || this._isCancelled) {
106+
return;
107+
}
108+
this._isCancelled = true;
109+
if (this.cancelHandlers.length) {
110+
try {
111+
for (const cancelHandler of this.cancelHandlers) {
112+
cancelHandler();
113+
}
114+
} catch (error) {
115+
console.warn('Cancellation threw an error', error);
116+
return;
117+
}
118+
}
119+
this.cancelHandlers.length = 0;
120+
if (this._reject) this._reject(new CancelError('Request aborted'));
121+
}
122+
123+
public get isCancelled(): boolean {
124+
return this._isCancelled;
125+
}
126+
}

0 commit comments

Comments
 (0)