paperclip
paperclip copied to clipboard
Workaround for using `!Apiv2Schema` types in endpoints
Would it make sense to expose a type like
#[derive(Apiv2Schema)]
#[openapi(empty)]
struct Wrapper<T>(T);
impl<T: FromRequest> FromRequest for Wrapper<T> {
type Error = <T as FromRequest>::Error;
type Config = <T as FromRequest>::Config;
type Future = Pin<Box<dyn std::future::Future<Output = Result<Self, Self::Error>>>>;
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
let fut = T::from_request(req, payload);
Box::pin(async move { fut.await.map(Self) })
}
}
that allows users to discard arguments to their endpoint functions if paperclip doesn't have support for it.
We use such a type for our actix_multipart::Multipart
endpoints.
We can certainly expose this. We already have something similar called ResponderWrapper
(which we use for impl Responder
stuff). Although, if they're types from other commonly used crates, then we can include the impl in paperclip itself and expose it through a feature gate (like we do for chrono::Datetime
and uuid::Uuid
).
I'm sorry I've missed this for a long time (feel free to poke me next time just in case I missed something).
actix_multipart::Multipart
now has the schema enabled through a feature gate (#182)