-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
default
specification (6.2) needs fleshing out
#204
Comments
@pipobscure I agree that we need more clarification. An important point that needs addressing somewhere (whether in the spec or on the web site in supplementary documentation) is that Non-validating defaultsObviously, if you use a default value in an instance but it does not validate, that would be strange. But so would several other things that are possible with JSON Schema. The right model here is probably linters vs compilers/interpreters. A schema linter should warn about a non-validating default or example, but it's not technically incorrect and may be useful in some odd circumstance. This was previously discussed in #125. The main reason to avoid a MUST here is to avoid imposing an implementation requirement during validation when this is really not a validation keyword (see also "Related topics" below).
|
No work to be done on the 25th!!! Tsk! p.s @handrews I'm not in the office next week. |
@Relequestual good! :-D |
@handrews in the case that In my validator, I have an option to trigger I think this is a sensible way to implement this, but I'd really like to clarify that this is "legitimate". If someone let's me know the procedure (or points me to a place to where I can look them up) I'd volunteer to make an attempt at a PR for the spec. (Also: isn't the point of celebratory days to mess with stuff like github issues for the pure fun of it? 😄 ) |
We don't (yet) do a great job of separating the different things going on under the general umbrella of "JSON Schema", although the split into three specs was a good start that just needs more follow-through. There are a couple of things one can implement with respect to JSON Schema: A validator, strictly speaking, just uses the validation keywords (everything except the meta-data section) to deliver a validation result. Beyond that, we can implement various applications and helpers, including but not limited to:
Each of those might use In the API case, the default might be used after the user (which may be a program rather than a human) sets up the data, to fill in whatever data is missing. This might be done to reduce the representation weight on the wire (although the actual benefit of this "optimization" is usually so small as to be irrelevant unless you're in a really constrained environment). So is what you're doing legit? Well, yes, but in the sense of it being one legit way of using the default, and not the only one. Up to you what use cases you are targeting with your work. For instance, I am working on a generic hyperschema client. In addition to running a validator module, it will use the defaults to fill in under-specified messages. The schemas that this client works with will be written and documented such that it is never ambiguous as to whether the default should be used or the field was intentionally omitted. But that use of the default will be in the representation management part of the code (the actual application-specific code), not in the validation module (which, depending on the language, might actually be a 3rd-party module).
😄😄 Indeed! |
@handrews the differing uses for At least that would allow schemas to remain portable. In the current case, schemas loose their portability, since an app that requires |
That is not lack of portability, that is adherance to a spec, perfect or not. @pipobscure if I haven't said it already please don't misinterpret anything as ingratitude, your input is more than welcome. But you need to understand first what is, and then why it is, and then whether it needs changing. |
@Julian I agree that it's adherence to spec, but I do have an issue with "perfect or not". I was under the impression that the point of the repo was to move the spec closer to perfect 😄 I understand the what is: the I also understand why it is: the intent was to allow a bit of flexibility in the use of the keyword especially in regards to the use of the schema. If used to pre-fill forms/ui there might be different needs as when it's used for documentation and those again may be different from generating a "defaulted" complete document. I believe that the answer to whether it needs changing is yes. Just to be clear: I am NOT arguing for a simple change from RECOMMENDED to MUST. That has been discussed all over the place ad-nauseam. I suggest we need to make clearer what values for My personal preference would be that: the value value for Simply replacing RECOMMENDED with MUST would mean that: {
"type": "object",
"properties": {
"foo": {
"bar": { "type": "integer", "default": 1 }
}
},
"required" : [ "foo" ],
"default: {}
} would be invalid, since the default value itself would not be strictly valid. My recommendation would be that Now back to the question of whether it needs changing. As I said, I believe the answer to be yes. I believe that the current wording suggests that while there is a clear preference for the value of
In other words, none of the engines/use-cases are actually able to rely on the value in any way. Unless you specifically craft the schema to fulfil the use-case and you are even aware of the use-case a-priori you have no sensible way to use that value. That in turn leads to the situation that if you want to be able to use a value you have to add more specification. Either by restricting That in turn leads to the So to my view, the current definition of `default is so deficient as to be worse than useless and a blotch on an otherwise good specification. There are two ways forward in my view:
Right now, I think it's just a case of being to chicken to say "actually this thing MUST to be valid", because there might be some theoretical case where someone would want it not to be valid. P.S.: If I haven't said it already: Please don't misinterpret anything I write as a personal attack on you or your work. I believe having an open debate is the way to produce the best OSS and Specs. I deeply respect all the work that has already gone into this and all those who have done that work. The only reason I am being argumentative is out of a desire to make this thing better. Once there is a clearer agreed way forward, I am volunteering to actually do the work as well. |
@pipobscure There is nothing wrong with a system that makes use of JSON Schema putting extra constraints on how it is used. That is to be expected. A UI generation system will have different needs from hypermedia description, and both are different from static documentation generation. There is no "generic" way to use schemas and a given schema might not be suitable for all three. There is also the question of: why does the value of default need to be reliable? What is wrong with just raising an error if a specific application finds that the default does not meet its requirements? There are many similar cases around JSON Schema. Structural validation may pass, as may whatever semantic validation can be achieved through Just because the spec allows a nonsense value there doesn't mean your application or tool has to do anything specific. If your system is documented to write the default into the instance before validation, then obviously anyone expecting to use that system needs to use a valid default. And your system in that case can easily validate each default and raise a sensible error if it fails validation. |
@pipobscure I would be more in favor of individual vocabularies defining how to use But in the hyper-schema spec we could say things like:
In a UI Schema spec, we could say:
In a documentation schema spec, we could say:
Alternatively, we could drop the notion of a global default and instead create specific keywords for specific behavior. The driving consideration there should be how likely it would be for someone to need to re-use the same schema in such a way that two conflicting uses of |
I think shrug label ¯_[ツ]_/¯ is timely here :) |
I'd be very much in favour of this. At a minimum it would make things a lot clearer and make schema compatibility a lot easier. Just for background, and why I might be a bit more passionate about |
@pipobscure that situation with the two teams is very good to know about, thanks! It's always helpful to see how things happen in the real world, especially unexpected things. I also just wrote up the beginnings of an idea for splitting the definition of annotation keywords like I'm going to (as @epoberezkin suggested) tag this issue with the shrug label (meaning "too long and wandering for most people to read). If the idea of splitting up |
Closing in favour of someone really wanting this who can clearly answer the number of use cases and issues @handrews rasises in this issue, to raise a new issue. |
The specification for
default
is insufficient in terms of its requirements for implementations.At minimum we have to think about the implications for further validation. The current specification suggests that a value for
default
that does not validate against the provided schema. However there are more implications presented bydefault
. For example the effect ofdefault
if the property is alsorequired
. Ifdefault
does not satisfyrequired
then its purpose is unclear at best and misleading at worst.I have created a PR against the test-suite with this in mind.
In my opinion the specification should be clearer by stating that the value for
default
MUST be valid according to the provided schema. The presence ofdefault
should also satisfy other schema criteria such asrequired
.I am maintaining a JS implementation (draft3 & draft4) for corporate in-house use (open-sourcing is in progress). It has the option to actually modify the original JSON-Document, or alternatively keep it untouched but continue validation as if the default value had been there all along. We have yet to come across a situation where this was insufficient or unclear.
The text was updated successfully, but these errors were encountered: