Describe the bug
I can't seem to figure out how to make body object's optional but their properties mandatory.
To Reproduce
checkSchema({
a: {
in: ["body"],
optional: true,
custom: {
options: (value) => validateRect(value),
errorMessage: "Invalid a",
},
},
"a.x": {
in: ["body"],
optional: false,
isInt: {
options: { min: 0 },
errorMessage: "a x must be a non-negative integer",
},
},
});
Expected behavior
The behavior I want is for a body no a to pass validation BUT a body with an empty a to fail, eg:
pass:
{}
fail:
{
a: {}
}
pass:
{
a: {
x: 1
}
}
Environment (please complete the following information):
express-validator 7.2.0
Operating system: WSL
Prerequisite
are you able to run jest from the command line? yes?
where do you run jest CLI from? [e.g., root directory of the project]
how do you run your tests from the command line? (e.g., "npm run test" or "node_modules/.bin/jest")
Additional context
Thanks for helping - I know I can create a custom validator for the object - i was just wondering if there was a way to achieve this behaviour without.
The fastest (and the most fun) way to resolve the issue is to submit a pull request yourself. If you are interested, please check out the contribution guide, we look forward to seeing your PR...
Describe the bug I can't seem to figure out how to make body object's optional but their properties mandatory.
To Reproduce
Expected behavior The behavior I want is for a body no
a
to pass validation BUT a body with an emptya
to fail, eg:pass:
fail:
pass:
Environment (please complete the following information):
Prerequisite
Additional context
Thanks for helping - I know I can create a custom validator for the object - i was just wondering if there was a way to achieve this behaviour without.
The fastest (and the most fun) way to resolve the issue is to submit a pull request yourself. If you are interested, please check out the contribution guide, we look forward to seeing your PR...