jsonschema-rs
jsonschema-rs copied to clipboard
Using $ref resolver outside validation
Is there currently functionality to transform a JSON Schema with $ref properties into a dereferenced JSON Schema (with sub-schema containing $ref properties replaced by the referenced schema)? e.g.
let mut schema = json!({
"properties": {
"foo": {"title": "Foo"},
"bar": {"$ref": "#/properties/foo"}
}
});
JSONSchema::dereference(&mut schema);
assert_eq!(schema, json!({
"properties": {
"foo": {"title": "Foo"},
"bar": {"title": "Foo"}
}
}))
This would be useful indeed!
Here are a few things to think about:
- Behavior for recursive references. I have a use case when it will be useful to inline all non-recursive references and leave recursive ones as they are. But I guess there could be other strategies too - return an error, cut at some recursion level if possible (e.g. if there is a place where the recursive branch is optional). Or maybe even a custom callback.
- I am not 100% sure about the behavior on
$dynamicRef, but it should probably work in a similar way