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

Merged
merged 16 commits into from
Nov 8, 2024

Conversation

pr0m3th3usEx
Copy link
Contributor

@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: a1b6f15

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 pr0m3th3usEx requested a review from yusukebe November 5, 2024 12:29
@pr0m3th3usEx
Copy link
Contributor Author

@yusukebe I made the changes

@pr0m3th3usEx
Copy link
Contributor Author

@yusukebe Done

@pr0m3th3usEx pr0m3th3usEx requested a review from yusukebe November 7, 2024 00:08
@pr0m3th3usEx pr0m3th3usEx requested a review from yusukebe November 7, 2024 13:31
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Nov 8, 2024

@pr0m3th3usEx

Looks good to me. Let's ship it! Thanks.

@yusukebe yusukebe merged commit a5c20b3 into honojs:main Nov 8, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Nov 8, 2024
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