5 releases (3 breaking)

0.4.0 Nov 24, 2021
0.3.0 Nov 18, 2021
0.2.0 Nov 16, 2021
0.1.1 Nov 11, 2021
0.1.0 Nov 11, 2021

#14 in #programmatically

Download history 7/week @ 2023-12-21 6/week @ 2023-12-28 17/week @ 2024-01-04 31/week @ 2024-01-11 18/week @ 2024-01-18 90/week @ 2024-01-25 18/week @ 2024-02-01 87/week @ 2024-02-08 58/week @ 2024-02-15 70/week @ 2024-02-22 38/week @ 2024-02-29 20/week @ 2024-03-07 30/week @ 2024-03-14 32/week @ 2024-03-21 27/week @ 2024-03-28

112 downloads per month
Used in 2 crates (via libflatterer)

MIT license

17KB
233 lines

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.

Dependencies

~7.5MB
~238K SLoC