Skip to main content

utoipa_helper/
lib.rs

1pub mod content_type_trait;
2pub mod html_response;
3pub mod json_response;
4pub mod response_description_trait;
5pub mod status_code_trait;
6
7pub use utoipa_helper_macro::UtoipaResponse;
8
9#[macro_export]
10macro_rules! derive_utoipa_schema {
11    ($T0:ty, $T1:ty) => {
12        impl utoipa::PartialSchema for $T0 {
13            fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
14                <$T1>::schema()
15            }
16        }
17
18        impl utoipa::ToSchema for $T0 {
19            fn name() -> std::borrow::Cow<'static, str> {
20                assert_eq!(std::mem::size_of::<$T0>(), std::mem::size_of::<$T1>());
21                <$T1>::name()
22            }
23            fn schemas(
24                schemas: &mut Vec<(
25                    String,
26                    utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
27                )>,
28            ) {
29                <$T1>::schemas(schemas)
30            }
31        }
32    };
33}
34
35#[macro_export]
36macro_rules! derive_utoipa_params {
37    ($T0:ty, $T1:ty) => {
38        impl utoipa::IntoParams for $T0 {
39            fn into_params(
40                parameter_in_provider: impl Fn() -> Option<utoipa::openapi::path::ParameterIn>,
41            ) -> Vec<utoipa::openapi::path::Parameter> {
42                <$T1>::into_params(parameter_in_provider)
43            }
44        }
45    };
46}
47
48#[macro_export]
49macro_rules! derive_utoipa_test {
50    ($T0:ty, $T1:ty) => {
51        assert_eq!(std::mem::size_of::<$T0>(), std::mem::size_of::<$T1>());
52    };
53}