Skip to content
Plugin
Valibot logo
plugins: [pluginValibot()]
OfficialBetav0.1.0kubb >=5.19.0node >=22.22

OpenAPI to Valibot schema generator

@kubb/plugin-valibot

Generates Valibot v1 schemas from your OpenAPI spec so you validate API responses, form input, and query params at runtime.

kubb add plugin-valibot
valibotvalidationschemaruntime-validationcodegenopenapi

The Valibot plugin generates a Valibot v1 schema for every schema in your OpenAPI spec, plus the parameter, request, and response schemas of each operation.

Every generated schema is a Standard Schema, so any library that takes one can validate with it.

@kubb/plugin-fetch, @kubb/plugin-axios, and @kubb/plugin-client validate with these schemas when you set their validator option to 'valibot'.

Installation

kubb add plugin-valibot

kubb add installs the version the Kubb registry pins and adds pluginValibot() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

  • No other plugins are needed.
  • Install valibot 1.2 or later in the app that uses the generated code.

Options worth knowing

OptionDefaultWhat it does
inferredfalseAdds a type next to each schema, so you can skip @kubb/plugin-ts.
coercionfalseConverts input before validation, such as query strings.
typeGuardsfalseAdds is* type guards and assert* assertions.
printerNoneReplaces the Valibot call for a schema type.

Example

This config generates the schemas with a v.InferOutput type next to each one. For a Pet schema, the plugin writes petSchema.ts:

import { defineConfig } from 'kubb/config'
import { pluginValibot } from '@kubb/plugin-valibot'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [pluginValibot({ inferred: true })],
})

Guides

Differences from the Zod plugin

The two plugins share option names, generated names, and file layout. These Zod options have no Valibot counterpart:

Zod optionIn this plugin
guidTypeNot needed. v.uuid() checks the shape only, so it already accepts any GUID.
inferred: 'codec'Always on. A request schema gets v.InferInput and every other schema v.InferOutput.
compile and miniZod features. Valibot is modular by default.

Dependencies

No extension dependencies.