Skip to content

Commit b9dc785

Browse files
authored
Merge pull request #3671 from hey-api/feat/zod-data-split
feat: extract zod and validator schemas
2 parents 9b9ffce + 96f60ad commit b9dc785

166 files changed

Lines changed: 6009 additions & 7790 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.

.changeset/eighty-suns-fly.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"@hey-api/openapi-ts": minor
3+
---
4+
5+
**plugin(valibot)**: remove request data schema
6+
7+
### Validator request schemas
8+
9+
Valibot plugin no longer exports composite request `Data` schemas. Instead, each layer is exported as a separate schema. If you're using validators with SDKs, you can preserve the composite schema with `shouldExtract`:
10+
11+
```js
12+
export default {
13+
input: 'hey-api/backend', // sign up at app.heyapi.dev
14+
output: 'src/client',
15+
plugins: [
16+
// ...other plugins
17+
{
18+
name: 'sdk',
19+
validator: 'valibot',
20+
},
21+
{
22+
name: 'valibot',
23+
requests: {
24+
shouldExtract: true,
25+
},
26+
},
27+
],
28+
};
29+
```

.changeset/every-vans-sleep.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@hey-api/openapi-ts": minor
3+
"@hey-api/shared": minor
4+
---
5+
6+
**internal**: remove `plugin.getSymbol()` function
7+
8+
### Removed `plugin.getSymbol()` function
9+
10+
This function has been removed. You can use `plugin.querySymbol()` instead. It accepts the same arguments and returns the same result.

.changeset/fine-flies-sink.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"@hey-api/openapi-ts": minor
3+
---
4+
5+
**plugin(zod)**: remove request data schema
6+
7+
### Validator request schemas
8+
9+
Zod plugin no longer exports composite request `Data` schemas. Instead, each layer is exported as a separate schema. If you're using validators with SDKs, you can preserve the composite schema with `shouldExtract`:
10+
11+
```js
12+
export default {
13+
input: 'hey-api/backend', // sign up at app.heyapi.dev
14+
output: 'src/client',
15+
plugins: [
16+
// ...other plugins
17+
{
18+
name: 'sdk',
19+
validator: 'zod',
20+
},
21+
{
22+
name: 'zod',
23+
requests: {
24+
shouldExtract: true,
25+
},
26+
},
27+
],
28+
};
29+
```

.changeset/happy-snails-strive.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(zod)**: export request body, path, query, and headers schemas

.changeset/short-things-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/shared": patch
3+
---
4+
5+
**plugins**: add request validator helpers

.changeset/small-beds-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(orpc)**: fix: adjust input shape

.changeset/thin-islands-happen.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(valibot)**: export request body, path, query, and headers schemas

docs/openapi-ts/migrating.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,63 @@ description: Migrating to @hey-api/openapi-ts.
77

88
While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues).
99

10+
## v0.95.0
11+
12+
### Validator request schemas
13+
14+
Valibot and Zod plugins no longer export composite request `Data` schemas. Instead, each layer is exported as a separate schema. If you're using validators with SDKs, you can preserve the composite schema with `shouldExtract`:
15+
16+
::: code-group
17+
18+
<!-- prettier-ignore-start -->
19+
```js [Zod]
20+
export default {
21+
input: 'hey-api/backend', // sign up at app.heyapi.dev
22+
output: 'src/client',
23+
plugins: [
24+
// ...other plugins
25+
{
26+
name: 'sdk',
27+
validator: 'zod',
28+
},
29+
{
30+
name: 'zod',
31+
requests: { // [!code ++]
32+
shouldExtract: true, // [!code ++]
33+
}, // [!code ++]
34+
},
35+
],
36+
};
37+
```
38+
<!-- prettier-ignore-end -->
39+
<!-- prettier-ignore-start -->
40+
```js [Valibot]
41+
export default {
42+
input: 'hey-api/backend', // sign up at app.heyapi.dev
43+
output: 'src/client',
44+
plugins: [
45+
// ...other plugins
46+
{
47+
name: 'sdk',
48+
validator: 'valibot',
49+
},
50+
{
51+
name: 'valibot',
52+
requests: { // [!code ++]
53+
shouldExtract: true, // [!code ++]
54+
}, // [!code ++]
55+
},
56+
],
57+
};
58+
```
59+
<!-- prettier-ignore-end -->
60+
61+
:::
62+
63+
### Removed `plugin.getSymbol()` function
64+
65+
This function has been removed. You can use `plugin.querySymbol()` instead. It accepts the same arguments and returns the same result.
66+
1067
## v0.93.0
1168

1269
### Removed resolver node

docs/openapi-ts/plugins/orpc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ For a more granular approach, manually add a validator plugin and set `validator
9999
```js [example]
100100
import { oc } from '@orpc/contract';
101101

102-
import { vAddPetData, vAddPetResponse } from './valibot.gen';
102+
import { vAddPetBody, vAddPetResponse } from './valibot.gen';
103103

104104
const addPet = oc
105105
.route({
@@ -111,7 +111,7 @@ const addPet = oc
111111
summary: 'Add a new pet to the store.',
112112
tags: ['pet'],
113113
})
114-
.input(vAddPetData) // [!code ++]
114+
.input(v.object({ body: vAddPetBody })) // [!code ++]
115115
.output(vAddPetResponse); // [!code ++]
116116
```
117117

docs/openapi-ts/plugins/valibot.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,21 @@ The Valibot plugin will generate the following artifacts, depending on the input
6868

6969
## Requests
7070

71-
A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers.
71+
A Valibot schema is generated for every request layer of each endpoint.
7272

7373
::: code-group
7474

7575
```ts [example]
76-
const vData = v.object({
77-
body: v.optional(
78-
v.object({
79-
foo: v.optional(v.string()),
80-
bar: v.optional(v.union([v.number(), v.null()])),
81-
}),
82-
),
83-
path: v.object({
84-
baz: v.string(),
85-
}),
86-
query: v.optional(v.never()),
76+
const vDeletePetHeaders = v.object({
77+
api_key: v.optional(v.string()),
78+
});
79+
80+
const vDeletePetPath = v.object({
81+
petId: v.number(),
82+
});
83+
84+
const vDeletePetQuery = v.object({
85+
additionalMetadata: v.string(),
8786
});
8887
```
8988

@@ -103,10 +102,6 @@ export default {
103102

104103
:::
105104

106-
::: tip
107-
If you need to access individual fields, you can do so using the [`.entries`](https://valibot.dev/api/object/) API. For example, we can get the request body schema with `vData.entries.body`.
108-
:::
109-
110105
You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.
111106

112107
## Responses

0 commit comments

Comments
 (0)