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
I used Joi to cast the input objects into well-defined models.
This package has a Validate function which reads the schema from its parameter.
It's like a bit nonsense since typescript doesn't allow creating non-valid objects (at least for the types).
So there should be something like this:
const obj = {
something: '12'
}
class Model {
@Required()
something: number,
@Required()
somethingElse: string
}
try {
const model : Model = Validate(Model, obj)
} catch(e) {
console.error("Invalid object given")
}
Thanks
The text was updated successfully, but these errors were encountered:
@fxdave you are right, i was currently using the validation explicitly by first getting the schema using the constructor and then validating it with Joi directly (same thing the Validate function does). const schema = getSchema(Model); return Joi.validate(obj, schema);
The validate function was there for objects created with the constructor. Now its fixed on a5c3785
I used Joi to cast the input objects into well-defined models.
This package has a
Validate
function which reads the schema from its parameter.It's like a bit nonsense since typescript doesn't allow creating non-valid objects (at least for the types).
So there should be something like this:
Thanks
The text was updated successfully, but these errors were encountered: