The screenshot API for developers -
Try ScreenshotOne
Skip to content

Valibot Integration

Valibot implements Standard Schema, so you can use it directly in your procedures without any extra setup. On top of that, @orpc/valibot provides a dedicated JSON Schema converter.

Installation

sh
npm install @orpc/valibot@beta valibot
sh
yarn add @orpc/valibot@beta valibot
sh
pnpm add @orpc/valibot@beta valibot
sh
bun add @orpc/valibot@beta valibot
sh
deno add npm:@orpc/valibot@beta npm:valibot

JSON Schema Converter

ValibotToJsonSchemaConverter wraps Valibot's built-in toJsonSchema and adds support for additional types such as v.bigint(), v.date(), v.set(), and v.map(). Use it with tools such as the OpenAPI Generator and Smart Coercion. It accepts the same options as Valibot's toJsonSchema, see the source code for implementation details.

ts
import { OpenAPIGenerator } from '@orpc/openapi'
import { ValibotToJsonSchemaConverter } from '@orpc/valibot'

const generator = new OpenAPIGenerator({
  converters: [new ValibotToJsonSchemaConverter()],
})

Reusable Schemas

A common pattern is defining reusable or recursive schemas via definitions. The converter preserves them in $defs, which OpenAPIGenerator can then hoist into components.schemas. For more on how definitions work in Valibot, see Valibot JSON Schema Definitions.

ts
import * as v from 'valibot'

const PlanetSchema = v.object({
  id: v.string(),
  name: v.string(),
})

const generator = new OpenAPIGenerator({
  converters: [
    new ValibotToJsonSchemaConverter({
      definitions: { PlanetSchema },
    }),
  ],
})

Released under the MIT License.