feat(torn-api): add chrono for datetime support
This commit is contained in:
parent
266122ea0e
commit
7a4f6462f5
7 changed files with 741 additions and 22 deletions
|
|
@ -61,10 +61,7 @@ impl Model {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{
|
||||
model::r#enum::{EnumRepr, EnumVariant},
|
||||
openapi::schema::OpenApiSchema,
|
||||
};
|
||||
use crate::openapi::schema::OpenApiSchema;
|
||||
|
||||
#[test]
|
||||
fn resolve_newtypes() {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub enum PrimitiveType {
|
|||
I64,
|
||||
String,
|
||||
Float,
|
||||
DateTime,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
|
@ -35,6 +36,9 @@ impl PropertyType {
|
|||
Self::Primitive(PrimitiveType::String) => {
|
||||
Some(format_ident!("String").into_token_stream())
|
||||
}
|
||||
Self::Primitive(PrimitiveType::DateTime) => {
|
||||
Some(quote! { chrono::DateTime<chrono::Utc> })
|
||||
}
|
||||
Self::Primitive(PrimitiveType::Float) => Some(format_ident!("f64").into_token_stream()),
|
||||
Self::Ref(path) => {
|
||||
let name = path.strip_prefix("#/components/schemas/")?;
|
||||
|
|
@ -211,6 +215,7 @@ impl Property {
|
|||
PrimitiveType::Float
|
||||
}
|
||||
(Some("string"), None) => PrimitiveType::String,
|
||||
(Some("string"), Some("date")) => PrimitiveType::DateTime,
|
||||
(Some("boolean"), None) => PrimitiveType::Bool,
|
||||
_ => return None,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -303,12 +303,7 @@ The default value [Self::{}](self::{}#variant.{})"#,
|
|||
let mut code = inner.codegen().unwrap_or_default();
|
||||
|
||||
let name = format_ident!("{}", outer_name);
|
||||
let inner_ty = if matches!(items.as_ref(), ParameterType::Schema { type_name: _ }) {
|
||||
let inner_name = format_ident!("{}", inner_name);
|
||||
quote! { crate::models::#inner_name }
|
||||
} else {
|
||||
items.codegen_type_name(&inner_name).to_token_stream()
|
||||
};
|
||||
let inner_ty = items.codegen_type_name(&inner_name);
|
||||
|
||||
code.extend(quote! {
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue