-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Per the discussion here, there are cases in which adding .example() to a schema will cause errors in the schema compile process. The most glaring case is if the schema contains a Joi ref. The ref cannot be resolved at schema compile time, so the validation fails and the schema is considered invalid.
Since resolving refs during schema compilation is not a reasonable approach, the open question is now "should .example perform validation"?
Arguments in favor of keeping the validation:
- Good safety net for developer error.
- Not removing it means not introducing a breaking change.
Arguments in favor of removing the validation:
- No more changing the order of schema composition (
.min().example()vs.example().min()) just to get around a complex bug. - The
.default()method does not perform validation on the provided value, so why should.example()?
Those are just my initial thoughts. If nobody else weighs in or thinks this is a big enough issue to warrant changing then by convenient default the "keep validation" option will be taken and I'll close this out and move on my merry way :)