feat: implement aide::OperationInput/OperationOutput for extractors

This commit is contained in:
gengteng
2024-01-06 15:36:00 +08:00
parent 16283fd562
commit c96c146fd5
4 changed files with 101 additions and 16 deletions

View File

@@ -25,7 +25,6 @@ use std::ops::{Deref, DerefMut};
/// If using arguments, you must pass the arguments to Garde extractor via state, meaning implementing `FromRef<StateType>` for your validation arguments type.
///
#[derive(Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "aide", derive(aide::OperationIo))]
pub struct Garde<E>(pub E);
impl<E> Deref for Garde<E> {
@@ -58,6 +57,16 @@ impl<E> Garde<E> {
}
}
#[cfg(feature = "aide")]
impl<T> aide::OperationInput for Garde<T>
where
T: aide::OperationInput,
{
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
T::operation_input(ctx, operation);
}
}
/// `GardeRejection` is returned when the `Garde` extractor fails.
///
pub type GardeRejection<E> = ValidationRejection<Report, E>;