chore: updated schemas

This commit is contained in:
TotallyNot 2025-05-19 20:09:38 +02:00
parent b4ce0c764e
commit 73358b70cc
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
11 changed files with 1628 additions and 100 deletions

View file

@ -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
})

View file

@ -1,4 +1,4 @@
use std::{fmt::Write, ops::Deref};
use std::fmt::Write;
use heck::{ToSnakeCase, ToUpperCamelCase};
use indexmap::IndexMap;
@ -40,7 +40,7 @@ pub struct Path {
pub segments: Vec<PathSegment>,
pub name: String,
pub summary: Option<String>,
pub description: String,
pub description: Option<String>,
pub parameters: Vec<PathParameter>,
pub response: PathResponse,
}
@ -63,7 +63,7 @@ impl Path {
}
let summary = schema.get.summary.as_deref().map(ToOwned::to_owned);
let description = schema.get.description.deref().to_owned();
let description = schema.get.description.as_deref().map(ToOwned::to_owned);
let mut params = Vec::with_capacity(schema.get.parameters.len());
for parameter in &schema.get.parameters {
@ -377,7 +377,23 @@ impl Path {
}
};
let doc = match (&self.summary, &self.description) {
(Some(summary), Some(description)) => {
Some(format!("{summary}\n\n# Description\n{description}"))
}
(Some(summary), None) => Some(summary.clone()),
(None, Some(description)) => Some(format!("# Description\n{description}")),
(None, None) => None,
};
let doc = doc.map(|d| {
quote! {
#[doc = #d]
}
});
Some(quote! {
#doc
pub async fn #fn_name<S>(
self,
#(#extra_args)*
@ -487,7 +503,23 @@ impl Path {
quote! { #(#disc_ty),* }
};
let doc = match (&self.summary, &self.description) {
(Some(summary), Some(description)) => {
Some(format!("{summary}\n\n# Description\n{description}"))
}
(Some(summary), None) => Some(summary.clone()),
(None, Some(description)) => Some(format!("# Description\n{description}")),
(None, None) => None,
};
let doc = doc.map(|d| {
quote! {
#[doc = #d]
}
});
Some(quote! {
#doc
pub fn #fn_name<S, I, B>(
self,
ids: I,

View file

@ -50,6 +50,7 @@ impl Scope {
}
Some(quote! {
#[allow(dead_code)]
pub struct #name<E>(E)
where
E: crate::executor::Executor;
@ -65,6 +66,7 @@ impl Scope {
#(#functions)*
}
#[allow(dead_code)]
pub struct #bulk_name<E> where
E: crate::executor::BulkExecutor,
{