schemars/json_schema_impls/
time.rs

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use std::time::{Duration, SystemTime};

impl JsonSchema for Duration {
    fn schema_name() -> String {
        "Duration".to_owned()
    }

    fn json_schema(gen: &mut SchemaGenerator) -> Schema {
        let mut schema = SchemaObject {
            instance_type: Some(InstanceType::Object.into()),
            ..Default::default()
        };
        let obj = schema.object();
        obj.required.insert("secs".to_owned());
        obj.required.insert("nanos".to_owned());
        obj.properties
            .insert("secs".to_owned(), <u64>::json_schema(gen));
        obj.properties
            .insert("nanos".to_owned(), <u32>::json_schema(gen));
        schema.into()
    }
}

impl JsonSchema for SystemTime {
    fn schema_name() -> String {
        "SystemTime".to_owned()
    }

    fn json_schema(gen: &mut SchemaGenerator) -> Schema {
        let mut schema = SchemaObject {
            instance_type: Some(InstanceType::Object.into()),
            ..Default::default()
        };
        let obj = schema.object();
        obj.required.insert("secs_since_epoch".to_owned());
        obj.required.insert("nanos_since_epoch".to_owned());
        obj.properties
            .insert("secs_since_epoch".to_owned(), <u64>::json_schema(gen));
        obj.properties
            .insert("nanos_since_epoch".to_owned(), <u32>::json_schema(gen));
        schema.into()
    }
}