Skip to content

Commit edd0702

Browse files
authored
Merge pull request #3660 from showhereco/tomvdv/fix-client-axios-ts2578
2 parents d7e660e + 11be579 commit edd0702

295 files changed

Lines changed: 2957 additions & 972 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/client-axios)**: fix: improve `beforeRequest` typing

.changeset/khaki-kiwis-travel-2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/client-ky)**: fix: improve `beforeRequest` typing

.changeset/khaki-kiwis-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/client-next)**: fix: improve `beforeRequest` typing

.changeset/nine-kiwis-call-3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/client-angular)**: fix: improve `beforeRequest` typing

.changeset/sour-numbers-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/client-fetch)**: fix: improve `beforeRequest` typing

examples/openapi-ts-angular-common/src/client/client/client.gen.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ export const createClient = (config: Config = {}): Client => {
9797
return { opts, req, url };
9898
};
9999

100-
const beforeRequest = async (options: RequestOptions) => {
100+
const beforeRequest = async <
101+
TData = unknown,
102+
TResponseStyle extends ResponseStyle = 'fields',
103+
ThrowOnError extends boolean = boolean,
104+
Url extends string = string,
105+
>(
106+
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
107+
) => {
101108
const { opts, req, url } = requestOptions(options);
102109

103110
if (opts.security) {
@@ -115,7 +122,6 @@ export const createClient = (config: Config = {}): Client => {
115122
};
116123

117124
const request: Client['request'] = async (options) => {
118-
// @ts-expect-error
119125
const { opts, req: initialReq } = await beforeRequest(options);
120126

121127
let req = initialReq;

examples/openapi-ts-angular/src/client/client/client.gen.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ export const createClient = (config: Config = {}): Client => {
9797
return { opts, req, url };
9898
};
9999

100-
const beforeRequest = async (options: RequestOptions) => {
100+
const beforeRequest = async <
101+
TData = unknown,
102+
TResponseStyle extends ResponseStyle = 'fields',
103+
ThrowOnError extends boolean = boolean,
104+
Url extends string = string,
105+
>(
106+
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
107+
) => {
101108
const { opts, req, url } = requestOptions(options);
102109

103110
if (opts.security) {
@@ -115,7 +122,6 @@ export const createClient = (config: Config = {}): Client => {
115122
};
116123

117124
const request: Client['request'] = async (options) => {
118-
// @ts-expect-error
119125
const { opts, req: initialReq } = await beforeRequest(options);
120126

121127
let req = initialReq;

examples/openapi-ts-axios/src/client/client/client.gen.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ export const createClient = (config: Config = {}): Client => {
3535
return getConfig();
3636
};
3737

38-
const beforeRequest = async (options: RequestOptions) => {
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+
) => {
3945
const opts = {
4046
..._config,
4147
...options,
@@ -65,7 +71,6 @@ export const createClient = (config: Config = {}): Client => {
6571

6672
// @ts-expect-error
6773
const request: Client['request'] = async (options) => {
68-
// @ts-expect-error
6974
const { opts, url } = await beforeRequest(options);
7075
try {
7176
// assign Axios here for consistency with fetch

examples/openapi-ts-axios/src/client/client/types.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolea
115115

116116
type BuildUrlFn = <
117117
TData extends {
118-
body?: unknown;
119118
path?: Record<string, unknown>;
120119
query?: Record<string, unknown>;
121120
url: string;
122121
},
123122
>(
124-
options: TData & Options<TData>,
123+
options: TData &
124+
Pick<
125+
RequestOptions<unknown, boolean>,
126+
'axios' | 'baseURL' | 'paramsSerializer' | 'querySerializer'
127+
>,
125128
) => string;
126129

127130
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {

examples/openapi-ts-fastify/src/client/client/client.gen.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ export const createClient = (config: Config = {}): Client => {
3131

3232
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
3333

34-
const beforeRequest = async (options: RequestOptions) => {
34+
const beforeRequest = async <
35+
TData = unknown,
36+
TResponseStyle extends 'data' | 'fields' = 'fields',
37+
ThrowOnError extends boolean = boolean,
38+
Url extends string = string,
39+
>(
40+
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41+
) => {
3542
const opts = {
3643
..._config,
3744
...options,
@@ -60,13 +67,14 @@ export const createClient = (config: Config = {}): Client => {
6067
opts.headers.delete('Content-Type');
6168
}
6269

63-
const url = buildUrl(opts);
70+
const resolvedOpts = opts as typeof opts &
71+
ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
72+
const url = buildUrl(resolvedOpts);
6473

65-
return { opts, url };
74+
return { opts: resolvedOpts, url };
6675
};
6776

6877
const request: Client['request'] = async (options) => {
69-
// @ts-expect-error
7078
const { opts, url } = await beforeRequest(options);
7179
const requestInit: ReqInit = {
7280
redirect: 'follow',

0 commit comments

Comments
 (0)