You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@farwayer I assume you are attempting to validate some object with the schema(s) mentioned above, could you please provide some examples of your input data.
It was just example, but sure I can provide data that will fail:
constschema=Joi.object().keys({authors: Joi.array().items(Joi.string()).default([Joi.ref('$user')]),});constdata={};const{value}=Joi.validate(data,schema,{context: {user: 'defaultUser'}})// values should be {authors: ['defaultUser']}// but will be {authors: [null]}
There was a missing piece in joi to let you accomplish that which is why I consider this a bug. But for obvious reasons, joi is not going to deep explore your objects looking for references, but you can generate those defaults using a function like :
constschema=Joi.object().keys({authors: Joi.array().items(Joi.string()).default(function(value,options){return[Joi.ref('$user')(value,options)];},'Array with default user'),});
lockbot
locked as resolved and limited conversation to collaborators
Jan 10, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Context
What are you trying to achieve or the steps to reproduce ?
This also will not work:
Which result you had ?
What did you expect ?
The text was updated successfully, but these errors were encountered: