npm hono 2.3.2
v2.3.2

latest releases: 4.6.9, 4.6.8, 4.6.7...
2 years ago

Summary

Fixed a bug related to the Validator and added a minor feature.

The Validator type is exported. You can write your schema definition outside the middleware handler as follows:

import type { Validator } from 'hono'
import { validator } from 'hono/validator'

const schema = (v: Validator) => ({
  query: v.query('query').isRequired(),
  page: v.query('page').isNumeric().isOptional(),
})

app.get('/search', validator(schema), (c) => {
  const { query, page } = c.req.valid()
  //...
  return c.text('Result!!')
})

Validator and validator are similar and confusing, but if you don't like it, just use an alias.

What's Changed

  • fix(validator): make "isOptional" work correctly with "value" validation by @yusukebe in #613
  • docs(migration): add v2.2.5 to v2.3.0 by @yusukebe in #617
  • docs(contribution): update about 3rd-party middleware by @yusukebe in #619
  • refactor(types): refactor and add tests for checking Types by @yusukebe in #615
  • test(validator): add test for custom rules by @yusukebe in #620
  • fix(deno): export static-router and smart-router by @yusukebe in #626
  • feat(validator): export Validator from 'hono' by @yusukebe in #627

Full Changelog: v2.3.1...v2.3.2

Don't miss a new hono release

NewReleases is sending notifications on new releases.