-
-
Notifications
You must be signed in to change notification settings - Fork 850
feat(validator)!: warn when validator does not find a valid content type in the request #4109
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Soviut <[email protected]>
Co-authored-by: Soviut <[email protected]>
|
hi @Soviut Combine middleware now handles multiple validator types well. |
|
E.x. describe('JSON and FormData', () => {
const app = new Hono()
app.post(
'/',
some(
validator('json', (value) => value),
validator('form', (value) => value)
),
async (c) => {
const jsonData = c.req.valid('json')
const formData = c.req.valid('form')
return c.json({
json: jsonData,
form: formData,
})
}
)
it('Should validate a JSON request', async () => {
const res = await app.request('/', {
method: 'POST',
body: JSON.stringify({ foo: 'bar' }),
headers: {
'Content-Type': 'application/json',
},
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.json).toEqual({ foo: 'bar' })
})
it('Should validate a FormData request', async () => {
const form = new FormData()
form.append('foo', 'bar')
const res = await app.request('/', {
method: 'POST',
body: form,
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.form).toEqual({ foo: 'bar' })
})
}) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4109 +/- ##
=======================================
Coverage 91.30% 91.31%
=======================================
Files 168 168
Lines 10780 10787 +7
Branches 3085 3095 +10
=======================================
+ Hits 9843 9850 +7
Misses 936 936
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The problem here is that in |
Related: #3707
The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code