Improve JSON Schema validator errors#197
Merged
dmarcotte merged 5 commits intokson-org:mainfrom Sep 12, 2025
Merged
Conversation
The KsonString keys in a KsonObject are important data, particularly since they have their `Location` data. But previously, they were hard to access because they were used as keys.
This error is not anchored to the property which requires the dependency, with an error logged on that property per missing dependency
SCHEMA_OBJECT_REQUIRED clearly (poorly) copied/pasted its message from SCHEMA_NUMBER_REQUIRED. Fixed.
Rather than an opaque "must match at least one of the specified schemas" on the whole offending object, we now bubble up specific errors, anchoring them to specific KSON source when possible (i.e. when an error is applicable for all anyOf sub-schemas) This may yet be further improved, but this is a good step forward that also makes a good example of what's possible with regards to schema errors in KSON as we progressively polish the messaging across the entire schema validation system This change also involved enhancements our Message and KsonObject interfaces to facilate this type of better error messaging. Messages are now trivial to de-dupe by using a Set, and KsonObject values now make it much easier to report error by location of their keys.
Rather than one opaque message stating "must match all of the specified schemas", the AllOfValidator can directly log the combination of all messages returned by all validators
faaed8c to
c1ce9b4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve the validation errors logged by some of our JSON Schema validators:
dependencyerrors to the property that demands the dependencyallOfrather than just saying "not all schemas satisfied"anyOfrather than just saying "at least one schema must be satisfied". We do this by surfacing groups of errors for the unsatisfied schemas, and we also try make these errors even more clear when possible by unifying any common errors and displaying them inline.There are likely more improvements of this type to be applied to our schema validators, but we can progressively apply those improvements over time using these changes as examples to build on.
Note this pull also updates
KsonObject's interface to make the locations of its keys more accessible and fix a confusing paste-o that meant giving an incorrect error message