Proposal: add keyword firstOf #780
Replies: 2 comments 41 replies
-
The spec explicitly states that implementations may shortcut any keyword so long as it doesn't impact annotation collection. The openeing paragraph to Section 7 has this (emphasis added):
I think this gives you license to treat (It does appear we should amend the tests in /tests/draft2020-12/unevaluatedProperties.json to cater to the scenario where the first subschema matches, but a second subschema defines a property that should be considered "known" by |
Beta Was this translation helpful? Give feedback.
-
This was only posted two days ago, but already I feel very late to the party given the length and intensity of the discussion 😆. While I agree that the lack of ability to short circuit (in some cases) is a concern, I don't think this is the right solution. First, I don't think it's addressing the root cause of the problem. Second, there's already an existing solution that has even better performance characteristics than The root of the problem is the way annotation collection works. Annotation collection requires all schemas be evaluated and that's what breaks short circuiting. I don't think creating a new keyword to work around the consequence of that choice is the right thing. If short circuiting is something we want to optimize for, we should be questioning how annotation collection works or maybe questioning whether we should have keywords that rely on dynamic annotation evaluation like the "unevaluated" keywords. I have opinions on both of those, but I'm not going to get into it because I do think it matters. It doesn't matter because there's already a solution available to schema authors to avoid this problem and get even better performance (and error messaging) than |
Beta Was this translation helpful? Give feedback.
-
Making my implementation I realized that
anyOf
keyword produces unneccessary overhead in many cases where there are no benefits. The reason for this is the requirement to parse all the items despite the fact that in 99% of the cases we only need the first one. I tested all theanyOf
tests intest-suite
with the proposed behaviour and... it actually break only one test. Mean while the actual behaviour ofanyOf
keyword is also useful and everyone is already used to it. So, in order to obtain the desired behaviour the only choice would be to add a new keywordfirstOf
which will stop evaluating items when a valid item is encountered.Beta Was this translation helpful? Give feedback.
All reactions