paperclip icon indicating copy to clipboard operation
paperclip copied to clipboard

Workaround for using `!Apiv2Schema` types in endpoints

Open oli-cosmian opened this issue 4 years ago • 2 comments

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.

oli-cosmian avatar May 06 '20 14:05 oli-cosmian

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).

wafflespeanut avatar May 14 '20 07:05 wafflespeanut

actix_multipart::Multipart now has the schema enabled through a feature gate (#182)

wafflespeanut avatar May 29 '20 05:05 wafflespeanut