-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support for ES6 Types #938
Comments
Joi is not really a JS types validator. It is for input validation... |
Yes, I understand that. Maybe I worded the issue poorly. But the problem remains that there is no way to validate input that is of or objects that contain those types. {
a: 1,
b: Symbol('b'),
c: new Set([1,2,3])
} The only way to deal with this would be to not validate some of the keys / use |
@esatterwhite did you ever seen the plain JSON with that kind of types |
@bricss if by plain, you are mean what JSON.parse and stringify support, then no. But that is not the problem. The problem is that it is not possible to validate objects of or containing those types with joi |
to come back to what @hueniverse said the description of Joi does state |
Not if the objects contain sets, maps, or symbols. |
Plainly - ES6 introduces new primitives that joi should understand just as well as arrays, objects or strings |
I agree that it's core-ish, I don't want to ship it with normal joi builds, but there should be an extension for it, not necessarily an official one, but if it gets adoption it would make sense to have it in hapi org. |
My comment was pro integrating the new types btw ;) |
Because it would make Joi fatter than it already is, and it's usually not needed, most people validate POJOs. |
Another way would be to have |
And what about promises? Actually we have to set a callback, and joi is not thenable right? |
This specific detail isn't related to this issue and has already been answered in #636 (comment). I don't think there's anything to check in promises either. |
Is anyone interested in implementing the last strategy ? |
can't we just do this with .extend() now? |
Closing due to lack of interest. |
Would be nice to have it:) |
Agree that it's useful, and also that it's probably best handled with an extension. I'll provide a sample use case as well, in case that helps motivate this - the TL;DR here is that, as mentioned elsewhere, Joi is used for validating both input and output. I'm building a REST API with Hapi. To limit N + 1 query problems, several endpoints perform multi-lookups by some ID / field. One natural way to return those results is as a Of course, ES6 replacer(_, value) {
if (value instanceof Map || value instanceof Set) {
return Array.from(value);
}
return value;
}, I can then either do Now, this isn't the only solution to my problem. I could instead use response: {
schema: Joi.array().items(
Joi.array().ordered(keySchema, valueSchema),
),
}, That's OK, but it does mean that I'm weakening the response type guarantee from my REST API. (Of course, if I really care that my REST API returns a A hypothetical equivalent response: {
schema: Joi.map().entries(keySchema, valueSchema),
}, |
There is no way to validate against
Map
,WeakMap
,Set
,WeakSet
orSymbol
. Right now the only work around I see is to define them asjoi.any()
in a schema.The text was updated successfully, but these errors were encountered: