···33description: Valibot plugin for Hey API. Compatible with all our features.
44---
5566-# Valibot <span data-soon>soon</span>
66+# Valibot
7788::: warning
99-This feature isn't in development yet. Help us prioritize it by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues/1474).
99+This feature is in development! :tada: Try it out and provide feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues/1474).
1010:::
11111212### About
13131414[Valibot](https://valibot.dev) is the open source schema library for TypeScript with bundle size, type safety and developer experience in mind.
15151616+<!-- ### Demo
1717+1818+<button class="buttonLink" @click="(event) => embedProject('hey-api-client-fetch-plugin-valibot-example')(event)">
1919+Launch demo
2020+</button> -->
2121+2222+## Features
2323+2424+- seamless integration with `@hey-api/openapi-ts` ecosystem
2525+- Valibot schemas for requests, responses, and reusable components
2626+2727+## Installation
2828+2929+In your [configuration](/openapi-ts/get-started), add `valibot` to your plugins and you'll be ready to generate Valibot artifacts. :tada:
3030+3131+```js
3232+import { defaultPlugins } from '@hey-api/openapi-ts';
3333+3434+export default {
3535+ input: 'https://get.heyapi.dev/hey-api/backend',
3636+ output: 'src/client',
3737+ plugins: [
3838+ ...defaultPlugins,
3939+ '@hey-api/client-fetch',
4040+ 'valibot', // [!code ++]
4141+ ],
4242+};
4343+```
4444+4545+## SDKs
4646+4747+To automatically validate response data in your SDKs, set `sdk.validator` to `true`.
4848+4949+```js
5050+import { defaultPlugins } from '@hey-api/openapi-ts';
5151+5252+export default {
5353+ input: 'https://get.heyapi.dev/hey-api/backend',
5454+ output: 'src/client',
5555+ plugins: [
5656+ ...defaultPlugins,
5757+ '@hey-api/client-fetch',
5858+ 'valibot',
5959+ {
6060+ name: '@hey-api/sdk', // [!code ++]
6161+ validator: true, // [!code ++]
6262+ },
6363+ ],
6464+};
6565+```
6666+6767+## Output
6868+6969+The Valibot plugin will generate the following artifacts, depending on the input specification.
7070+7171+## Schemas
7272+7373+More information will be provided as we finalize the plugin.
7474+7575+<!--@include: ../../examples.md-->
1676<!--@include: ../../sponsors.md-->
+1-1
docs/openapi-ts/validators.md
···13131414Hey API natively supports the following validators.
15151616+- [Valibot](/openapi-ts/plugins/valibot)
1617- [Zod](/openapi-ts/plugins/zod)
1718- [Ajv](/openapi-ts/plugins/ajv) <span data-soon>Soon</span>
1819- [Arktype](/openapi-ts/plugins/arktype) <span data-soon>Soon</span>
1920- [Joi](/openapi-ts/plugins/joi) <span data-soon>Soon</span>
2021- [TypeBox](/openapi-ts/plugins/typebox) <span data-soon>Soon</span>
2121-- [Valibot](/openapi-ts/plugins/valibot) <span data-soon>Soon</span>
2222- [Yup](/openapi-ts/plugins/yup) <span data-soon>Soon</span>
23232424Don't see your validator? Let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { ClientOptions } from './types.gen';
44+import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
55+66+/**
77+ * The `createClientConfig()` function will be called on client initialization
88+ * and the returned object will become the client's initial configuration.
99+ *
1010+ * You may want to initialize your client this way instead of calling
1111+ * `setConfig()`. This is useful for example if you're using Next.js
1212+ * to ensure your client always has the correct values.
1313+ */
1414+export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
1515+1616+export const client = createClient(createConfig<ClientOptions>());
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
44+import type { PostFooData, PostFooResponse } from './types.gen';
55+import { postFooResponseTransformer } from './transformers.gen';
66+import { vPostFooResponse } from './valibot.gen';
77+import * as v from 'valibot';
88+import { client as _heyApiClient } from './client.gen';
99+1010+export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
1111+ /**
1212+ * You can provide a client instance returned by `createClient()` instead of
1313+ * individual options. This might be also useful if you want to implement a
1414+ * custom client.
1515+ */
1616+ client?: Client;
1717+ /**
1818+ * You can pass arbitrary values through the `meta` object. This can be
1919+ * used to access values that aren't defined as part of the SDK function.
2020+ */
2121+ meta?: Record<string, unknown>;
2222+};
2323+2424+export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => {
2525+ return (options?.client ?? _heyApiClient).post<PostFooResponse, unknown, ThrowOnError>({
2626+ responseTransformer: postFooResponseTransformer,
2727+ responseValidator: async (data) => {
2828+ return await v.parseAsync(vPostFooResponse, data);
2929+ },
3030+ url: '/foo',
3131+ ...options
3232+ });
3333+};
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { ClientOptions } from './types.gen';
44+import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
55+66+/**
77+ * The `createClientConfig()` function will be called on client initialization
88+ * and the returned object will become the client's initial configuration.
99+ *
1010+ * You may want to initialize your client this way instead of calling
1111+ * `setConfig()`. This is useful for example if you're using Next.js
1212+ * to ensure your client always has the correct values.
1313+ */
1414+export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
1515+1616+export const client = createClient(createConfig<ClientOptions>());
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
44+import type { PostFooData, PostFooResponse } from './types.gen';
55+import { postFooResponseTransformer } from './transformers.gen';
66+import { vPostFooResponse } from './valibot.gen';
77+import * as v from 'valibot';
88+import { client as _heyApiClient } from './client.gen';
99+1010+export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
1111+ /**
1212+ * You can provide a client instance returned by `createClient()` instead of
1313+ * individual options. This might be also useful if you want to implement a
1414+ * custom client.
1515+ */
1616+ client?: Client;
1717+ /**
1818+ * You can pass arbitrary values through the `meta` object. This can be
1919+ * used to access values that aren't defined as part of the SDK function.
2020+ */
2121+ meta?: Record<string, unknown>;
2222+};
2323+2424+export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => {
2525+ return (options?.client ?? _heyApiClient).post<PostFooResponse, unknown, ThrowOnError>({
2626+ responseTransformer: postFooResponseTransformer,
2727+ responseValidator: async (data) => {
2828+ return await v.parseAsync(vPostFooResponse, data);
2929+ },
3030+ url: '/foo',
3131+ ...options
3232+ });
3333+};
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { ClientOptions } from './types.gen';
44+import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
55+66+/**
77+ * The `createClientConfig()` function will be called on client initialization
88+ * and the returned object will become the client's initial configuration.
99+ *
1010+ * You may want to initialize your client this way instead of calling
1111+ * `setConfig()`. This is useful for example if you're using Next.js
1212+ * to ensure your client always has the correct values.
1313+ */
1414+export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
1515+1616+export const client = createClient(createConfig<ClientOptions>());
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
44+import type { PostFooData, PostFooResponse } from './types.gen';
55+import { postFooResponseTransformer } from './transformers.gen';
66+import { vPostFooResponse } from './valibot.gen';
77+import * as v from 'valibot';
88+import { client as _heyApiClient } from './client.gen';
99+1010+export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
1111+ /**
1212+ * You can provide a client instance returned by `createClient()` instead of
1313+ * individual options. This might be also useful if you want to implement a
1414+ * custom client.
1515+ */
1616+ client?: Client;
1717+ /**
1818+ * You can pass arbitrary values through the `meta` object. This can be
1919+ * used to access values that aren't defined as part of the SDK function.
2020+ */
2121+ meta?: Record<string, unknown>;
2222+};
2323+2424+export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => {
2525+ return (options?.client ?? _heyApiClient).post<PostFooResponse, unknown, ThrowOnError>({
2626+ responseTransformer: postFooResponseTransformer,
2727+ responseValidator: async (data) => {
2828+ return await v.parseAsync(vPostFooResponse, data);
2929+ },
3030+ url: '/foo',
3131+ ...options
3232+ });
3333+};
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import * as v from 'valibot';
44+55+export const vFoo = v.object({
66+ foo: v.optional(v.pipe(v.bigint(), v.minValue(BigInt(0)), v.maxValue(BigInt(100))))
77+});
···11+// import type { IR } from '../../ir/types';
22+import type { Plugin } from '../types';
33+44+export interface Config extends Plugin.Name<'valibot'> {
55+ /**
66+ * Should the exports from the generated files be re-exported in the index
77+ * barrel file?
88+ *
99+ * @default false
1010+ */
1111+ exportFromIndex?: boolean;
1212+ /**
1313+ * Customise the Valibot schema name. By default, `v{{name}}` is used,
1414+ * where `name` is a definition name or an operation name.
1515+ */
1616+ // nameBuilder?: (model: IR.OperationObject | IR.SchemaObject) => string;
1717+ /**
1818+ * Name of the generated file.
1919+ *
2020+ * @default 'valibot'
2121+ */
2222+ output?: string;
2323+}