express-validator
express-validator copied to clipboard
Is checkExact() with wildcards supported?
Hi all,
quick question: Is the checkExact() middleware supported for wildcards?
E.g. consider the following scenario:
I need to validate a body that looks something like this:
const body = [
{
id: 1,
qty: 100
},
{
id: 2,
qty: 100
}
]
-> So essentially an array of objects with an id and qty property.
I can nicely check for validity with the following chain
body()
.isArray(),
body("*")
.isObject(),
body("*.id")
.isInt(),
body("*.qty")
.isInt(),
Adding checkExact()
to the end of the chain above however does not seem to cause the following example to fail validation, despite it having one additional unwanted property (wrong
) in the second object:
const body = [
{
id: 1,
qty: 100
},
{
id: 2,
wrong: 1,
qty: 100
}
]
So I wonder: is this scenario even supported currently, or am I running into a bug (or maybe I am doing something wrong?)
thanks in advance
Kind regards,
Pano
Facing same challenge. checkExact does not work when request is validated for array level in checkSchema.
Facing same problem here. I'm doing this:
app.post(
"/signup",
checkExact([
body("addresses").isObject(),
body("addresses.*.number").isInt(),
body("siblings.*.name").notEmpty(),
]),
(req, res) => {
validationResult(req).throw()
res.json({
msg: "Sucess",
})
}
)
but there is no throwed error when I send this:
{
"addresses": {
"home": {
"number": 35
},
"work": {
"number": 501,
"wrong": "yes"
}
},
"siblings": [
{
"name": "Maria von Validator"
},
{
"name": "Checky McCheckFace"
}
]
}
I'm investigating