Skip to content

Improve JSON Schema validator errors#197

Merged
dmarcotte merged 5 commits intokson-org:mainfrom
dmarcotte:schema-validator-errors
Sep 12, 2025
Merged

Improve JSON Schema validator errors#197
dmarcotte merged 5 commits intokson-org:mainfrom
dmarcotte:schema-validator-errors

Conversation

@dmarcotte
Copy link
Contributor

@dmarcotte dmarcotte commented Sep 11, 2025

Improve the validation errors logged by some of our JSON Schema validators:

  • 491103b : anchor missing dependency errors to the property that demands the dependency
  • faaed8c : give explicit errors for allOf rather than just saying "not all schemas satisfied"
  • 23854cb : give explicit errors for anyOf rather 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

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
@dmarcotte dmarcotte force-pushed the schema-validator-errors branch from faaed8c to c1ce9b4 Compare September 11, 2025 15:14
@dmarcotte dmarcotte marked this pull request as ready for review September 11, 2025 15:41
@dmarcotte dmarcotte merged commit 99a6052 into kson-org:main Sep 12, 2025
1 check passed
@dmarcotte dmarcotte deleted the schema-validator-errors branch September 12, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant