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
Validate json object #1264
Comments
Hey, express-validator/src/express-validator.spec.ts Lines 158 to 163 in 28a8d5f
...but this might be weird when you're not near the HTTP layer of your application (e.g. "why does this object have a body/cookie/query/header/param property") You might like using pure validator.js instead: https://github.com/validatorjs/validator.js/ Then there are plenty other libraries for object validation out there. |
@gustavohenke do we want to make a shift allowing validations to run on express requests and on plain json objects too? It shouldn't be too tricky to implement and would provide a nice wrapper over validator.js. |
I think that would be great.
The problem I'm trying to solve is that I have the validator chains already
built and in a library I share between projects and I want to reuse them as
much as possible, now I want to use the same chains to validate rows from a
csv upload.
And I would like every row in the CSV to be validated with the same chains
I use for the post request.
…On Sun, 19 Nov 2023, 10:06 Federico Ciardi, ***@***.***> wrote:
@gustavohenke <https://github.com/gustavohenke> do we want to make a
shift allowing validations to run on express requests and on plain json
objects too? It shouldn't be too tricky to implement and would provide a
nice wrapper over validator.js.
—
Reply to this email directly, view it on GitHub
<#1264 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAANKL4PDI42QV6QKGXRTNDYFHK2NAVCNFSM6AAAAAA7JN573CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJXHAYDOOJRHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Yeah, I think this can be done. I'm marking this issue as an enhancement then, but please note it might take a few weeks/months before I'm able to get around to working on it @syco |
That's great news, thanks |
I may do that this week. It shouldn't take me more than a couple hours to get it working. |
Hi,
is it possible to use an array of chains
[body('xx').isInt(), body('yy').isString()]
or similar, against a json object instead of the request object?I have complex validation arrays already built and I'm in the situation where I need to validate objects coming from a different source, not from an http request.
Would be great if I could use a logic like
const result = validationResult(object, [body('xx').isInt(), body('yy').isString()]);
Thanks
The text was updated successfully, but these errors were encountered: