Open
Description
What is the feature you are proposing?
Related: honojs/middleware#887
Standard Schema is a spec to make APIs of JavaScript validators unified. I'd like to propose adding Standard Schema support to hono/validator
.
import { validator } from 'hono/validator'
import z from 'zod'
import * as v from 'valibot'
import { type } from 'arktype'
app.post('/zod', validator('json', z.number()), ...)
app.post('/valibot', validator('json', v.number()), ...)
app.post('/arktype', validator('json', type('number')), ...)
Currently, we can use this with @hono/standard-validator
as a 3rd party middleware, but using it needs to install another package. It can be a little troublesome.
Some frameworks are using Standard Schema natively1 and they are increasing (Astro 6.0 may support Standard Schema2). I think this will be a moderate incentive to use the frameworks supporting Standard Schema.
Pros
- We will be able to use our favorite validators without installing other dependencies.
- The amount of code to implement it is very short so we don't need to worry about bundled size.
Cons
- Currently
hono/validator
provides very simple APIs and uses minimal algorithm. This can be broken with implementing this. - Standard Schema is not a Web Standard.