Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .changeset/eighty-suns-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@hey-api/openapi-ts": minor
---

**plugin(valibot)**: remove request data schema

### Validator request schemas

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`:

```js
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
plugins: [
// ...other plugins
{
name: 'sdk',
validator: 'valibot',
},
{
name: 'valibot',
requests: {
shouldExtract: true,
},
},
],
};
```
10 changes: 10 additions & 0 deletions .changeset/every-vans-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@hey-api/openapi-ts": minor
"@hey-api/shared": minor
---

**internal**: remove `plugin.getSymbol()` function

### Removed `plugin.getSymbol()` function

This function has been removed. You can use `plugin.querySymbol()` instead. It accepts the same arguments and returns the same result.
29 changes: 29 additions & 0 deletions .changeset/fine-flies-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@hey-api/openapi-ts": minor
---

**plugin(zod)**: remove request data schema

### Validator request schemas

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`:

```js
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
plugins: [
// ...other plugins
{
name: 'sdk',
validator: 'zod',
},
{
name: 'zod',
requests: {
shouldExtract: true,
},
},
],
};
```
5 changes: 5 additions & 0 deletions .changeset/happy-snails-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**plugin(zod)**: export request body, path, query, and headers schemas
5 changes: 5 additions & 0 deletions .changeset/short-things-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/shared": patch
---

**plugins**: add request validator helpers
5 changes: 5 additions & 0 deletions .changeset/small-beds-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**plugin(orpc)**: fix: adjust input shape
5 changes: 5 additions & 0 deletions .changeset/thin-islands-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**plugin(valibot)**: export request body, path, query, and headers schemas
57 changes: 57 additions & 0 deletions docs/openapi-ts/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,63 @@ description: Migrating to @hey-api/openapi-ts.

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).

## v0.95.0

### Validator request schemas

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`:

::: code-group

<!-- prettier-ignore-start -->
```js [Zod]
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
plugins: [
// ...other plugins
{
name: 'sdk',
validator: 'zod',
},
{
name: 'zod',
requests: { // [!code ++]
shouldExtract: true, // [!code ++]
}, // [!code ++]
},
],
};
```
<!-- prettier-ignore-end -->
<!-- prettier-ignore-start -->
```js [Valibot]
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
plugins: [
// ...other plugins
{
name: 'sdk',
validator: 'valibot',
},
{
name: 'valibot',
requests: { // [!code ++]
shouldExtract: true, // [!code ++]
}, // [!code ++]
},
],
};
```
<!-- prettier-ignore-end -->

:::

### Removed `plugin.getSymbol()` function

This function has been removed. You can use `plugin.querySymbol()` instead. It accepts the same arguments and returns the same result.

## v0.93.0

### Removed resolver node
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi-ts/plugins/orpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ For a more granular approach, manually add a validator plugin and set `validator
```js [example]
import { oc } from '@orpc/contract';

import { vAddPetData, vAddPetResponse } from './valibot.gen';
import { vAddPetBody, vAddPetResponse } from './valibot.gen';

const addPet = oc
.route({
Expand All @@ -111,7 +111,7 @@ const addPet = oc
summary: 'Add a new pet to the store.',
tags: ['pet'],
})
.input(vAddPetData) // [!code ++]
.input(v.object({ body: vAddPetBody })) // [!code ++]
.output(vAddPetResponse); // [!code ++]
```

Expand Down
27 changes: 11 additions & 16 deletions docs/openapi-ts/plugins/valibot.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,21 @@ The Valibot plugin will generate the following artifacts, depending on the input

## Requests

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

::: code-group

```ts [example]
const vData = v.object({
body: v.optional(
v.object({
foo: v.optional(v.string()),
bar: v.optional(v.union([v.number(), v.null()])),
}),
),
path: v.object({
baz: v.string(),
}),
query: v.optional(v.never()),
const vDeletePetHeaders = v.object({
api_key: v.optional(v.string()),
});

const vDeletePetPath = v.object({
petId: v.number(),
});

const vDeletePetQuery = v.object({
additionalMetadata: v.string(),
});
```

Expand All @@ -103,10 +102,6 @@ export default {

:::

::: tip
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`.
:::

You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.

## Responses
Expand Down
27 changes: 11 additions & 16 deletions docs/openapi-ts/plugins/zod.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,21 @@ The Zod plugin will generate the following artifacts, depending on the input spe

## Requests

A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers.
A Zod schema is generated for every request layer of each endpoint.

::: code-group

```ts [example]
const zData = z.object({
body: z
.object({
foo: z.optional(z.string()),
bar: z.optional(z.union([z.number(), z.null()])),
})
.optional(),
path: z.object({
baz: z.string(),
}),
query: z.optional(z.never()),
const zDeletePetHeaders = z.object({
api_key: z.string().optional(),
});

const zDeletePetPath = z.object({
petId: z.number(),
});

const zDeletePetQuery = z.object({
additionalMetadata: z.string(),
});
```

Expand All @@ -103,10 +102,6 @@ export default {

:::

::: tip
If you need to access individual fields, you can do so using the [`.shape`](https://zod.dev/api?id=shape) API. For example, we can get the request body schema with `zData.shape.body`.
:::

You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.

## Responses
Expand Down
27 changes: 11 additions & 16 deletions docs/openapi-ts/plugins/zod/mini.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,21 @@ The Zod plugin will generate the following artifacts, depending on the input spe

## Requests

A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers.
A Zod schema is generated for every request layer of each endpoint.

::: code-group

```ts [example]
const zData = z.object({
body: z
.object({
foo: z.optional(z.string()),
bar: z.optional(z.union([z.number(), z.null()])),
})
.optional(),
path: z.object({
baz: z.string(),
}),
query: z.optional(z.never()),
const zDeletePetHeaders = z.object({
api_key: z.optional(z.string()),
});

const zDeletePetPath = z.object({
petId: z.number(),
});

const zDeletePetQuery = z.object({
additionalMetadata: z.string(),
});
```

Expand All @@ -110,10 +109,6 @@ export default {

:::

::: tip
If you need to access individual fields, you can do so using the [`.def.shape`](https://zod.dev/api?id=shape) API. For example, we can get the request body schema with `zData.def.shape.body`.
:::

You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.

## Responses
Expand Down
27 changes: 11 additions & 16 deletions docs/openapi-ts/plugins/zod/v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,21 @@ The Zod plugin will generate the following artifacts, depending on the input spe

## Requests

A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers.
A Zod schema is generated for every request layer of each endpoint.

::: code-group

```ts [example]
const zData = z.object({
body: z
.object({
foo: z.string().optional(),
bar: z.union([z.number(), z.null()]).optional(),
})
.optional(),
path: z.object({
baz: z.string(),
}),
query: z.never().optional(),
const zDeletePetHeaders = z.object({
api_key: z.string().optional(),
});

const zDeletePetPath = z.object({
petId: z.number(),
});

const zDeletePetQuery = z.object({
additionalMetadata: z.string(),
});
```

Expand All @@ -110,10 +109,6 @@ export default {

:::

::: tip
If you need to access individual fields, you can do so using the [`.shape`](https://v3.zod.dev/?id=shape) API. For example, we can get the request body schema with `zData.shape.body`.
:::

You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options.

## Responses
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IR, NamingConfig, SchemaProcessorContext } from '@hey-api/shared';
import type { NamingConfig, SchemaProcessorContext } from '@hey-api/shared';

import type { PydanticPlugin } from '../types';
import type { PydanticFinal } from './types';
Expand All @@ -9,7 +9,6 @@ export type ProcessorContext = SchemaProcessorContext & {
naming: NamingConfig;
/** The plugin instance. */
plugin: PydanticPlugin['Instance'];
schema: IR.SchemaObject;
};

export type ProcessorResult = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createProcessor(plugin: PydanticPlugin['Instance']): ProcessorRe
}

for (const hook of extractorHooks) {
const result = hook?.(ctx);
const result = typeof hook === 'boolean' ? hook : (hook?.(ctx) ?? false);
if (result) {
process({
namingAnchor: processor.context.anchor,
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-python/src/plugins/pydantic/v2/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface VisitorConfig {
}

export function createVisitor(
config: VisitorConfig,
config: VisitorConfig = {},
): SchemaVisitor<PydanticResult, PydanticPlugin['Instance']> {
const { schemaExtractor } = config;

Expand Down
Loading
Loading