Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/aide/src/axum/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,40 @@ where
add_parameters(ctx, operation, params);
}
}

#[cfg(feature = "axum-extra")]
mod extra {
use axum_extra::either;

use super::*;

macro_rules! impl_either {
($ty:ident, $($e:ident),*) => {
impl<$($e),*> OperationInput for either::$ty<$($e),*>
where
$($e: OperationInput),*
{
fn operation_input(ctx: &mut crate::generate::GenContext, operation: &mut Operation) {
$($e::operation_input(ctx, operation);)*
}

fn inferred_early_responses(
ctx: &mut crate::generate::GenContext,
operation: &mut Operation,
) -> Vec<(Option<StatusCode>, Response)> {
let mut responses = Vec::new();
$(responses.extend($e::inferred_early_responses(ctx, operation));)*
responses
}
}
}
}

impl_either!(Either, E1, E2);
impl_either!(Either3, E1, E2, E3);
impl_either!(Either4, E1, E2, E3, E4);
impl_either!(Either5, E1, E2, E3, E4, E5);
impl_either!(Either6, E1, E2, E3, E4, E5, E6);
impl_either!(Either7, E1, E2, E3, E4, E5, E6, E7);
impl_either!(Either8, E1, E2, E3, E4, E5, E6, E7, E8);
}
30 changes: 29 additions & 1 deletion crates/aide/src/axum/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl OperationOutput for Redirect {
#[cfg(feature = "axum-extra")]
#[allow(unused_imports)]
mod extra {
use axum_extra::{extract, response};
use axum_extra::{either, extract, response};

use super::*;
use crate::{
Expand All @@ -266,6 +266,34 @@ mod extra {
operation::OperationOutput,
};

macro_rules! impl_either {
($ty:ident, $($e:ident),*) => {
impl<$($e),*> OperationOutput for either::$ty<$($e),*>
where
$($e: OperationOutput),*
{
type Inner = Self;

fn inferred_responses(
ctx: &mut GenContext,
operation: &mut Operation,
) -> Vec<(Option<StatusCode>, Response)> {
let mut responses = Vec::new();
$(responses.extend($e::inferred_responses(ctx, operation));)*
responses
}
}
}
}

impl_either!(Either, E1, E2);
impl_either!(Either3, E1, E2, E3);
impl_either!(Either4, E1, E2, E3, E4);
impl_either!(Either5, E1, E2, E3, E4, E5);
impl_either!(Either6, E1, E2, E3, E4, E5, E6);
impl_either!(Either7, E1, E2, E3, E4, E5, E6, E7);
impl_either!(Either8, E1, E2, E3, E4, E5, E6, E7, E8);

#[cfg(feature = "axum-extra-cookie")]
impl OperationOutput for extract::CookieJar {
type Inner = ();
Expand Down