You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clients can now validate both request and response data. As a result, passing a boolean or string to `validator` will control both of these options. To preserve the previous behavior, set `validator.request` to `false` and `validator.response` to your previous configuration.
Copy file name to clipboardExpand all lines: docs/openapi-ts/migrating.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,35 @@ This config option is deprecated and will be removed in favor of [clients](./cli
27
27
28
28
This config option is deprecated and will be removed.
29
29
30
+
## v0.77.0
31
+
32
+
### Updated `sdk.validator` option
33
+
34
+
Clients can now validate both request and response data. As a result, passing a boolean or string to `validator` will control both of these options. To preserve the previous behavior, set `validator.request` to `false` and `validator.response` to your previous configuration.
35
+
36
+
```js
37
+
exportdefault {
38
+
input:'https://get.heyapi.dev/hey-api/backend',
39
+
output:'src/client',
40
+
plugins: [
41
+
// ...other plugins
42
+
{
43
+
name:'@hey-api/sdk',
44
+
validator:true, // [!code --]
45
+
validator: {
46
+
// [!code ++]
47
+
request:false, // [!code ++]
48
+
response:true, // [!code ++]
49
+
}, // [!code ++]
50
+
},
51
+
],
52
+
};
53
+
```
54
+
55
+
### Updated Plugin API
56
+
57
+
Please refer to the [custom plugin](/openapi-ts/plugins/custom) tutorial for the latest guide.
Copy file name to clipboardExpand all lines: docs/openapi-ts/output/sdk.md
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,5 +146,83 @@ client.post({
146
146
147
147
:::
148
148
149
+
## Validators
150
+
151
+
There are two ways to configure validators. If you only want to add validators to your SDKs, set `sdk.validator` to a validator plugin name. This will implicitly add the selected plugin with default values.
152
+
153
+
For a more granular approach, add a validator plugin and set `sdk.validator` to the plugin name or `true` to automatically select a plugin. Until you customize the validator plugin, both approaches will produce the same default output.
154
+
155
+
::: code-group
156
+
157
+
```js [sdk]
158
+
exportdefault {
159
+
input:'https://get.heyapi.dev/hey-api/backend',
160
+
output:'src/client',
161
+
plugins: [
162
+
{
163
+
name:'@hey-api/sdk',
164
+
validator:'zod', // [!code ++]
165
+
},
166
+
],
167
+
};
168
+
```
169
+
170
+
```js [validator]
171
+
exportdefault {
172
+
input:'https://get.heyapi.dev/hey-api/backend',
173
+
output:'src/client',
174
+
plugins: [
175
+
{
176
+
name:'@hey-api/sdk',
177
+
validator:true, // or 'zod' // [!code ++]
178
+
},
179
+
{
180
+
name:'zod', // [!code ++]
181
+
// other options
182
+
},
183
+
],
184
+
};
185
+
```
186
+
187
+
:::
188
+
189
+
You can choose to validate only requests or responses.
190
+
191
+
::: code-group
192
+
193
+
```js [requests]
194
+
exportdefault {
195
+
input:'https://get.heyapi.dev/hey-api/backend',
196
+
output:'src/client',
197
+
plugins: [
198
+
{
199
+
name:'@hey-api/sdk',
200
+
validator: {
201
+
request:'zod', // [!code ++]
202
+
},
203
+
},
204
+
],
205
+
};
206
+
```
207
+
208
+
```js [responses]
209
+
exportdefault {
210
+
input:'https://get.heyapi.dev/hey-api/backend',
211
+
output:'src/client',
212
+
plugins: [
213
+
{
214
+
name:'@hey-api/sdk',
215
+
validator: {
216
+
response:'zod', // [!code ++]
217
+
},
218
+
},
219
+
],
220
+
};
221
+
```
222
+
223
+
:::
224
+
225
+
Learn more about available validators on the [Validators](/openapi-ts/validators/) page.
Reserved fields are prefixed with an underscore and are not exposed to the user.
60
-
:::
61
-
62
-
`config.ts` contains the runtime configuration for your plugin. It must implement the `Config` interface we created above and define `handler()` and `handlerLegacy()` functions from the `Plugin.Config` interface.
62
+
`config.ts` contains the runtime configuration for your plugin. It must implement the `MyPlugin` interface we created above and define the `handler()` function from the `MyPlugin['Config']` interface.
Notice we defined `handlerLegacy` in our `config.ts` file. This method is responsible for generating the actual output when using the legacy parser. We do not recommend implementing this method unless you must use the legacy parser. You can use one of our [`plugin-legacy.ts`](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/%40hey-api/typescript/plugin-legacy.ts) files as an inspiration for potential implementation.
148
+
You can also define an optional `handlerLegacy`function in `config.ts`. This method is responsible for generating the output when using the legacy parser. We do not recommend implementing this method unless you must use the legacy parser. You can use one of our [`plugin-legacy.ts`](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/%40hey-api/typescript/plugin-legacy.ts) files as an inspiration for potential implementation.
Copy file name to clipboardExpand all lines: docs/openapi-ts/validators.md
+5-38Lines changed: 5 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,11 @@ There are times when you cannot blindly trust the server to return the correct d
9
9
10
10
Whatever your reason to use validators might be, you can rest assured that you're working with the correct data.
11
11
12
+
## Features
13
+
14
+
- seamless integration with `@hey-api/openapi-ts` ecosystem
15
+
- schemas for requests, responses, and reusable definitions
16
+
12
17
## Options
13
18
14
19
Hey API natively supports the following validators.
@@ -23,43 +28,5 @@ Hey API natively supports the following validators.
23
28
24
29
Don't see your validator? Let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
25
30
26
-
## Installation
27
-
28
-
There are two ways to generate validators. If you only need response validation in your SDKs, set `sdk.validator` to the desired value. For a more granular approach, add your validator to plugins and set `sdk.validator` to `true`.
0 commit comments