Skip to content

Commit a8f1ba0

Browse files
⬆️ Bump @hey-api/openapi-ts from 0.73.0 to 0.97.3 and migrate to new client (#2388)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent f8b7926 commit a8f1ba0

42 files changed

Lines changed: 2798 additions & 1714 deletions

Some content is hidden

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

‎bun.lock‎

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

‎frontend/openapi-ts.config.ts‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,17 @@ export default defineConfig({
55
output: "./src/client",
66

77
plugins: [
8-
"legacy/axios",
8+
{ name: "@hey-api/client-axios", throwOnError: true },
9+
{ name: "@hey-api/typescript", case: "preserve" },
910
{
1011
name: "@hey-api/sdk",
11-
// NOTE: this doesn't allow tree-shaking
12-
asClass: true,
13-
operationId: true,
14-
classNameBuilder: "{{name}}Service",
15-
methodNameBuilder: (operation) => {
16-
// @ts-expect-error
17-
let name: string = operation.name
18-
// @ts-expect-error
19-
const service: string = operation.service
20-
21-
if (service && name.toLowerCase().startsWith(service.toLowerCase())) {
22-
name = name.slice(service.length)
23-
}
24-
25-
return name.charAt(0).toLowerCase() + name.slice(1)
12+
operations: {
13+
// NOTE: this doesn't allow tree-shaking
14+
strategy: "byTags",
15+
methods: "static",
16+
containerName: "{{name}}Service",
17+
methodName: (name: string): string => name.replace(/^[^-]*-/, ""),
2618
},
2719
},
28-
{
29-
name: "@hey-api/schemas",
30-
type: "json",
31-
},
3220
],
3321
})

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@biomejs/biome": "^2.4.16",
53-
"@hey-api/openapi-ts": "0.73.0",
53+
"@hey-api/openapi-ts": "0.97.3",
5454
"@playwright/test": "1.61.1",
5555
"@tanstack/router-devtools": "^1.167.0",
5656
"@tanstack/router-plugin": "^1.168.18",

‎frontend/src/client/client.gen.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { type ClientOptions, type Config, createClient, createConfig } from './client';
4+
import type { ClientOptions as ClientOptions2 } from './types.gen';
5+
6+
/**
7+
* The `createClientConfig()` function will be called on client initialization
8+
* and the returned object will become the client's initial configuration.
9+
*
10+
* You may want to initialize your client this way instead of calling
11+
* `setConfig()`. This is useful for example if you're using Next.js
12+
* to ensure your client always has the correct values.
13+
*/
14+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
15+
16+
export const client = createClient(createConfig<ClientOptions2>({ throwOnError: true }));
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios';
4+
import axios from 'axios';
5+
6+
import { createSseClient } from '../core/serverSentEvents.gen';
7+
import type { HttpMethod } from '../core/types.gen';
8+
import { getValidRequestBody } from '../core/utils.gen';
9+
import type { Client, Config, RequestOptions } from './types.gen';
10+
import { buildUrl, createConfig, mergeConfigs, mergeHeaders, setAuthParams } from './utils.gen';
11+
12+
export const createClient = (config: Config = {}): Client => {
13+
let _config = mergeConfigs(createConfig(), config);
14+
15+
let instance: AxiosInstance;
16+
17+
if (_config.axios && !('Axios' in _config.axios)) {
18+
instance = _config.axios;
19+
} else {
20+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21+
const { auth, ...configWithoutAuth } = _config;
22+
instance = axios.create(configWithoutAuth);
23+
}
24+
25+
const getConfig = (): Config => ({ ..._config });
26+
27+
const setConfig = (config: Config): Config => {
28+
_config = mergeConfigs(_config, config);
29+
instance.defaults = {
30+
...instance.defaults,
31+
..._config,
32+
// @ts-expect-error
33+
headers: mergeHeaders(instance.defaults.headers, _config.headers),
34+
};
35+
return getConfig();
36+
};
37+
38+
const beforeRequest = async <
39+
TData = unknown,
40+
ThrowOnError extends boolean = boolean,
41+
Url extends string = string,
42+
>(
43+
options: RequestOptions<TData, ThrowOnError, Url>,
44+
) => {
45+
const opts = {
46+
..._config,
47+
...options,
48+
axios: options.axios ?? _config.axios ?? instance,
49+
headers: mergeHeaders(_config.headers, options.headers),
50+
};
51+
52+
if (opts.security) {
53+
await setAuthParams(opts);
54+
}
55+
56+
if (opts.requestValidator) {
57+
await opts.requestValidator(opts);
58+
}
59+
60+
if (opts.body !== undefined && opts.bodySerializer) {
61+
opts.body = opts.bodySerializer(opts.body);
62+
}
63+
64+
const url = buildUrl(opts);
65+
66+
return { opts, url };
67+
};
68+
69+
// @ts-expect-error
70+
const request: Client['request'] = async (options) => {
71+
const { opts, url } = await beforeRequest(options);
72+
try {
73+
// assign Axios here for consistency with fetch
74+
const _axios = opts.axios!;
75+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
76+
const { auth, ...optsWithoutAuth } = opts;
77+
const response = await _axios({
78+
...optsWithoutAuth,
79+
baseURL: '', // the baseURL is already included in `url`
80+
data: getValidRequestBody(opts),
81+
headers: opts.headers as RawAxiosRequestHeaders,
82+
// let `paramsSerializer()` handle query params if it exists
83+
params: opts.paramsSerializer ? opts.query : undefined,
84+
url,
85+
});
86+
87+
let { data } = response;
88+
89+
if (opts.responseType === 'json') {
90+
if (opts.responseValidator) {
91+
await opts.responseValidator(data);
92+
}
93+
94+
if (opts.responseTransformer) {
95+
data = await opts.responseTransformer(data);
96+
}
97+
}
98+
99+
return {
100+
...response,
101+
data: data ?? {},
102+
};
103+
} catch (error) {
104+
const e = error as AxiosError;
105+
if (opts.throwOnError) {
106+
throw e;
107+
}
108+
// @ts-expect-error
109+
e.error = e.response?.data ?? {};
110+
return e;
111+
}
112+
};
113+
114+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
115+
request({ ...options, method });
116+
117+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
118+
const { opts, url } = await beforeRequest(options);
119+
return createSseClient({
120+
...opts,
121+
body: opts.body as BodyInit | null | undefined,
122+
headers: opts.headers as Record<string, string>,
123+
method,
124+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
125+
// @ts-expect-error
126+
signal: opts.signal,
127+
url,
128+
});
129+
};
130+
131+
const _buildUrl: Client['buildUrl'] = (options) =>
132+
buildUrl({ axios: instance, ..._config, ...options });
133+
134+
return {
135+
buildUrl: _buildUrl,
136+
connect: makeMethodFn('CONNECT'),
137+
delete: makeMethodFn('DELETE'),
138+
get: makeMethodFn('GET'),
139+
getConfig,
140+
head: makeMethodFn('HEAD'),
141+
instance,
142+
options: makeMethodFn('OPTIONS'),
143+
patch: makeMethodFn('PATCH'),
144+
post: makeMethodFn('POST'),
145+
put: makeMethodFn('PUT'),
146+
request,
147+
setConfig,
148+
sse: {
149+
connect: makeSseFn('CONNECT'),
150+
delete: makeSseFn('DELETE'),
151+
get: makeSseFn('GET'),
152+
head: makeSseFn('HEAD'),
153+
options: makeSseFn('OPTIONS'),
154+
patch: makeSseFn('PATCH'),
155+
post: makeSseFn('POST'),
156+
put: makeSseFn('PUT'),
157+
trace: makeSseFn('TRACE'),
158+
},
159+
trace: makeMethodFn('TRACE'),
160+
} as Client;
161+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type { Auth } from '../core/auth.gen';
4+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
5+
export {
6+
formDataBodySerializer,
7+
jsonBodySerializer,
8+
urlSearchParamsBodySerializer,
9+
} from '../core/bodySerializer.gen';
10+
export { buildClientParams } from '../core/params.gen';
11+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
12+
export { createClient } from './client.gen';
13+
export type {
14+
Client,
15+
ClientOptions,
16+
Config,
17+
CreateClientConfig,
18+
Options,
19+
RequestOptions,
20+
RequestResult,
21+
TDataShape,
22+
} from './types.gen';
23+
export { createConfig } from './utils.gen';

0 commit comments

Comments
 (0)