-
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
Allow self references #1569
Comments
This syntax would only work for strings though, and how do you define the default case ? |
I was only thinking of defining it for booleans really. The schema definition is powerful and I wouldn't want to define a whole parallel syntax to it. I think the main thing that makes me feel like it's not already simple is the Could this be solved by a |
responseSchema: Joi.object({
messageId: Joi.number(),
success: Joi.boolean(),
)
.when('.success', {
is: true,
then: {
responseObject: Joi.object(),
otherData: Joi.string(),
isDataNew: Joi.boolean()
},
otherwise: {
reason: Joi.string().valid(Object.values(Constants.FailureReasons)),
description: Joi.string().optional()
}
}); |
I like the new self reference syntax, thank you @hueniverse! |
Describe the problem you are trying to fix (provide as much context as possible)
I use a
success
boolean key in message responses, and the structure of the message often depends on if it is true or false. I useJoi.alternatives
to match ontrue
orfalse
but the syntax is pretty awkward and confusing for new readers (especiallyunknown()
):The line I think is strange is this one:
Which API (or modification of the current API) do you suggest to solve that problem ?
I would prefer a syntax that supported this case more easily and clearly.
I am not sure what the ideal solution would be, but maybe something like this would work:
Are you ready to work on a pull request if your suggestion is accepted ?
Honestly I am not sure I have the depth of understanding required to contribute to this project yet, I am just getting into it.
The text was updated successfully, but these errors were encountered: