| 1 | use crate::SchemaGenerator; |
| 2 | use crate::{json_schema, JsonSchema, Schema}; |
| 3 | use alloc::borrow::Cow; |
| 4 | |
| 5 | impl JsonSchema for core::time::Duration { |
| 6 | fn schema_name() -> Cow<'static, str> { |
| 7 | "Duration".into() |
| 8 | } |
| 9 | |
| 10 | fn schema_id() -> Cow<'static, str> { |
| 11 | "std::time::Duration".into() |
| 12 | } |
| 13 | |
| 14 | fn json_schema(generator: &mut SchemaGenerator) -> Schema { |
| 15 | json_schema!({ |
| 16 | "type": "object", |
| 17 | "required": ["secs", "nanos"], |
| 18 | "properties": { |
| 19 | "secs": u64::json_schema(generator), |
| 20 | "nanos": u32::json_schema(generator), |
| 21 | } |
| 22 | }) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | #[cfg(feature = "std")] |
| 27 | impl JsonSchema for std::time::SystemTime { |
| 28 | fn schema_name() -> Cow<'static, str> { |
| 29 | "SystemTime".into() |
| 30 | } |
| 31 | |
| 32 | fn schema_id() -> Cow<'static, str> { |
| 33 | "std::time::SystemTime".into() |
| 34 | } |
| 35 | |
| 36 | fn json_schema(generator: &mut SchemaGenerator) -> Schema { |
| 37 | json_schema!({ |
| 38 | "type": "object", |
| 39 | "required": ["secs_since_epoch", "nanos_since_epoch"], |
| 40 | "properties": { |
| 41 | "secs_since_epoch": u64::json_schema(generator), |
| 42 | "nanos_since_epoch": u32::json_schema(generator), |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | } |