-
Notifications
You must be signed in to change notification settings - Fork 241
Multiple anonymous schema validation #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
ah, of course a contribution to the documentation that will hinder others from getting confused too about it will be highly appreciated. |
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. |
be aware the so, could an implementation #84 have been a more straight-forward help for you? |
well, in a rudimentary way you did it. feel free to open a pull request with a proper implementation that includes:
|
Hi all,
I am looking for a schema that can validates multiples schema ;
(note the difference between
this_field
andthat_field
)From what I understand from the documentation, it could be written using
*-of
:When I try to validate, I get the following error
I need to "name" the field used by
oneof
to pass this errorbut this won't validate my original
document1
anddocument2
, which now needs to contains anamed
keyCorrectly outputs
But this is not as good as what I need since it changes the structures of my documents (
document1 != document3
anddocument2 != document4
)How can I write a schema that validates both
document1
anddocument2
, without using a specific named key ?Please, let me know if I did not made myself clear, or if you need any extra more information.
The text was updated successfully, but these errors were encountered: