reactive_graph_graph/
json_schema.rs

1use schemars::Schema;
2use serde_json::json;
3
4pub(crate) fn add_json_schema_id_property(schema: &mut Schema, id: &str) {
5    let root_schema = schema.ensure_object();
6    root_schema
7        .get_mut("properties")
8        .and_then(|properties| properties.as_object_mut())
9        .map(|properties| {
10            properties.insert(
11                "$id".to_owned(),
12                json!({
13                    "default": id.to_owned(),
14                    "description": "The schema identifier",
15                    "type": "string"
16                }),
17            )
18        })
19        .expect("Inserting $id into json schema failed: Expected field 'properties'");
20}