jsonref

Crates.iojsonref
lib.rsjsonref
version0.4.0
sourcesrc
created_at2021-11-11 01:34:39.371853
updated_at2021-11-24 00:11:40.379186
descriptionDeref your JSONSchema here!
homepagehttps://github.com/kindly/jsonref-rs
repositoryhttps://github.com/kindly/jsonref-rs
max_upload_size
id479954
size19,258
(kindly)

documentation

README

jsonref dereferences JSONSchema $ref attributes and creates a new dereferenced schema.

Dereferencing is normally done by a JSONSchema validator in the process of validation, but it is sometimes useful to do this independent of the validator for tasks like:

  • Analysing a schema programatically to see what field there are.

  • Programatically modifying a schema.

  • Passing to tools that create fake JSON data from the schema.

  • Passing the schema to form generation tools.

Example:

use serde_json::json;
use jsonref::JsonRef;

let mut simple_example = json!(
          {"properties": {"prop1": {"title": "name"},
                          "prop2": {"$ref": "#/properties/prop1"}}
          }
       );

let mut jsonref = JsonRef::new();

jsonref.deref_value(&mut simple_example).unwrap();

let dereffed_expected = json!(
    {"properties": 
        {"prop1": {"title": "name"},
         "prop2": {"title": "name"}}
    }
);
assert_eq!(simple_example, dereffed_expected)

Note: If the JSONSchema has recursive $ref only the first recursion will happen. This is to stop an infinate loop.

Commit count: 7

cargo fmt