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

fix(valibot-validator): Fix response query types on RPC #914

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

ajotaos
Copy link
Contributor

@ajotaos ajotaos commented Dec 27, 2024

This middleware addresses #899.

Copy link

changeset-bot bot commented Dec 27, 2024

🦋 Changeset detected

Latest commit: 72ce1ce

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

This PR includes changesets to release 1 package
Name Type
@hono/valibot-validator Patch

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

if (!result.success) {
return c.json(result, 400)
if (!parsed.success) {
return c.json({
Copy link
Member

Choose a reason for hiding this comment

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

The tests fail. If you change these lines like them, it is fixed. Is it OK?

if (!parsed.success) {
  return c.json(parsed, 400)
}

@yusukebe
Copy link
Member

Hi @ajotaos

Can you add a test like this?

diff --git a/packages/valibot-validator/test/index.test.ts b/packages/valibot-validator/test/index.test.ts
index d50fd78..2c16d76 100644
--- a/packages/valibot-validator/test/index.test.ts
+++ b/packages/valibot-validator/test/index.test.ts
@@ -324,3 +324,28 @@ describe('With Hook Async', () => {
     expect(res.status).toBe(400)
   })
 })
+
+describe('Test types', () => {
+  it('Should return correct types when validating a query', () => {
+    const app = new Hono()
+
+    const routes = app.post(
+      '/',
+      vValidator(
+        'query',
+        object({
+          foo: string(),
+        })
+      ),
+      (c) => {
+        return c.json(c.req.valid('query'))
+      }
+    )
+
+    type T = ExtractSchema<typeof routes>
+
+    type Actual = T['/']['$post']['input']['query']
+    type Expected = { foo: string }
+    type verify = Expect<Equal<Expected, Actual>>
+  })
+})

@ajotaos
Copy link
Contributor Author

ajotaos commented Jan 7, 2025

Hi @yusukebe, sorry for the delay on this update. Had already gone home for the holidays.

The changes you suggested were added. Thank you about it.

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 Jan 8, 2025

@ajotaos

Thanks! Looks good to me. I'll merge it and release a new version.

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