Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does stripUnknown in JOI validation does?

The Documentaion of JOI says that,

response.options Options to pass to joi during validation. Useful to set global options such as stripUnknown or abortEarly. If a custom validation function is defined via schema or status then options can an arbitrary object that will be passed to this function as the second argument.

It is not clear that what it does.

const joi = require('joi');

joi.validate(object, schema, {stripUnknown:true}, callback);

Can someone tell me what does stripUnknown does?

like image 701
kartik Avatar asked Oct 25 '25 07:10

kartik


1 Answers

        validate: {
            payload: Joi.object({
                start: Joi.string().min(1).max(4),
                end: Joi.date().required()
            }).options({ stripUnknown: true, abortEarly: false })
        }

In the above example, stripUnknown is set to true that it will not complain if your payload has any other keys other than start and end. By default stripUnknown is false.

like image 81
kartik Avatar answered Oct 27 '25 00:10

kartik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!