Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include middleware dependencies in openapi specification #892

Open
skrcka opened this issue Oct 7, 2024 · 0 comments
Open

Include middleware dependencies in openapi specification #892

skrcka opened this issue Oct 7, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@skrcka
Copy link

skrcka commented Oct 7, 2024

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 skrcka added the enhancement New feature or request label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant