Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: class validator middleware for Hono #788

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

pr0m3th3usEx
Copy link

@pr0m3th3usEx pr0m3th3usEx commented Oct 22, 2024

This middleware enables validation using class-validator & class-transformer packages.

Example

import { classValidator } from '@hono/class-validator'
import { IsInt, IsString } from 'class-validator'
 
class CreateUserDto {
  @IsString()
  name!: string;
 
  @IsInt()
  age!: number;
}
 
 
const route = app.post('/user', classValidator('json', CreateUserDto), (c) => {
  const user = c.req.valid('json')
  return c.json({ success: true, message: `${user.name} is ${user.age}` })
})

Copy link

changeset-bot bot commented Oct 22, 2024

🦋 Changeset detected

Latest commit: da23e9c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/class-validator Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

packages/class-validator/package.json Outdated Show resolved Hide resolved
packages/class-validator/package.json Outdated Show resolved Hide resolved
.github/workflows/ci-class-validator.yml Outdated Show resolved Hide resolved
@yusukebe
Copy link
Member

yusukebe commented Nov 5, 2024

Hi @pr0m3th3usEx

I've left the comments. Please check them!

change to tsup for build

fix ci name
@pr0m3th3usEx
Copy link
Author

@yusukebe I made the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants