Behavior negotiation: Balancing author intent and runtime flexibility #243
Replies: 4 comments 11 replies
-
I don't have an opinion on this yet, but here's a perspective to consider. The context in which a schema is used can be significant. Assume a schema is used in a web application to validate form data. The schema is used on the front-end to give user feedback before they submit, but it's also used on the back-end to enforce that the submitted data is valid. Let's assume that the implementation used on the front-end doesn't support If the schema is written to require format-assertion, the front-end implementation that doesn't support this vocab can't work at all providing an even worse user experience than a best-effort validation. If the schema is written to make format-assertion optional then a back-end implementation that doesn't support format-assertion could get a false positive validation result because format-assertion behavior should be required on the back-end. This is all mostly not a problem in a closed system where the schema author is also the consumer of the schema, but that's not always the case. The schema author doesn't always know the context in which the schema will be used, so putting behavior requirements solely in the control of schema authors can be limiting. |
Beta Was this translation helpful? Give feedback.
-
I'm of the belief that the specification defines a behavior, and through configuration away from the default mode, implementations can do what they want. Basically a compliant implementation:
If a feature must have multiple modes defined in the spec, then the spec must also declare one of those modes as the default. We also need to be aware that if the spec defines multiple modes for a feature, it puts a burden on implementors to support all of those modes and a configurability mechanism. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
NOTE: This approach did not resonate with folks so I am considering this discussion closed. I will try a different approach to the idea at some point. |
Beta Was this translation helpful? Give feedback.
-
NOTE: This approach did not resonate with folks so I am considering this discussion closed. I will try a different approach to the idea at some point.
A primary goal of vocabularies is to increase the confidence of schema authors that their schemas will be processed as expected, or not at all. Of course, someone using the schema can edit the meta-schema or (depending on the implementation) override it to get around those requirements, but doing so most likely involves observing a failure to run and making a choice to circumvent it. That's totally fine, and sometimes there are good reasons for doing that sort of thing.
We also have some spec-mandated as well as commonly-present runtime configuration options that are outside of the control of the spec author, and in various discussions folks have proposed more of these. Let's figure out some architectural principles for this. Let's not discuss mechanisms, unless you think that something is outright impossible to do.
My starting point:
I think that these are pretty solid principles, but I'm definitely open to counter-proposals as I came up with them fairly quickly.
Here are some examples to help make this more concrete — I'd like to avoid trying to solve these specific problems in this discussion, but we can refer to them while discussing if the principles make sense.
How
format
does and does not comply with the above principlesWith 2020-12, we almost got
format
to comply with these principles. Schema authors can selectformat-annotation
orformat-assertion
.While even
format-assertion
's specification acknowledges that validation behavior might still vary, it is a stronger requirement than how people implementedformat
in the past, and it's clearly acknowledged in the specification. A schema author who requiresformat-validation
knows that they will get a substantial amount of validation for every standard format, and accepts that the spec allows some variation.Therefore, any variation in
format-assertion
behavior that is within the spec's allowances is acceptable runtime variation.However,
format-annotation
does not guarantee thatformat
will only be treated as an annotation. It's possible to turn on the old-style best-effort format validation regardless of how the schema author set upformat-annotation
in$vocabulary
. If a schema author wants to outright forbid any validation attempts, there is no way to do that.So while we can hand-wave and say "yeah,
format-annotation
includes that, so it's still within the schema author's specified range of behavior", doing so defeats the purpose offormat-annotation
as the predictable option.However, if running best-effort validation on top of
format-annotation
required an explicit "circumvent schema author intent" option (either separately or in the name or at least documentation of the option itself), then that would be fine.Current problem: annotation support
Right now, a schema author cannot require annotation support. This matters if the validation concerns of the schema are pretty trivial, and the main work is being done in complex annotations. Chances are, the person running the schema would figure this out, but it's an example of someplace where more control would be better.
Annotation collection is still a somewhat experimental feature, and not universally supported. If you really depend on it, it would be better to get an error (or at least warning?) so that someone not deeply versed in JSON Schema could quickly figure out that they need a different implementation, or need to lobby for annotation support.
This likely generalizes for other use cases involving not-yet-stable features as discussed in #234.
Beta Was this translation helpful? Give feedback.
All reactions