Skip to content

Commit c3908ba

Browse files
committed
feat(client): update example to use actual code from the spec to avoid type error
1 parent 8372977 commit c3908ba

File tree

1,043 files changed

+349366
-2
lines changed

Some content is hidden

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

1,043 files changed

+349366
-2
lines changed

examples/openapi-ts-sample/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ function App() {
1515
const onClick = async () => {
1616
const response = await getPetById({
1717
path: {
18-
// @ts-expect-error
19-
foo: 3,
2018
petId: 3,
2119
},
2220
});
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 } from './types.gen';
4+
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
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 DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
15+
16+
export const client = createClient(createConfig<ClientOptions>());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
3+
export * from './sdk.gen';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
4+
import type { PostFooData, PostFooResponse } from './types.gen';
5+
import { client as _heyApiClient } from './client.gen';
6+
7+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
8+
/**
9+
* You can provide a client instance returned by `createClient()` instead of
10+
* individual options. This might be also useful if you want to implement a
11+
* custom client.
12+
*/
13+
client?: Client;
14+
/**
15+
* You can pass arbitrary values through the `meta` object. This can be
16+
* used to access values that aren't defined as part of the SDK function.
17+
*/
18+
meta?: Record<string, unknown>;
19+
};
20+
21+
export const postFoo = <ThrowOnError extends boolean = false>(options: Options<PostFooData, ThrowOnError>) => {
22+
return (options.client ?? _heyApiClient).post<PostFooResponse, unknown, ThrowOnError>({
23+
bodySerializer: null,
24+
url: '/foo',
25+
...options,
26+
headers: {
27+
'Content-Type': 'text/plain',
28+
...options?.headers
29+
}
30+
});
31+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type PostFooData = {
4+
body: string;
5+
path?: never;
6+
query?: never;
7+
url: '/foo';
8+
};
9+
10+
export type PostFooResponses = {
11+
/**
12+
* OK
13+
*/
14+
200: string;
15+
};
16+
17+
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
18+
19+
export type ClientOptions = {
20+
baseUrl: string;
21+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type _110 = '1-10' | '11-20';
4+
5+
export const _110 = {
6+
110: '1-10',
7+
1120: '11-20'
8+
} as const;
9+
10+
export type MyFoo = 'myFoo' | 'myBar';
11+
12+
export const MyFoo = {
13+
MyFoo: 'myFoo',
14+
MyBar: 'myBar'
15+
} as const;
16+
17+
export type MyFoo2 = 'MyFoo' | 'MyBar';
18+
19+
export const MyFoo2 = {
20+
MyFoo: 'MyFoo',
21+
MyBar: 'MyBar'
22+
} as const;
23+
24+
export type Foo = 'foo' | 'bar' | '' | true | false;
25+
26+
export const Foo = {
27+
Foo: 'foo',
28+
Bar: 'bar',
29+
'': '',
30+
True: true,
31+
False: false
32+
} as const;
33+
34+
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
35+
36+
export const Numbers = {
37+
100: 100,
38+
200: 200,
39+
300: 300,
40+
'-100': -100,
41+
'-200': -200,
42+
'-300': -300
43+
} as const;
44+
45+
export type ClientOptions = {
46+
baseUrl: string;
47+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type _110 = '1-10' | '11-20';
4+
5+
export const _110 = {
6+
'1_10': '1-10',
7+
'11_20': '11-20'
8+
} as const;
9+
10+
export type MyFoo = 'myFoo' | 'myBar';
11+
12+
export const MyFoo = {
13+
MY_FOO: 'myFoo',
14+
MY_BAR: 'myBar'
15+
} as const;
16+
17+
export type MyFoo2 = 'MyFoo' | 'MyBar';
18+
19+
export const MyFoo2 = {
20+
MY_FOO: 'MyFoo',
21+
MY_BAR: 'MyBar'
22+
} as const;
23+
24+
export type Foo = 'foo' | 'bar' | '' | true | false;
25+
26+
export const Foo = {
27+
FOO: 'foo',
28+
BAR: 'bar',
29+
'': '',
30+
TRUE: true,
31+
FALSE: false
32+
} as const;
33+
34+
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
35+
36+
export const Numbers = {
37+
100: 100,
38+
200: 200,
39+
300: 300,
40+
'-100': -100,
41+
'-200': -200,
42+
'-300': -300
43+
} as const;
44+
45+
export type ClientOptions = {
46+
baseUrl: string;
47+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';

0 commit comments

Comments
 (0)