I'm currently using a body-parser middleware, and it transforms an undefined body into an empty object ({}).
This causes a validation problem when a body is marked as optional.
Example
@Post('')
myMethod(@Body() body?: {foo: boolean}){
...
}
If the user does not send a body, body-parser will inject {} into request.body, then getValidatedArgs will test the schema on an empty object instead of undefined, which will throw a ValidateError because foo is marked as required.
I'm currently using a
body-parsermiddleware, and it transforms anundefinedbody into an empty object ({}).This causes a validation problem when a body is marked as optional.
Example
If the user does not send a body,
body-parserwill inject{}intorequest.body, thengetValidatedArgswill test the schema on an empty object instead of undefined, which will throw aValidateErrorbecausefoois marked as required.