-
-
Notifications
You must be signed in to change notification settings - Fork 111
Add schema paths to compilation context; this change requires changin… #226
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
Add schema paths to compilation context; this change requires changin… #226
Conversation
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.
Yep, this is something I had in mind :) The invariant we should get in the end is - Looking up the resulting JSON Pointer in the input schema should lead to the sub-schema that failed validation.
For example:
{
"properties": {
"foo": {
"type": "string"
}
}
}
In the schema above, the stack for the type
validator should look like this - ["properties", "foo"]
. Converting it to a JSON Pointer will give us /properties/foo
and passing it to schema.pointer
(assuming it is serde_json::Value
) should return {"type": "string"}
:
#[test]
fn test_schema_path() {
let schema = json!({
"properties": {
"foo": {
"type": "string"
}
}
});
let instance = json!({"foo": 42});
let compiled = JSONSchema::compile(&schema).unwrap();
let result = compiled.validate(&instance);
let error = result.expect_err("Errors").next();
let pointer = error.schema_path.to_string();
assert_eq!(schema.pointer(&pointer), Some(&json!({"type": "string"})))
}
) -> CompilationResult { | ||
context.schema_path.push(schema.to_string()); |
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.
I believe it should be context.schema_path.push("additionalItems".to_string());
jsonschema/src/keywords/all_of.rs
Outdated
let mut schemas = Vec::with_capacity(items.len()); | ||
for item in items { | ||
context.schema_path.push(item.to_string()); |
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.
Here we need indexes within items
- e.g., apply enumerate
to the items
above and store indexes like strings. Similar applies to anyOf
validator implementation below.
) -> Result<BigValidatorsMap, CompilationError> { | ||
let mut properties = AHashMap::with_capacity(map.len()); | ||
for (key, subschema) in map { | ||
context.schema_path.push(subschema.to_string()); |
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.
It should be key
instead of subschema
) -> Result<SmallValidatorsMap, CompilationError> { | ||
let mut properties = Vec::with_capacity(map.len()); | ||
for (key, subschema) in map { | ||
context.schema_path.push(subschema.to_string()); |
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.
It should be key
instead of subschema
Hi @DzikiChrzan ! Let me know if I can help here :) |
6791aec
to
61fa7ab
Compare
Codecov Report
@@ Coverage Diff @@
## master #226 +/- ##
==========================================
- Coverage 82.89% 82.57% -0.32%
==========================================
Files 53 53
Lines 3660 3869 +209
==========================================
+ Hits 3034 3195 +161
- Misses 626 674 +48
Continue to review full report at Codecov.
|
I made some progress on this (I hope you don't mind), and it seems like there is not that much left to do. My current todo items are:
Changing |
…g mutability of compilation context
a6f1b8b
to
d279ceb
Compare
Add schema paths to compilation context; this change requires changing mutability of compilation context
Work in progress
#199