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.
I'm not sure whether this should be done in a separate crate or not as it is quite a large addition, and isn't about generation, but I thought I'd start here anyway.
Also this has got to be my longest PR description thus far, sorry!
The goal of this PR is to implement validation of values with unknown structures against
Schema
s.For example:
It doesn't touch any derive features.
There are some unresolved questions and limitations that I haven't been able to solve yet.
My initial criteria were:
serde_json::Value
)Notable traits
Validate
Modelled after Serde's
Serialize
it allows validation of a value with aValidator
. It also has an associatedSpan
type which theValidator
can use in its errors.Validator
Modelled after Serde's
Serializer
with a bit less complexity, it provides interface for validation of values of different types.Span
Any kind of information about a value, usually probably a span of bytes or characters, but can be anything.
Spanner
It's a new word in this sense, but it is rather logical to me, it is used to provide spans for values.
Notable types
Spanned
A wrapper over Serde
Serialize
values, it implementsValidate
and also implementsSerializer
(in an inner type that is not exposed) that just proxies calls to theValidator
while collecting errors and using a givenSpanner
to provide spans.Features
validation
Everything in this PR is under a new feature called
validation
, and it is not enabled by default.Added Dependencies
Unresolved questions and missing things
format
field is ignored for now.$ref
s in the schema, and they have to be resolved before validation, I haven't found anything that does this, does it exist, or is it planned?ToString
bound, this issue is actually the only one that would tie this implementation to this crate, otherwise it's not a problem.There are also a few "TODO" comments that should be resolved before this is merged (if ever).