koajs / koajs/parameter

Validate non-string parameters

Open
#12 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
67
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Since Koa's ctx.query object has every query parameter set to a string value, this middleware is throwing an error when I attempt to validate a query parameter that should be an integer. For instance, if my URI has a query parameter like `?limit=5` and then I do `ctx.verifyParams({ limit: 'int' });` an error is thrown because ctx.query is `{ limit: '5' }`. Is there a way to tell the middleware to attempt to coerce the query parameter's value to the expected type from a string before the validation occurs or a separate middleware that would perform this?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported validation failure with a Koa query value such as `?limit=5` and `ctx.verifyParams({ limit: 'int' })`. The issue does not identify files or tests; done would require a decided behavior for coercion or a separate middleware and validation that the chosen behavior works.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.