-
-
Notifications
You must be signed in to change notification settings - Fork 313
Clarify how to combine boolean and numeric "items" annotations #904
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
Comments
@jdesrosiers I believe, if I'm reading it correctly, that this line in your validator uses a size and not the index: https://github.com/hyperjump-io/json-schema-validator/blob/6eab4c231a954c6df46e57b33933e0b4a1216f08/lib/keywords/items.js#L30 |
Why do you believe you need to combine the annotations? In regards to 2, you may have an Regarding 3. Consider annotations are only collected for successful validation. If the array schema values of Again, happy to provide examples if required. It's a little confusing at first. I got this wrong and even showed a dud example the last time I gave a JSON Schema talk at an international conference... 😳 |
Your explanation of annotations not being applied if a schema doesn't pass was a good reminder. It makes sense. However, I'm still not understanding why Boolean and number "items" annotations won't be combined, and also why an "items" annotation can't be -1. Some examples follow. An example illustrating why Boolean and number annotations would have to be combined:
When applying the first "items", an array, the max. index that got checked was "1", and so that's the annotation. Next, the second "items" is applied and it results in a Boolean annotation, "true". We have to combine these somehow. Or, instead of using a Boolean, we could instead use the max. processed index, which is "2". (The spec doesn't require a Boolean annotation here). Combining using the max. function results in "2". Example showing "items" annotation with "-1":
What's the max. index in the instance to which the array schema was applied? It's not zero, so what should it be? That's why I was proposing that the annotation is actually the valid item count instead of the largest index. |
The In terms of your example where
It doesn't have any subschemas, so it cannot apply them, and therefore produces no annotation results. Given it's a no-op, the fact it doesn't procude an annotations has no impact on further validation. |
Yes, you're making sense. :) But one other thing is maybe I'm misunderstanding how annotations are being collected. I thought that annotations are combined and collected for each element in the instance, independent of where they're from in the schema. i.e. whenever a location in the instance is "touched" by the schema and it's appropriate to add an annotation, an annotation is added and combined with others that may already be there. In my first example, two "items" schemas are applied to the main instance array (from inside the "allOf"; one is an array of schemas and the other is just a schema). This means that two "items" annotations will be applied to the main instance array. Is this not correct? If correct, don't two annotations that have the same name need to be combined? As I create a validator to learn how this all works, the following is my current mental model: unique annotations are collected whenever an instance element is "touched". So if a particular instance element is "touched" twice by "items" (from anywhere), those two annotations need to be combined somehow. Is this mental model even correct? The schema spec implies this whenever it mentions "combining annotations". Update: Quote from the spec:
Where else would a more "items" schemas get applied from if not from an "allOf" or something? |
@ssilverman My implementation doesn't collect annotations (not yet), so you don't want to look at my implementation as an example for that stuff. |
Specific answer: A Long general answer: Combining annotations during collection is an idea that hasn't made as much sense as it seemed to at first. The idea was simple enough: for So it seemed like a good idea to put that into the spec, as I had this notion of annotations being rolled up while they were collected and producing some sort of end value. "I sorted out a ton of But that's not actually how any of our recommended output formats work. Instead, those formats provide you (the end user getting the data back, or the code processing a schema object and examining the annotations from subschemas or adjacent keywords ini that object) with the information needed to make that determination. They don't provide a notion of rolled-up value. So I think we should drop that notion. We can still say that applications SHOULD treat a property as read-only (or whatever) if there is at least one In the case of |
See also #906 I'm going to close this because I think everything has been addressed or belongs with #906. Regarding "successful evaluation", with |
I'm implementing the "items" annotations and had some questions:
convert a "true" Boolean annotation value to the size of the array minus one? A "false" annotation value I think would convert to -1.
See: 9.3.1.1. items
The text was updated successfully, but these errors were encountered: