hapijs / joi

The most powerful data validation library for JS
Other
20.75k stars 1.51k forks source link

The documentation doesn't explain overrides or re-using naming conventions of existing rules when extending joi #3035

Open xaddict opened 2 months ago

xaddict commented 2 months ago

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.