Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xaddict opened this issue May 8, 2024 · 0 comments
Labels
documentation Non-code related changes

Comments

@xaddict
Copy link

xaddict commented May 8, 2024

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
@xaddict xaddict added the documentation Non-code related changes label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Non-code related changes
Projects
None yet
Development

No branches or pull requests

1 participant