Skip to content
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

Clarify that adjacent keywords evaluate as if by "allOf" #896

Closed
ssilverman opened this issue Apr 23, 2020 · 5 comments
Closed

Clarify that adjacent keywords evaluate as if by "allOf" #896

ssilverman opened this issue Apr 23, 2020 · 5 comments
Assignees
Labels

Comments

@ssilverman
Copy link
Member

It doesn't seem clear in the spec that a schema evaluates to true if all its keywords also evaluate to true. i.e. an allOf behaviour.

@karenetheridge
Copy link
Member

It's implicit, but I suppose it could be made more explicit in a few places.

The spec does say that an empty schema validates to true, and when defining each keyword, it says something like "the keyword has no effect when it is absent", and "the instance successfully validates against the keyword when ..." or "the instance does not successfully validate against the keyword when ...".

Also "JSON Schema implementations produce a single boolean result when evaluating an instance against schema assertions." (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.7.6) -- This section could possibly add something like: "...that means that when multiple keywords apply to the instance at a particular schema location, the single boolean result is the result of ANDing all the individual assertions together."

@ssilverman
Copy link
Member Author

I would argue that it's not implicit what to do with the keyword results. Here's why: In the paragraph containing quoted parts about keywords ("The spec does say..."), it effectively states that "each keyword results in a Boolean value when evaluated against an instance." i.e. a successful validation produces "true" and an unsuccessful one produces "false". We also start with a value of "true" when there's an empty schema.

So now, given a collection of evaluated keywords, we have a resulting set of Boolean values.

Next, there is "JSON Schema implementations produce a single boolean result". This means, as an implementor, I have to somehow combine a collection of Boolean values into a single Boolean result. This is where I feel there's no such implicit step. How to transform a set of Boolean values into a single Boolean value?

Now, it doesn't say (or at least I haven't found where) that all keywords must successfully validate in order for a schema to successfully validate. If it did, that would indeed imply a logical AND. I think your suggested addition is necessary to link "collection of Boolean values" with "single Boolean result." We could additionally add some statement to the effect of, "All keywords must successfully validate in order for the schema to successfully validate." Or: "A schema validates if and only if all keywords successfully validate." (To use the mathematical strong bidirectional "if".)

@handrews
Copy link
Contributor

Yeah we should do this. It was supposed to be part of #849 (which expanded to cover both loading and processing of schemas), but that issue is probably too ambitious for the next draft and we should cover this one key bit.

@Relequestual
Copy link
Member

Relequestual commented Oct 26, 2020

Looking at this again, it IS covered by the validation spec document already, although not with any requirement level keywords...

JSON Schema validation asserts constraints on the structure of instance data. An instance location that satisfies all asserted constraints is then annotated with any keywords that contain non-assertion information, such as descriptive metadata and usage hints. If all locations within the instance satisfy all asserted constraints, then the instance is said to be valid against the schema.

https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.3

This hasn't changed in roughly 3 years.

Is the above not enough?
@ssilverman if it is, can we close this issue?

@ssilverman
Copy link
Member Author

Yes, I guess that sentence is enough. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants