-
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
schema.describe minor issues and feature suggestions #1606
Comments
describe
minor issues and feature suggestions
At the risk of derailing the discussion, did you by chance check out Felicity for generating randomized data based on a Joi schema? If so, would you mind letting me know if there was anything about it that didn't meet your needs or expectations? Always looking to improve it, and always thrilled to have PRs and feedback :) |
@WesTyler I checked out felicity before starting this project even opened an issues xogroup/felicity#143 Also I assume felicity was made with the idea to generate user readble examples for api routes. It could be great if the features and fixes could be integrated into felicity since I assume maintaining this kind of code is going to be painful. |
Oh, ha! Sorry! That's what I get for trying to catch up on things at night after a vacation. I recognized your name but couldn't place it. I'll move the ongoing discussion back over to the Felicity issue (which I've been meaning to get back to you on). Sorry for derailing the |
Are you going to be able to sort it out in felicity or is this issue still needed ? |
@Marsup this issue isn't really about felicity. It is about issues with Joi |
|
Providing the function is good enough
What ever you think. It doesn't affect my code that much but I thought it might be worth pointing it out.
That would be great. |
Breaking changes:
|
I am reverting the last change (schema behind a symbol). It is no longer needed with the new |
I'm working on a fuzzer that would accept joi schema and would return a valid example with random data.
based on the discussion here (#946) I was using describe to
understand the schema and try to create a valid example.
I found a few places where the description is not clear enough to understand the actual schema.
Not sure if this is something joi would care to change but it can be useful
Joi.lazy()
- does not describe in any way the schema to be lazy load.I think the minimum will be to return the function that can be called to retrieve the schema
but a better solution might be to actually get the schema from the function and include it's description.
For example in the following schema -
from the description it looks like
o.a
ando.d
has the same definition, buto.a
has to be 'x' wheno.b === o.c
ando.d
has to be 'x' wheno.b
is the literal stringref:c
.I know chances that there are small chances for the schema ever use literal string start with 'ref:' are small but it still would be great to have an option to differentiate between those values and in general maybe a nicer description for references (including context references) might be more useful
like an actual object
{ref: key}
and{context: key}
Another feature that can be useful (but might be a bit specific to my use case) is to include the schema as part of the description.
This can be useful test if the generated value actually meet the required description (especially in the case of alternatives and references where you want to check if a value meet a certain condition)
alternative option will be to have a reverse method that will regenerate a schema out of a description, but it will probably be much harder to implement
The text was updated successfully, but these errors were encountered: