-
-
Notifications
You must be signed in to change notification settings - Fork 39
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Rename required
to present
#186
Comments
this would impact |
The naming is one of a series of quirks that I don't think can be perfect... we have a few other properties where the name is a bit ambiguous, for example "minimum"... well, minimum what? (scalar value, item count, string length, sort order, ...?) Sometimes this could have been better thought through: When we were changing how "required" worked, that may have been a good opportunity to name it "requiredProperties" instead. But even in this case it might not matter (it only makes sense to think of properties as being required or not). However I don't think "present" would have been a better name. The naming scheme for validation keywords follows assertive language. A schema "requires" a property, it doesn't "present" a property. Likewise, there's other properties that could be confusing: "if minLength: 5 then ..." well hold up, this will evaluate true for all numbers and other non-string types! A better way to explain its behavior might be like this: "If the condition that the property 'foo' is required is valid, then ..." or "If the condition minLength: 5 validates, then ..." |
I'd be extremely hesitant to start renaming keywords, since (as @awwright noted) there are several that could probably be better. Most of the keywords were chosen by people who left the project nearly a decade ago or longer, and most of the newer keywords were chosen to align with those. We have done a few renames:
Perhaps at some point if we need to do some sort of large-scale breaking change, a holistic rename could be consider. But more likely, it's better to push for |
I would describe the real meaning behind this to be that a schema requires the presence of a property. It looks like you're using the verb form, 'to present a property' rather than an adjective, which isn't how I mean it (though that potential ambiguity may be a downside of the name).
I agree with this; I see the assertion being made to be that the property is present. Asserting a condition and requiring that condition seem synonymous to me. For |
I object to the choice of "present" because it's such an overloaded word in english:
If we are in the mood to change the name of this keyword (and personally I am not), I think "mustExist" or "exists" would be clearer than "present". |
I do agree. I also agree with all of the naming changes that have been made so far, the ones you've listed, the It may be the case that other keywords could be named better too. And it is always the case that I can take any idea I like and do my own vocabulary that nobody but me will use. That doesn't help improve the clarity of the core validation's |
@karenetheridge I do think |
The critically important difference here is that none of them were renamed just to rename them. The closest would be adding That is extremely important. We have never renamed a keyword just because we didn't like the name. No one will ever agree on what names are best. We all have keyword names that we think are unclear or just not ideal. I would strongly prefer not to debate different names because the question that needs to be answered first is "should we be renaming at all?", and I think the answer to that is an emphatic "no." |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I will recognize at the outset this is change would be a significant backwards incompatibility. I want to at least bring it for discussion.
I think the keyword "required" has a poor name for its purpose. All of the validation keywords express requirements of one sort or another.
required
should be named for what it is actually requiring - the presence of the indicated properties. I think "present" is the best keyword to express this. some variant of "properties present" might be an option too.The current name is okay for positively validating - saying a property is required does imply that its presence is the requirement. That case is natural enough to read and make intuitive sense. But we have all seen the confusion that results when using it in conditional or negated schemas.
"If property
foo
is required, then ..." is how that reads, but what it means is not very intuitive. "If propertyfoo
is present" is much more applicable, and reads more naturally fromif: {present: ["foo"]}
.Likewise,
not: {required: ["foo"]}
does not mean "propertyfoo
is not required". Multiple properties are worse:not: {required: ["foo", "bar"]}
reads like "neitherfoo
norbar
is required". Much improved,not: {present: ["foo", "bar"]}
does assert "propertiesfoo
andbar
are not present" or "must not be present".I think
required
made more sense back when it was a boolean keyword of a property schema, but would have been better renamed when it was put in its right place as a sibling ofproperties
. I think the namepresent
is a significant improvement - I'm interested to hear people's opinions.Of course, there are countless schemas which use
required
. This would be a widely impactful change, though not the biggest (e.g. smaller thanid
/$id
, I think). There are tools to convert schemas between spec versions, and this would be a trivial conversion to implement. Mayberequired
could live on for a while as a deprecated alias with the same function aspresent
(though I don't think the spec has ever done that before and that may be a whole other issue to address).I think in the long run, though this change would have some pain in its transition, it is worth the benefit of more clearly expressing the intent and meaning of the keyword in all the contexts where it is used.
The text was updated successfully, but these errors were encountered: