poem icon indicating copy to clipboard operation
poem copied to clipboard

Support for multiple transforms

Open x1qqq opened this issue 2 years ago • 1 comments

Does poem-openapi support multiple transforms (middlewares) to be applied on endpoints

x1qqq avatar Feb 17 '23 19:02 x1qqq

I think you can just do the following

use poem::{Result, Endpoint, EndpointExt, middleware::{SizeLimit, SetHeader}};
use poem_openapi::{payload::Json, OpenApi};

pub struct Api;

fn transform(ep: impl Endpoint) -> impl Endpoint {
  ep.with(SizeLimit::new(15))
    .with(SetHeader::new().appending("MyHeader1", "a"))
}

#[OpenApi]
impl Api {
    #[oai(path = "/", method = "post", transform="transform")]
    async fn create(...) -> Result<...> {
        ...
}

mh-trimble avatar Mar 09 '23 00:03 mh-trimble