Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract validation rules from a route

Tags:

hapi.js

I am trying to build an endpoint like this /schema?method=get&endpoint=/users/search and the purpose is the provide a "JSONified" representation of the Joi validation I'm using. This will be used by the Front-End for client-side validation.

Is this even possible? Printing server.table() doesn't seem to have the information there.

I also welcome suggestion about how to name my schema route.

like image 748
Cybrix Avatar asked May 03 '26 13:05

Cybrix


1 Answers

You can use server.match() (for route lookup) in combination with Joi.describe() (for Joi schema description) to do what you want.

like image 193
Adri Van Houdt Avatar answered May 07 '26 11:05

Adri Van Houdt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!