-
-
Notifications
You must be signed in to change notification settings - Fork 309
General expressions support and cross-field validations #541
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
Big +1 to this. Support for co-occurrence constraints in JSON schema would be incredibly advantageous in terms of deferring property and property value interpretation to the schema itself instead of having to build such interpretation into JSON consumption tooling. |
@brunodymios @anweiss you might want to take a look at @awwright's data relationship proposal #549 and see if that would meet your needs? |
Thanks @handrews. Per some of your comments, what I'm mostly interested in is data relationship validations in the instance document itself and not references to external data parameters via URIs per the proposed |
My personal opinion is if JSON Schema is going to support assertions that source multiple data sources, it needs to support references in the same document, values in other documents, and arbitrary data sources (e.g. databases). Because, in a nutshell, JSON Schema shouldn't encourage people to combine too much data into a single document just so that developers can make use of one of its features. I'd only like to encourage documents to contain more data if that's actually the right way to go about designing them. Also, note there's a slight change in the meaning of the assertion. All the assertions presently are assertions about a single JSON value (the instance). The proposal is about relationships between multiple data points. This is also really difficult to implement, in general. XForms has the ability to do exactly what you're asking; it's just not widely implemented because it's so comprehensive. Eventually someone will want to do something really complex. Say, "An array of objects, the The easy solution is just implement multi-datum assertions in application code. The comprehensive solution is let's copy XForms. Maybe there's a solution in the middle too (only implement simple references), I'm not sure exactly. (Or, let people go all-out and embed processing languages in JSON Schema like Lua, XForms, XSLT, or ECMAScript. I don't think this is unreasonable either; this is exactly what HTML does to satisfy the "Code-on-demand" part of REST.) |
@awwright I'm increasingly convinced that the right way to implement this whole area of functionality, whether Yeah, I know, vocabularies are my solution to nearly everything, but as you note, this is both difficult to implement yet in demand from a certain subset of users. We've had multiple related issues filed over just the past few months, and I don't think that adding this sort of thing disrupts the existing core spec (including the additions to it already planned for draft-08). It will also continue to be possible to implement existing validation and hyper-schema without it. And as you note, this is "code-on-demand" territory which is an optional constraint for REST in general, which tells us something. How would you feel about working on this as an additional vocabulary? It can then succeed or fail on its own, like XForms (although hopefully we can learn from XForms' difficulties). And it also would mean that we don't add a huge and burdensome requirement to basic validator implementations when we're trying to stabilize core and validation as an actual standard. |
#549 covers the fundamental idea behind what's been missing, I think, but still needs to describe how it covers cases like this issue. I sort of have an idea on how to fill that in, except this issue asks for one more thing: it's asking for a relationship between three fields. It wants to assert that Further, there's math considerations. JSON Schema is arbitrary precision. But most people will probably want to implement IEEE floating point. |
I agree on what has been written above. A first step is to introduce relationships between data inside the same JSON Schema definition and define how they relates in order to cross-validate them. I did not think about data precision before @awwright comment, since the Remote data sources for validations can of course help very often but I see them as a subsequent step with respect to these "local" cross-validations and I would maintain them separated. |
We've consolidated the proposals of this sort into #855. If this conversation is still of interest, please continue it there. |
What about having a requirement saying that field A must be always equal to field B divided by field C?
Consider the case in which we are managing financial data and we need this information to both show in a form the auto-computed value and validate/recompute this value server-side.
Having this kind of possibility directly in the Json Schema (even through the support for referencing other fields in properties like "minimum" or "multipleOf") could be extremely useful and makes Json Schema even more complete in my opinion.
Such a feature will enable for creating both server-side and client-side validations by only relying on the Json Schema describing the data.
Is this currently being addressed somehow?
The text was updated successfully, but these errors were encountered: