-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Report schema paths in validation errors #199
Comments
May I take a swing on this? |
Hi @DzikiChrzan! Absolutely! Let me know if you have any questions on it :) |
I've been studying the code and I can't fully understand the flow of the data.
|
{
"cmd": ["ls", "-lh", "/home"]
} If we'd like to extract the "/home" string, then we need to take the following steps when navigating from the document root:
When The main point of this two-variant enum is to avoid creating heap-allocated strings for indexes within JSON arrays as I'll update the docs for these structs, and maybe
I think that
I'll try to describe the main blocks of the compilation process first, as the validation part uses its outcomes. The schema compilation starts in compilation::options::CompilationOptions::compile, and its goal is to traverse the input schema and build a tree of validators. This tree is actually a vector of pointers (then it is a forest, I believe) that reference validators that implement the Each validator there knows how to process their inputs. For example - if the input is When the validation process starts inside JSONSchema::validate, it iterates over the top validators level and delegates validation to them. As they know how to process their respective inputs, the I hope that it helps :) If not - I'd be happy to elaborate. |
I think that one's one understands point of Thank you for thorough explanation. I'll get back at you when I'll have de# mind, probably tommorow. |
I just noticed, that gavadinov@4014932 is not merged yet. |
The best way is to use that commit as inspiration & implement this issue separately. It changes most of the places required to implement this issue, and that approach works. The original goal of that commit was to track paths within instances, but the implementation was then re-worked in #184. Instances can't be unambiguously tracked by having data only from the input schema. However, the initial take in that commit could be extended to track paths within schemas. After that point, I changed the way instance paths are tracked - it uses a linked list without allocating a vector for the path components. Probably something similar can be done for paths in schemas as well. Still, I'm happy with a vector-based stack as the compilation step performance is not that important compared to validation. |
Sorry for long no-response period, but I got some time off and was resting from computer. |
Hi @DzikiChrzan Thank you, I'll check it tomorrow :) |
Ref: #199 Co-authored-by: ueco <ueco@libertymail.net> Co-authored-by: Dmitry Dygalo <dadygalo@gmail.com>
Resolved via #226 Thank you, @DzikiChrzan, for taking a step on this :) I added few more things on top in that PR |
When a validation error is reported, it contains only
instance_path
that points to the erroneous part of the input, but there is no information about what part of the schema caused this error.The gist of the implementation is to keep a stack of strings while the input schema is compiled. The stack should be convertible to
paths::JSONPointer
.The process for regular, non-composite validators (more on this below):
properties
);I think that pushing/popping could be implemented similarly to
instance_path
- a linked list without heap allocations. This way, the actual popping step is not needed at all.Composite validators are slightly more complicated - they are single structs that implement the logic for multiple different keywords or their specific variants (e.g. this one handles
patternProperties
andadditionalProperties: false
) which is done due to performance reasons.To handle them, the stack should not be pushed during compilation, but rather during validation - if a validation error happens, the stored stack should be cloned, and the exact keyword variant should be pushed to it. And finally, it is moved to
ValidationError
.Validators live in
keywords
.A lot of work in this direction was done by @gavadinov in gavadinov@4014932, and I think that it could be a great base for implementing this feature.
@gavadinov, let me know if you are OK if somebody can base their work on your commit, or if you want to continue it yourself :)
The text was updated successfully, but these errors were encountered: