chore: updated schemas
This commit is contained in:
parent
b4ce0c764e
commit
73358b70cc
11 changed files with 1628 additions and 100 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use heck::{ToSnakeCase, ToUpperCamelCase};
|
||||
use indexmap::IndexMap;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{ToTokens, format_ident, quote};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::Ident;
|
||||
|
||||
use crate::openapi::r#type::OpenApiType;
|
||||
|
|
@ -82,6 +82,7 @@ pub struct Property {
|
|||
pub required: bool,
|
||||
pub nullable: bool,
|
||||
pub r#type: PropertyType,
|
||||
pub deprecated: bool,
|
||||
}
|
||||
|
||||
impl Property {
|
||||
|
|
@ -105,30 +106,25 @@ impl Property {
|
|||
name,
|
||||
description,
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
one_of: Some(types),
|
||||
..
|
||||
} => match types.as_slice() {
|
||||
[
|
||||
left,
|
||||
OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
},
|
||||
] => {
|
||||
[left, OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
}] => {
|
||||
let mut inner = Self::from_schema(&name, required, left, schemas)?;
|
||||
inner.nullable = true;
|
||||
Some(inner)
|
||||
}
|
||||
[
|
||||
left @ ..,
|
||||
OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
},
|
||||
] => {
|
||||
[left @ .., OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
}] => {
|
||||
let rest = OpenApiType {
|
||||
one_of: Some(left.to_owned()),
|
||||
..schema.clone()
|
||||
|
|
@ -141,9 +137,10 @@ impl Property {
|
|||
let r#enum = Enum::from_one_of(&name.to_upper_camel_case(), cases)?;
|
||||
Some(Self {
|
||||
name,
|
||||
description: None,
|
||||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Enum(r#enum),
|
||||
})
|
||||
}
|
||||
|
|
@ -155,9 +152,10 @@ impl Property {
|
|||
let composite = Object::from_all_of(&name.to_upper_camel_case(), types, schemas)?;
|
||||
Some(Self {
|
||||
name,
|
||||
description: None,
|
||||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Nested(Box::new(composite)),
|
||||
})
|
||||
}
|
||||
|
|
@ -173,6 +171,7 @@ impl Property {
|
|||
name,
|
||||
description,
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
|
|
@ -183,6 +182,7 @@ impl Property {
|
|||
description,
|
||||
r#type: PropertyType::Ref((*path).to_owned()),
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
|
|
@ -197,6 +197,7 @@ impl Property {
|
|||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Array(Box::new(inner.r#type)),
|
||||
})
|
||||
}
|
||||
|
|
@ -217,6 +218,7 @@ impl Property {
|
|||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Primitive(prim),
|
||||
})
|
||||
}
|
||||
|
|
@ -245,8 +247,17 @@ impl Property {
|
|||
ty_inner
|
||||
};
|
||||
|
||||
let deprecated = self.deprecated.then(|| {
|
||||
let note = self.description.as_ref().map(|d| quote! { note = #d });
|
||||
|
||||
quote! {
|
||||
#[deprecated(#note)]
|
||||
}
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
#desc
|
||||
#deprecated
|
||||
#serde_attr
|
||||
pub #name: #ty
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue