Closed jescalan closed 8 years ago
Based on rule 2, Object should be good. https://github.com/molnarg/js-schema/#basic-rules Let me know if that doesn't work.
Jeff Escalante notifications@github.com ezt írta (időpont: 2015. dec. 27., V, 10:27):
I may be just missing something in the docs here, but I really am stuck on this one, hoping someone can help me out.
I've got an object like this I want to validate:
var foo = { bar: { baz: 12, quux: 'wow' } }
I want to validate it such that foo can optionally have a bar property or not, but if it does, bar is an object (not anything that is an instance of an object, which includes arrays), and that it has the keys baz and quux. Is there any way to do this with js-schema?
For the key, I assume I want ?bar, but I'm not sure what to put in for the value at all.
— Reply to this email directly or view it on GitHub https://github.com/molnarg/js-schema/issues/45.
not anything that is an instance of an object, which includes arrays
Doesn't make the cut here. I ended up using joi, so no need to put in a fix for this unless you want to for your or someone else's needs. Thank you for the quick response though, I really appreciate it!
I may be just missing something in the docs here, but I really am stuck on this one, hoping someone can help me out.
I've got an object like this I want to validate:
I want to validate it such that
foo
can optionally have abar
property or not, but if it does,bar
is an object (not anything that is an instance of an object, which includes arrays), and that it has the keysbaz
andquux
. Is there any way to do this with js-schema?For the key, I assume I want
?bar
, but I'm not sure what to put in for the value at all.