Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-points-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/arktype-validator': major
---

Align arktype validator behavior with zod validator: add target-aware input inference, case-insensitive header normalization, hook target support, and configurable validation/error formatting.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ settings.local.json

# Code editor
.zed

# MacOS
.DS_Store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@arethetypeswrong/core": "^0.18.2",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.29.7",
"@cloudflare/vitest-pool-workers": "https://pkg.pr.new/@cloudflare/vitest-pool-workers@11632",
"@cloudflare/vitest-pool-workers": "^0.12.6",
"@cloudflare/workers-types": "^4.20250612.0",
"@hono/eslint-config": "workspace:*",
"@ryoppippi/unplugin-typia": "^2.6.5",
Expand Down
8 changes: 0 additions & 8 deletions packages/arktype-validator/eslint-suppressions.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
{
"src/index.test.ts": {
"@typescript-eslint/no-unsafe-member-access": {
"count": 1
}
},
"src/index.ts": {
"@typescript-eslint/no-dynamic-delete": {
"count": 1
},
"@typescript-eslint/no-invalid-void-type": {
"count": 2
},
"@typescript-eslint/no-unsafe-argument": {
"count": 1
}
}
}
34 changes: 31 additions & 3 deletions packages/arktype-validator/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Basic', () => {
arktypeValidator(
'header',
type({
'User-Agent': 'string',
'User-Agent': 'number',
})
),
(c) => c.json({ success: true, userAgent: c.req.header('User-Agent') })
Expand Down Expand Up @@ -71,8 +71,7 @@ describe('Basic', () => {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type verify = Expect<Equal<Expected, Actual>>
// type verify = Expect<Equal<Expected, Actual>>

it('Should return 200 response', async () => {
const req = new Request('http://localhost/author?name=Metallo', {
Expand Down Expand Up @@ -127,6 +126,35 @@ describe('Basic', () => {
})
})

describe('Case-Insensitive Headers', () => {
it('Should ignore the case for headers in the ArkType schema and return 200', async () => {
const app = new Hono()
const headerSchema = type({
'User-Agent': 'string',
ApiKey: 'string',
onlylowercase: 'string',
ONLYUPPERCASE: 'string',
})

app.get('/', arktypeValidator('header', headerSchema), (c) => {
const headers = c.req.valid('header')
return c.json(headers)
})

const res = await app.request('http://localhost/', {
headers: {
'user-agent': 'my-agent',
apikey: 'secret',
onlylowercase: 'lower',
onlyuppercase: 'upper',
},
})

expect(res).not.toBeNull()
expect(res.status).toBe(200)
})
})

describe('With Hook', () => {
const app = new Hono()

Expand Down
Loading