-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Replace ValidationError::schema
with custom errors
#280
Replace ValidationError::schema
with custom errors
#280
Conversation
Thank you @zhiburt ! I am happy to see your contribution :) I'll try to review this in the next few days :) Could you, please:
|
I think it is alright, in any case, it is an improvement over the status quo
That's alright :) |
Codecov Report
@@ Coverage Diff @@
## master #280 +/- ##
==========================================
- Coverage 83.15% 80.50% -2.65%
==========================================
Files 56 56
Lines 5124 5336 +212
==========================================
+ Hits 4261 4296 +35
- Misses 863 1040 +177
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During the compilation phase, schema_path
means a path within the JSON Schema meta schemas, and instance_path
is a path within the input schema. Given that, the schema_path
argument to ValidationError
constructors can't be easily derived, so we can leave it empty - this is a corner case anyway (something that metaschema validation doesn't catch).
So, we need to put pointers constructed from context
to instance_path
argument and JSONPointer::default()
to the schema_path
one. As far as I see, it is the other way around now.
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
So its essentially pointers to this map? I am curious if we could reuse |
Yep, I'd say that they point to some locations within the values of this map.
In the majority of the cases, these Of course, we may try to keep the meta-schema context manually and trace all the paths during the compilation. However, it will be hard to do as we'll need to do it differently for different JSON Schema drafts, so I assume it will be easier to tweak the meta-schema instead - it happened before and was caused by an actual bug in meta schemas. Hope I helps :) |
I guess I did make a typo. ValidationError::format(self.schema_path, context.clone().into_pointer(), ...) |
These structures are available only after compilation, the compilation process creates a tree of them. We already use meta-schema validators during the compilation process - errors from it will have exactly these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments - most of them are quite similar to each other and mostly are about choosing the proper ValidationError
variant
Co-authored-by: dmitry.dygalo <dadygalo@gmail.com> Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
You've spend quite a bit of time reviewing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think we're getting closer to merging :) A couple of minor things
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Co-Authored-by: dmitry.dygalo <dadygalo@gmail.com>
Awesome! Thanks :) |
Hi there, bump into here via hacktoberfest mark.
Honestly most likely it doesn't address
JSONPointer
correctly in errors.And I was not sure which type of error better use for things like as64 error or regex syntax error but I did used
ValidationError::format
.Note: there might be an issue with cargo fmt.
closes #235
Thank you for the library.