Replies: 3 comments 6 replies
-
@AML14 regarding relational and arithmetic constraints, it is possible (in theory) to express such things in JSON Schema, just not with the standard vocabularies. From the most recent draft (unchanged from the previous draft or two, I'm pretty sure):
So if you want to say that the parameterSchema:
type: object
required: [minimumAmount]
properties:
minimumAmount:
type: number
maximumAmount:
type: number
greaterThan: 1/minimumAmount # this is a Relative JSON Pointer, using the instance (not schema) structure A basic relational vocabulary would not be hard to spec out. I know of at least two JSON Schema implementations that can handle extension vocabularies that use Relative JSON Pointer for instance data access. |
Beta Was this translation helpful? Give feedback.
-
(I'm starting separate threads to keep sub-topics distinct) Regarding difficulty of reading, for "if type == 'number' then prefix or number must be specified", rather than this: oneOf:
- not:
- properties:
type:
enum: ['number']
- required: [prefix]
- required: [number] which I agree is incorrect unless the intention was "exactly one of prefix or number must be specified", I would write: if:
properties: {type: {const: number}}
then:
anyOf:
- required: [prefix]
- required: [number] For this sort of thing I like writing the Some of this is just education on good idiomatic use of modern JSON Schema. The OAS community is still used to draft-04 which was far less expressive than 2020-12. |
Beta Was this translation helpful? Give feedback.
-
I've changed the title of this to make it more distinct from #100, which has become the general discussion for parameter interdependencies. This discussion focuses on more complex dependencies that are worth considering on top of the basics. |
Beta Was this translation helpful? Give feedback.
-
I just checked the proposed format for specifying inter-parameter dependencies with JSON Schema (thanks @darrelmiller and @mkistler!) and, although it may support most dependencies found in our research study (see research paper, Medium post or ASC'22 talk), I see three main drawbacks:
Arithmetic and relational dependencies are not supported. Or, at least, I don't see any examples. In our experience, arithmetic dependencies are not common at all (e.g.,
p1 + p2 < 100
), although relational dependencies are very common (e.g.,p1 < p2
). These are very typical for specifying ranges (e.g.,minPrice
andmaxPrice
).Some dependencies are hard to understand. When reading a description like the Tropo dependency, "if type == 'number' then prefix or number must be specified", I find it really difficult to understand its corresponding translation to the proposed format:
What's more, I'm not 100% sure this dependency is correct, since the oneOf keyword forces the use of just one alternative, but using both
prefix
andnumber
at the same time would still satisfy the dependency (i.e., that combination is ananyOf
). In any case, to me, it seems much more natural to write something likeIF type=='number' THEN prefix OR number'
. Plus, it is less error-prone. These two dependency formats are not exclusive. We could support a simple DSL like that (something similar to our IDL) that translates into this JSON Schema-compatible format.Some dependencies are too verbose. Some dependencies like ZeroOrOne or Complex dependencies happen to be too verbose with this format. A clear example is the ZeroOrOne dependency from YouTube: 31 lines for something that could be written as
ZeroOrOne(forContentOwner, forDeveloper, forMine, relatedToVideoId)
. Again, this could also be solved by supporting and intermediary succinct DSL that would translate into this format. In this way, we wouldn't have to reimplement all the validation logic already present in JSON Schema from scratch, but simply the translationDSL -> this format
.All in all, as I was arguing on the Slack channel, it's not only about supporting these dependencies, it's about how we support them. Are developers willing to write 31 lines of code to formally express something like "Specify 0 or 1 of the following parameters: forContentOwner, forDeveloper, forMine, or relatedToVideoId"? I really think we need to make their (our) lives easier.
Beta Was this translation helpful? Give feedback.
All reactions