-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
How can I perform more complex validations #306
Comments
Found the solution ... add a custom validator to the object itself, not only to the attribute. |
Just one comment: Too me, this sounds like a design smell. |
@RST-J Jonas, thanks for your comment. It is not necessarily a design smell. A sample use case is {
"event": {
"title" : "handling negative durations",
"start" : "2016-02-17T12:30",
"end" : "2016-01-17T17:00"
}
} Validation shall report that end date is before start date in the event "handling negative durations" Initially I tried to do this while validating start or end as I was not aware that "format" can also be specified for objects, not only for primitives. |
@bwl21 Well, considerations like this were actually my thoughts for developing this feature. The spec of format seems to tell us 'do whatever you think might help, but be careful'. On the cons side I see currently two things: First, it is not portable. No one can just take the schema and validate objects one wants to send to your system, even not using Ruby if you don't provide the semantics of your custom formats. No big deal, but at least a deal. So, I'm more intereseted in hearing other's thoughts on this (and probably like to be convinced that it is a rather good thing to use it this way) than telling them that this is crap. |
It is indeed one ot the issues I am arguing for years, that there is a difference between structural validation and semantical validation. I was often asked why an xml file is not processed correctly even if it passes the validation against the schema. So I can really understand an accept your point of view. Semantic validations can hardly be expressed in a portable way. There are attempts like this (e.g. OCL) but they end up implementing another programming language. So in my rather small project I prefer semantic validation by a clear interface an implementing the rules in ruby (as the application itself is written in Ruby). In my case the objects are created i my application. I do't have a Gui so the users are (as of now) creating the objects with a DSL. There I need the validation. Using "format" is a good approach to keep the validations in an extra rule set and use a formal reference for integration. |
I would like to implement validations which take into account not only the current attribute but also sibling attributes.
If the signature of a custom validator would be (value, object), then one could access the container object of the atttribute and thus consider sibling attributes as well.
The text was updated successfully, but these errors were encountered: