schema_jsonrs/json_schema_impls/
chrono04.rs1use crate::SchemaGenerator;
2use crate::{json_schema, JsonSchema, Schema};
3use alloc::borrow::Cow;
4use chrono04::prelude::*;
5
6impl JsonSchema for Weekday {
7 always_inline!();
8
9 fn schema_name() -> Cow<'static, str> {
10 "Weekday".into()
11 }
12
13 fn schema_id() -> Cow<'static, str> {
14 "chrono::Weekday".into()
15 }
16
17 fn json_schema(_: &mut SchemaGenerator) -> Schema {
18 json_schema!({
19 "type": "string",
20 "enum": [
21 "Mon",
22 "Tue",
23 "Wed",
24 "Thu",
25 "Fri",
26 "Sat",
27 "Sun",
28 ]
29 })
30 }
31}
32
33macro_rules! formatted_string_impl {
34 ($ty:ident, $format:literal) => {
35 formatted_string_impl!($ty, $format, JsonSchema for $ty);
36 };
37 ($ty:ident, $format:literal, $($desc:tt)+) => {
38 impl $($desc)+ {
39 always_inline!();
40
41 fn schema_name() -> Cow<'static, str> {
42 stringify!($ty).into()
43 }
44
45 fn schema_id() -> Cow<'static, str> {
46 stringify!(chrono::$ty).into()
47 }
48
49 fn json_schema(_: &mut SchemaGenerator) -> Schema {
50 json_schema!({
51 "type": "string",
52 "format": $format
53 })
54 }
55 }
56 };
57}
58
59formatted_string_impl!(NaiveDate, "date");
60formatted_string_impl!(NaiveDateTime, "partial-date-time");
61formatted_string_impl!(NaiveTime, "partial-time");
62formatted_string_impl!(DateTime, "date-time", <Tz: TimeZone> JsonSchema for DateTime<Tz>);