Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  130] [ 1]  / answers: 1 / hits: 29593  / 8 Years ago, wed, april 20, 2016, 12:00:00

I am trying to create nested schema in joi and it is throwing error



[Error: Object schema cannot be a joi schema]



var nestedSchema = joi.object({
b: joi.number()
});

var base = joi.object({
a: joi.string(),
nestedData:joi.object(nestedSchema)
});


How should i define nested schema in joi?


More From » node.js

 Answers
2

You could use object.keys API



var nestedSchema = joi.object().keys({
b: joi.number()
});

var base = joi.object({
a: joi.string(),
nestedData: nestedSchema
});

[#62470] Monday, April 18, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeanettee

Total Points: 209
Total Questions: 97
Total Answers: 98

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
;