schemars/json_schema_impls/
time.rs

1use crate::gen::SchemaGenerator;
2use crate::schema::*;
3use crate::JsonSchema;
4use std::time::{Duration, SystemTime};
5
6impl JsonSchema for Duration {
7    fn schema_name() -> String {
8        "Duration".to_owned()
9    }
10
11    fn json_schema(gen: &mut SchemaGenerator) -> Schema {
12        let mut schema = SchemaObject {
13            instance_type: Some(InstanceType::Object.into()),
14            ..Default::default()
15        };
16        let obj = schema.object();
17        obj.required.insert("secs".to_owned());
18        obj.required.insert("nanos".to_owned());
19        obj.properties
20            .insert("secs".to_owned(), <u64>::json_schema(gen));
21        obj.properties
22            .insert("nanos".to_owned(), <u32>::json_schema(gen));
23        schema.into()
24    }
25}
26
27impl JsonSchema for SystemTime {
28    fn schema_name() -> String {
29        "SystemTime".to_owned()
30    }
31
32    fn json_schema(gen: &mut SchemaGenerator) -> Schema {
33        let mut schema = SchemaObject {
34            instance_type: Some(InstanceType::Object.into()),
35            ..Default::default()
36        };
37        let obj = schema.object();
38        obj.required.insert("secs_since_epoch".to_owned());
39        obj.required.insert("nanos_since_epoch".to_owned());
40        obj.properties
41            .insert("secs_since_epoch".to_owned(), <u64>::json_schema(gen));
42        obj.properties
43            .insert("nanos_since_epoch".to_owned(), <u32>::json_schema(gen));
44        schema.into()
45    }
46}