jsonschema-rs icon indicating copy to clipboard operation
jsonschema-rs copied to clipboard

Using $ref resolver outside validation

Open jpmckinney opened this issue 2 years ago • 1 comments

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"}
    }
}))

jpmckinney avatar Mar 22 '23 20:03 jpmckinney

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

Stranger6667 avatar Dec 29 '24 14:12 Stranger6667