I am trying to create nested schema in joi and it is throwing error
[Error: Object schema cannot be a joi schema]
JavaScript
x
9
1
var nestedSchema = joi.object({
2
b: joi.number()
3
});
4
5
var base = joi.object({
6
a: joi.string(),
7
nestedData:joi.object(nestedSchema)
8
});
9
How should i define nested schema in joi?
Advertisement
Answer
You could use object.keys API
JavaScript
1
9
1
var nestedSchema = joi.object().keys({
2
b: joi.number()
3
});
4
5
var base = joi.object({
6
a: joi.string(),
7
nestedData: nestedSchema
8
});
9