-
Notifications
You must be signed in to change notification settings - Fork 240
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
conditional normalization using oneof #515
Comments
while you are correct that conditional normalization with the since you want to set a default value that depends on the document context, i propose to use a |
thank you for your fast reply @funkyfuture and sorry that it took me so long to react. At first I experimented with On the validation side I really like the extensibility of Cerberus using Following what is proposed in #279 I agree that the complexity inside the code might be reduced, but I am afraid that it makes the definition of the schema more complex and as far as I can see it might introduces redundancy in the schema definition as well when use for the problem that I tried to address here. However, I'd be happy to have a look once the corresponding branch is online - maybe my first impression is wrong. Above you mention that the proposed |
don't worry, i'm short of time as well.
see #438 and amend if you have additional thoughts.
yes, because the i'm in a hurry, but let me try to point out what my overall view is on the matter: Cerberus is great to make simple schemas that solve rather simple problems. of course there are more complex problems in the world, but Cerberus could only solve these with a more complex grammar (it doesn't have a formalized one, btw) which would render the solutions to simple problems to be more complex. in my experience, users often expect some kind of magic and implicit handling for a given combination of rules (and constraints) that are absolutely obvious and unambiuous in the scope of the problem they tackle. but they often fail the problems of other users when abstracted. and the code gets much less maintainable with each of such implications. one very aspect that concerns your proposal: normalization and validation are two different stages (each can be skipped) and they work very differently. bridging these phases is possible, and we do that for two or three rules, but it's quickly getting messy with the amount of rules. in the future i hope to reduce that number and to implement a framework that allows to declare complex rules in a clean way. having that said, i really want to advise you that you take a complex problem as such. that improvement of the framework will take a while, isn't guaranteed to succeed and i'll be happy to have your feedback on it. |
To me Cerberus is already quite a strong tool that manages to deal with rather complex problems using a simple grammar, that is one of the reasons why I really like Cerberus. Looking at my proposal I, currently define a schema like this:
how would you like if the normalization role of
like this the there is a clear cut between the role of 'oneof' in the validation phase and in the normalization phase. |
any update on this issue? Today I just meet the problem as you guys. By the way, I think the proposal above would be ok if implemented. |
I am not aware of any progress on this, For the moment we are using a patched Validator that does In case you want to have a look, here is what we use: |
thank you, it's helpful! |
I'm not sure but we might be running into the same issue as described here. We have a |
i'm closing this now. my main point would still be that it introduces inconsistency in the design and code complexity for rather rare cases. as a recommendation for all your cases, i wanna remind that Cerberus was initally designed for validation, not normalization, and point at the possibility to do these things in subsequent steps. not all steps need to use Cerberus. |
Used Cerberus version / latest commit: current master
to solve.
Use-case abstract
So far Cerberus does not allow for conditional default values which is supported by other validators (e.g. in Schema using
Or
). Here pledge for a new feature that adds the possibility to define more complex defaults i.g. where the default value depends on another field. This feature can be added without any new rule simply by consideringoneof
during normalization.Feature request
It would be nice to consider
oneof
also for normalization. While other of-rules (anyof
,noneof
,alloff
) are not unambiguous in the context of normalizationoneof
instead could be used to insert conditional default values.e.g.
The text was updated successfully, but these errors were encountered: