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

In favor of custom validations or custom types. #240

Closed
ericchaves opened this issue Apr 10, 2014 · 3 comments
Closed

In favor of custom validations or custom types. #240

ericchaves opened this issue Apr 10, 2014 · 3 comments
Labels
support Questions, discussions, and general support

Comments

@ericchaves
Copy link

Hi Eran,

I saw a previous closed issue where is said that Joi won't accept custom validations since this could be done with functions applied on data after/prior Joi's validation.

However because in Hapi validations are done with Join internally (we just assign an schema to it) don't you think this restriction can lead to a messy code, where some validations are set during route configuration and others would be left somewhere inside the handlers?

What would be your opinion on this matter?

Cheers,

@hueniverse
Copy link
Contributor

That's the equivalent of eating the cake and having it too.

Joi is a validation module used by hapi. It is designed to encourage configuration over code and to provide a clear path to automatic documentation. Providing external functions voids all that.

Now, I do understand that people would like to be able to perform more complex validation in hapi and you are free to create a solution that combines joi with custom function (since hapi will just take any validation function instead of joi schema). You can also use an extension function or perform extra logic in a pre or handler.

Many options.

Nothing is free and between a consistent API that can be automatically documented to extensibility, I picked the first. You are free to pick the second by taking joi and wrapping it with a module that adds what you want into the any() prototype.

@paglias
Copy link

paglias commented May 22, 2014

@ericchaves I understand you won't add custom validation to Joi and ok. But allowing for an extend() method which accept a function, an error message and a settings object would be far more consistent than having to add pre/post validations that won't fit into joi's error object and will make it difficult to combine a custom validation function with joi's other sanitizations and validations methods?

@hueniverse
Copy link
Contributor

The problem is that while we can expose the internal mechanism for adding new tests, there is so much that can go wrong with that. At the end its the same outcome. If you have a specific proposal, open a new issue with code of how it will work and we can discuss.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants