1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(transparent)]
pub struct JsonObject {
    #[serde(flatten)]
    map: serde_json::Map<String, Value>,
}

#[cfg(test)]
mod tests {
    use super::JsonObject;
    use schemars::schema_for;

    #[test]
    fn test_json_object_schema() {
        let schema = schema_for!(JsonObject);
        println!("{}", serde_json::to_string_pretty(&schema).unwrap());
        assert_eq!(
            serde_json::json!({
                "$schema": "http://json-schema.org/draft-07/schema#",
                "title": "Map_of_AnyValue",
                "additionalProperties": true,
                "type": "object"
            }),
            serde_json::json!(&schema)
        );
    }
}