The documentation doesn't explain overrides or re-using naming conventions of existing rules when extending joi
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
### Module version
17.13.0
### What documentation problem did you notice?
The documentation on extending joi is not really helpful in writing new rules, nor does it explain how to globally extend joi to support new rules
For example, I want to extend joi by adding a `.file()` which has `.min(bytes)` and `.max(bytes)`
I am using `joi.object()` as a base (since almost everything in JS is an object, like FileList and File)
When I add a rule `min` I get a console error stating: `Error: Rule conflict in file min`. This is (probably) because `joi.object().min` already exists.
The documentation mentions:
> overrides: A hash of method names and their overridden implementation. To refer to the parent method, use `$_parent()`
But doesn't explain how to use it or how one can override the base schema rules.
- I tried putting the rules in overrides, but overrides need to be functions.
- I tried putting the rules in objects and returning them in overrides, but that doesn't work
- I tried using this.$_addRule in override functions and calculating in the root validate, but that logs `Invalid rule`
Contributor guide
Assessment
This issue has not been assessed yet.