Skip to content

Commit 354c975

Browse files
committed
feat(client): update example to use actual code from the spec to avoid type error
1 parent 7af9ef1 commit 354c975

File tree

5 files changed

+279
-144
lines changed

5 files changed

+279
-144
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
Section,
1010
} from '@radix-ui/themes';
1111

12-
// @ts-expect-error
13-
import { postFoo } from './client/sdk.gen';
12+
import { addPet } from './client/sdk.gen';
1413

1514
function App() {
1615
const onClick = async () => {
17-
postFoo({
16+
addPet({
1817
body: {
19-
foo: [[1, 2]],
18+
name: 'test',
19+
photoUrls: ['test'],
2020
},
2121
});
2222
};
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import { createClient, createConfig } from '@hey-api/client-fetch';
3+
import {
4+
type ClientOptions as DefaultClientOptions,
5+
type Config,
6+
createClient,
7+
createConfig,
8+
} from '@hey-api/client-fetch';
49

510
import { createClientConfig } from '../hey-api';
11+
import type { ClientOptions } from './types.gen';
612

7-
export const client = createClient(createClientConfig(createConfig()));
13+
/**
14+
* The `createClientConfig()` function will be called on client initialization
15+
* and the returned object will become the client's initial configuration.
16+
*
17+
* You may want to initialize your client this way instead of calling
18+
* `setConfig()`. This is useful for example if you're using Next.js
19+
* to ensure your client always has the correct values.
20+
*/
21+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
22+
(
23+
override?: Config<DefaultClientOptions & T>,
24+
) => Config<Required<DefaultClientOptions> & T>;
25+
26+
export const client = createClient(
27+
createClientConfig(
28+
createConfig<ClientOptions>({
29+
baseUrl: 'https://petstore3.swagger.io/api/v3',
30+
}),
31+
),
32+
);

examples/openapi-ts-sample/src/client/schemas.gen.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,6 @@ export const OrderSchema = {
3838
},
3939
} as const;
4040

41-
export const CustomerSchema = {
42-
properties: {
43-
address: {
44-
items: {
45-
$ref: '#/components/schemas/Address',
46-
},
47-
type: 'array',
48-
xml: {
49-
name: 'addresses',
50-
wrapped: true,
51-
},
52-
},
53-
id: {
54-
example: 100000,
55-
format: 'int64',
56-
type: 'integer',
57-
},
58-
username: {
59-
example: 'fehguy',
60-
type: 'string',
61-
},
62-
},
63-
type: 'object',
64-
xml: {
65-
name: 'customer',
66-
},
67-
} as const;
68-
69-
export const AddressSchema = {
70-
properties: {
71-
city: {
72-
example: 'Palo Alto',
73-
type: 'string',
74-
},
75-
state: {
76-
example: 'CA',
77-
type: 'string',
78-
},
79-
street: {
80-
example: '437 Lytton',
81-
type: 'string',
82-
},
83-
zip: {
84-
example: 94301,
85-
type: 'string',
86-
},
87-
},
88-
type: 'object',
89-
xml: {
90-
name: 'address',
91-
},
92-
} as const;
93-
9441
export const CategorySchema = {
9542
properties: {
9643
id: {
@@ -130,11 +77,11 @@ export const UserSchema = {
13077
type: 'string',
13178
},
13279
password: {
133-
example: 12345,
80+
example: '12345',
13481
type: 'string',
13582
},
13683
phone: {
137-
example: 12345,
84+
example: '12345',
13885
type: 'string',
13986
},
14087
userStatus: {
@@ -206,9 +153,6 @@ export const PetSchema = {
206153
tags: {
207154
items: {
208155
$ref: '#/components/schemas/Tag',
209-
xml: {
210-
name: 'tag',
211-
},
212156
},
213157
type: 'array',
214158
xml: {

0 commit comments

Comments
 (0)