-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support non-hierarchical dependencies #20
Comments
@yhack can you give some examples of this sort of dependency? My feeling is that {
"type": "object",
"required": ["x", "y"],
"properties": {
"y": {"type": "boolean"}
},
"if": {
"properties": {
"y": {"const": true}
}
},
"then": {
"properties": {
"x": {"type": "string"}
}
},
"else": {
"properties": {
"x": {"type": "integer"}
}
}
} You may also find @awwright's data relationships proposal interesting: json-schema-org/json-schema-spec#549. |
@handrews I'm working on getting you an example I can share. In the meantime, I'll build on your example. The use case occurs when interdependent data is nested in different branches of the JSON tree. Referring to your example, suppose "x" and "y" were each objects with properties "a" and "b" respectively. Suppose you want to assert something about "a" based on the value of "b". Technically you could accomplish this with an json-schema-org/json-schema-spec#549 is interesting, but both that and json-schema-org/json-schema-spec#51 are about importing data into the schema rather than applying schema to an arbitrary part of the JSON document. |
Here's an example. Suppose we have the following JSON document describing a birthday party:
We might validate guests and desserts as follows:
Now suppose our guests are rather picky. As a caring host we want to provide a dessert that every guest likes. Dessert likes are provided by the following table:
As you can see, which desserts are valid depends on which guests attend. Validating this type of internal consistency using JSON Schema is currently not possible in a general and elegant manner.* I'd like to propose a simple extension to support this. Proposal:
|
I'd like to see an example of how this is useful for structural validation. JSON Schema generally does not encode valid data ranges; that is to say, if the guest list changes, the schema should still remain the same. |
You hit the nail on the head. The point of this proposal is to validate data consistency.
With |
@yhack With draft
But mostly, it's that there are tons of requests for really complex things that not very many people ask for. We have to draw the line somewhere, and at this point there's a really, really high bar for keywords going into the Core and Validations specifications. This is exactly why we designed the vocabulary feature. |
As noted above, this is probably more of an extension vocabulary thing. Without the |
Without this feature, how do you write a validation, if you want it fail if two integer type properties are same, the values to these 2 properties will be either provided as input or has defaults. Please let me know. |
I'm very interested in using JSON Schema to model documents that have non-hierarchical intradependencies.
The dependency specification includes this statement:
In other words, if this object has the dependency key, then this object must validate against the subschema. The crucial functionality missing is the ability to conditionally apply a subschema to a different part of the document.
Notes:
The ability to model intradocument dependencies would be useful both for UI generation and consistency checking of JSON documents with non-hierarchical relationships. Given JSON Schema's existing tooling, extending it to support this use case should be relatively straightforward.
The text was updated successfully, but these errors were encountered: