Skip to content

Commit 97b2776

Browse files
committed
fix: more examples
1 parent 4b98f28 commit 97b2776

13 files changed

Lines changed: 142 additions & 46 deletions

File tree

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-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',

examples/openapi-ts-fetch/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',

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

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

3737
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
3838

39-
const beforeRequest = async (options: RequestOptions) => {
39+
const beforeRequest = async <
40+
TData = unknown,
41+
TResponseStyle extends 'data' | 'fields' = 'fields',
42+
ThrowOnError extends boolean = boolean,
43+
Url extends string = string,
44+
>(
45+
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
46+
) => {
4047
const opts = {
4148
..._config,
4249
...options,
@@ -64,9 +71,11 @@ export const createClient = (config: Config = {}): Client => {
6471
opts.headers.delete('Content-Type');
6572
}
6673

67-
const url = buildUrl(opts);
74+
const resolvedOpts = opts as typeof opts &
75+
ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
76+
const url = buildUrl(resolvedOpts);
6877

69-
return { opts, url };
78+
return { opts: resolvedOpts, url };
7079
};
7180

7281
const parseErrorResponse = async (
@@ -113,7 +122,6 @@ export const createClient = (config: Config = {}): Client => {
113122
};
114123

115124
const request: Client['request'] = async (options) => {
116-
// @ts-expect-error
117125
const { opts, url } = await beforeRequest(options);
118126

119127
const kyInstance = opts.ky!;

examples/openapi-ts-nestjs/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',

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

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

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

34-
const beforeRequest = async (options: RequestOptions) => {
34+
const beforeRequest = async <
35+
TData = unknown,
36+
ThrowOnError extends boolean = boolean,
37+
Url extends string = string,
38+
>(
39+
options: RequestOptions<TData, ThrowOnError, Url>,
40+
) => {
3541
const opts = {
3642
..._config,
3743
...options,
@@ -60,14 +66,14 @@ export const createClient = (config: Config = {}): Client => {
6066
opts.headers.delete('Content-Type');
6167
}
6268

63-
const url = buildUrl(opts);
69+
const resolvedOpts = opts as typeof opts & ResolvedRequestOptions<ThrowOnError, Url>;
70+
const url = buildUrl(resolvedOpts);
6471

65-
return { opts, url };
72+
return { opts: resolvedOpts, url };
6673
};
6774

6875
// @ts-expect-error
6976
const request: Client['request'] = async (options) => {
70-
// @ts-expect-error
7177
const { opts, url } = await beforeRequest(options);
7278

7379
for (const fn of interceptors.request.fns) {

examples/openapi-ts-openai/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',

examples/openapi-ts-pinia-colada/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',

examples/openapi-ts-tanstack-angular-query-experimental/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;

0 commit comments

Comments
 (0)