Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Multiple anonymous schema validation #132
I am looking for a schema that can validates multiples schema ;
(note the difference between
From what I understand from the documentation, it could be written using
When I try to validate, I get the following error
I need to "name" the field used by
but this won't validate my original
But this is not as good as what I need since it changes the structures of my documents (
How can I write a schema that validates both
Please, let me know if I did not made myself clear, or if you need any extra more information.
unfortunately such convenience isn't possible.
apparently your first schema will not work because constraints are always bound to a field, so 'oneof_schema' will be interpreted like this.
the second schema is a good approach to deal with it, but the 'common' fields are kept one level too high.
i would recommend you to write write (parts of) the schema without shortcuts and then figure out how it can be condensed.
i hope that helps you. i'm not testing your bits, so i may oversee something.
I'm afraid I did not understand all you said about constraints and field. I would be happy to contribute to the documentation, but I don't wont to mess with it.
Anyway, I managed to solve my problem with the following class based custom validator :
And my schema now looks like :
I am totally happy with this solutions that allow me to define mutually exclusive (xor) fields in cerberus. Hope it helps another soul on the internet.
well, in a rudimentary way you did it. feel free to open a pull request with a proper implementation that includes: