Description
In response to #810 and #925, it seems we need agree on how keywords are named. Since prefixItems
is new for the upcoming draft, we should consider fixing this now rather than being stuck with it or introducing another breaking change.
Based on previous conversations, there are two schools of thought, which are defined by two aspects of keywords:
- Function
- Relationship to other keywords
In either case, the other is intended to be declared in the specification.
Although being able to convey both with a name, I prioritize naming by function because it increases readability while authoring schemas.
Another thing to consider is keyword symmetry along:
- array vs object (having similar functionality for both)
- boolean logic (having functionality for AND and OR)
In general, keywords tend toward function or both, but prefixItems
deviates from this pattern. Below is an analysis of some existing keywords, followed by a similar analysis of prefixItems
:
*Of
, not
, type
, maxLength
These keywords land in the function camp. It's very clear what they do and how they apply.
There's no mention of how they interact with other keywords, if they do at all.
if
/then
/else
These names actually satisfy both aspects.
Most people are familiar with conditional constructs (dispite the volume of SO questions regarding these keywords), both in regard to what they do as well as how they relate to each other.
items
I think this one is a little vague, but it leans pretty strongly towards "function".
The word "items" suggests that it applies to arrays, but it doesn't convey that all items must match the given subschema. Perhaps a more functionally-oriented name could be allItems
.
This opens the opportunity for contains
to be renamed to anyItem
, which would satisfy boolean symmetry.
additional*
& unevaluated*
These also happily have names that both convey the function and relationship. For example, unevaluatedItems
is processed like items
but after all other array-related keywords have been processed. (Note, however, that unevaluated*
doesn't convey that it can peer into sibling applicator keywords. I think that's just matter of terseness.)
prefixItems
This name is relationship-based. It is named such because it should be processed before items
is processed. But there's no mention that the subschemas are intended to be applied in order. This is the only keyword that fails to do this.
This keyword is analogous to properties
(apply multiple subschemas to multiple sub-instances of the instance passed to it) with one addendum: arrays are considered to be ordered. Since objects aren't ordered, that doesn't apply. However, it does beg the question: If we have an ordered items keyword, should we also have an unordered items keyword (think boolean symmetry again)?
Supposing we have an unordered items keyword, what do we call it? I expect that it should also be applied before items
, but prefixItems
is already used.
But if we call it orderedItems
, that gives us the opportunity to create an unorderedItems
without any naming issues.
There is also some additional symmetry created by this:
items
(allItems
) andcontains
(anyitem
) (after extensive discussion at "unevaluatedItems" should consider "contains" #810 and some sort of resolution on Split "prefixItems" from "items", drop "additionalItems", make "unevaluatedItems" respect "contains" #925) work together to provide AND/OR functionality respectively for single subschemas.orderedItems
andunorderedItems
would provide that same functionality for multiple subschemas.