You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to keep keys for optional fields in request body in matchedData return value.
To Reproduce
Let's say we have user model.
interface User {
firstName?: string;
lastName?: string;
email: string
}
In frontend, user removed first name. and other fields are not changed.
So frontend sends request with only changed fields.
{"firstName": null}
In this case matchedData function returns empty JSON, but I would like to keep firstName key.
There is a parameter called includeOptional, but if we set that parameter to True, matchedData function returns JSON which contains both firstName and lastName as key.
{
"firstName": null,
"lastName": null
}
Moreover, I think it's more accurate that if keys exist in both request and validation schema, it should exist in matchedData return value.
Environment:
Express-validator version: 7.0.1
Express version: 4.18.2
Node.js version: 20.11.0
The text was updated successfully, but these errors were encountered:
Describe the bug
I want to keep keys for optional fields in request body in
matchedData
return value.To Reproduce
Let's say we have user model.
In frontend, user removed first name. and other fields are not changed.
So frontend sends request with only changed fields.
In this case
matchedData
function returns empty JSON, but I would like to keepfirstName
key.There is a parameter called
includeOptional
, but if we set that parameter to True,matchedData
function returns JSON which contains bothfirstName
andlastName
as key.Moreover, I think it's more accurate that if keys exist in both request and validation schema, it should exist in
matchedData
return value.Environment:
The text was updated successfully, but these errors were encountered: