routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

Custom param decorator with required set to true does not throw an error if value is undefined

Open prodigga opened this issue 4 years ago • 1 comments

function RejectAlways(){
    return createParamDecorator({
        required: true,
        value: action =>{
        }
    })
}

@JsonController()
export class TestController
{
    @Get("/test")
    public async GetTest(@RejectAlways() someValue:String){
        return {status:"All good chief"};
    }
}

Sending a GET request to /test results in {status:"All good chief"}. Shouldn't this throw an error?

action with return undefined doesn't work, either.

Using 0.8.1. Typescript 3.8.3.

createParamDecorator example in readme says:

here you'll have user authorized and you can safely save your question in the case if user returned your undefined from the database and "required"parameter was set, routing-controllers will throw you ParameterRequired error

prodigga avatar May 08 '20 09:05 prodigga

Just FYI in case anyone comes across this issue, the bug definitely still exists today. Do not rely on the required parameter to make a custom parameter required!

wpf500 avatar Feb 02 '24 17:02 wpf500