Skip to main content

DocumentedLayer

Trait DocumentedLayer 

Source
pub trait DocumentedLayer {
    // Required method
    fn contribution(&self) -> LayerContribution;
}
Expand description

A tower Layer that declares its own OpenAPI contribution.

Implement this on the same struct that implements tower::Layer, so call sites can use crate::OpenApiRouterExt::layer_documented with a single argument and the contribution is inferred from the layer’s type.

use doxa::{
    DocumentedLayer, HeaderParam, LayerContribution,
    ResponseContribution, SecurityContribution,
};

pub struct MyAuthLayer { /* … */ }
impl<S> tower::Layer<S> for MyAuthLayer {
    /* … */
}
impl DocumentedLayer for MyAuthLayer {
    fn contribution(&self) -> LayerContribution {
        LayerContribution::new()
            .with_header(HeaderParam::required("Authorization"))
            .with_response(ResponseContribution::unauthorized())
            .with_security(SecurityContribution::new("bearer"))
    }
}

Required Methods§

Source

fn contribution(&self) -> LayerContribution

Return the OpenAPI contribution this layer adds to every operation it covers. Called once at router-build time, on every crate::OpenApiRouterExt::layer_documented invocation.

Implementors§