Skip to main content

axum_error_sets/
utoipa_impls.rs

1use super::*;
2use std::collections::BTreeMap;
3use utoipa::openapi::RefOr;
4
5macro_rules! impl_into_responses {
6    ($($error:ident),+ $(,)?) => {
7        impl<R, $($error),+> utoipa::IntoResponses for ErrorSet<R, ($($error,)+)>
8        where
9            R: UtoipaResponseFor,
10            $($error: StatusWrapper),+
11        {
12            fn responses() -> BTreeMap<String, RefOr<utoipa::openapi::Response>> {
13                let mut map = BTreeMap::new();
14                $(
15                    map.insert(
16                        $error::STATUS_CODE.as_u16().to_string(),
17                        RefOr::T(R::response_for($error::STATUS_CODE)),
18                    );
19                )+
20                map
21            }
22        }
23    };
24}
25
26impl_into_responses!(E1);
27impl_into_responses!(E1, E2);
28impl_into_responses!(E1, E2, E3);
29impl_into_responses!(E1, E2, E3, E4);
30impl_into_responses!(E1, E2, E3, E4, E5);
31impl_into_responses!(E1, E2, E3, E4, E5, E6);
32impl_into_responses!(E1, E2, E3, E4, E5, E6, E7);
33impl_into_responses!(E1, E2, E3, E4, E5, E6, E7, E8);
34impl_into_responses!(E1, E2, E3, E4, E5, E6, E7, E8, E9);
35impl_into_responses!(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10);
36impl_into_responses!(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11);
37impl_into_responses!(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12);
38
39impl<R> utoipa::IntoResponses for ErrorSet<R, ()>
40where
41    R: UtoipaResponseFor,
42{
43    fn responses() -> BTreeMap<String, RefOr<utoipa::openapi::Response>> {
44        BTreeMap::new()
45    }
46}