mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
add chrono support
This commit is contained in:
parent
887d874063
commit
84ff8acc68
3 changed files with 29 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -331,6 +331,7 @@ dependencies = [
|
|||
name = "gotham-restful"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fake 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -16,6 +16,7 @@ repository = "https://gitlab.com/msrd0/gotham-restful"
|
|||
gitlab = { repository = "msrd0/gotham-restful", branch = "master" }
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4", optional = true }
|
||||
failure = "0.1"
|
||||
futures = "0.1"
|
||||
gotham = "0.4"
|
||||
|
@ -34,5 +35,5 @@ log = "0.4"
|
|||
log4rs = { version = "0.8", features = ["console_appender"], default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["openapi"]
|
||||
default = ["openapi", "chrono"]
|
||||
openapi = ["indexmap", "log", "openapiv3"]
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#[cfg(feature = "chrono")]
|
||||
use chrono::{
|
||||
Date, DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, Utc
|
||||
};
|
||||
use openapiv3::{
|
||||
ArrayType, IntegerType, NumberType, ObjectType, ReferenceOr::Item, Schema, SchemaData, SchemaKind, StringType, Type
|
||||
ArrayType, IntegerType, NumberType, ObjectType, ReferenceOr::Item, Schema, SchemaData, SchemaKind,
|
||||
StringFormat, StringType, Type, VariantOrUnknownOrEmpty
|
||||
};
|
||||
|
||||
|
||||
|
@ -66,7 +71,21 @@ macro_rules! str_types {
|
|||
SchemaKind::Type(Type::String(StringType::default()))
|
||||
}
|
||||
}
|
||||
)*}
|
||||
)*};
|
||||
|
||||
(format = $format:ident, $($str_ty:ty),*) => {$(
|
||||
impl OpenapiType for $str_ty
|
||||
{
|
||||
fn to_schema() -> SchemaKind
|
||||
{
|
||||
SchemaKind::Type(Type::String(StringType {
|
||||
format: VariantOrUnknownOrEmpty::Item(StringFormat::$format),
|
||||
pattern: None,
|
||||
enumeration: Vec::new()
|
||||
}))
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
str_types!(String, &str);
|
||||
|
@ -91,3 +110,8 @@ impl<T : OpenapiType> OpenapiType for Vec<T>
|
|||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
str_types!(format = Date, Date<FixedOffset>, Date<Local>, Date<Utc>, NaiveDate);
|
||||
#[cfg(feature = "chrono")]
|
||||
str_types!(format = DateTime, DateTime<FixedOffset>, DateTime<Local>, DateTime<Utc>, NaiveDateTime);
|
||||
|
|
Loading…
Add table
Reference in a new issue