Recursive parse
kivervinicius opened this issue · comments
Kiver Teixeira commented
No works with complex json example:
const schema = require("schm");
const { validate } = schema;
const userSchema = schema({
name: String,
age: Number,
child: {
name: String,
age: Number,
},
});
validate({ name: "John", age: 17, childs: {name: "Test", age: 1} }, userSchema)
.then(parsedValues => {
console.log("Yaay!", parsedValues);
})
.catch(errors => {
console.log("Oops!", errors);
});
Haz commented
It should work. You're passing childs
instead of child
. Could that be the problem?
Kiver Teixeira commented
I'm sorry, was that, but should I accuse property that is not being passed right? instead of giving only the error "undefined"
Haz commented
Sorry about the delayed response. It'll return the error if you make the properties required:
const userSchema = schema({
name: {
type: String,
required: true
}
});