poem icon indicating copy to clipboard operation
poem copied to clipboard

Include middleware dependencies in openapi specification

Open skrcka opened this issue 4 months ago • 0 comments

Description of the feature

I want to use some header arguments inside a middleware and need them to be included in the OpenAPI specification. Currently I need to list header argument as dependency in every endpoint separate.

Code example (if possible)

pub struct SomeMiddleware<E> {
    ep: E,
}

impl<E: Endpoint> Endpoint for SomeMiddleware<E> {
    type Output = E::Output;

    async fn call(&self, mut req: Request) -> Result<Self::Output> {
        if let Some(value) = req
            .headers()
            .get("SOME_HEADER")
            .and_then(|value| value.to_str().ok())
            .filter(|value| value.starts_with("SOME PREFIX "))
            .map(|value| &value[7..])
        {
            ...some_new_dep_logic
            req.extensions_mut().insert(some_new_dep);
        }
        self.ep.call(req).await
    }
}

skrcka avatar Oct 07 '24 08:10 skrcka