utoipa_redoc/
actix.rs

1#![cfg(feature = "actix-web")]
2
3use actix_web::dev::HttpServiceFactory;
4use actix_web::guard::Get;
5use actix_web::web::Data;
6use actix_web::{HttpResponse, Resource, Responder};
7
8use crate::{Redoc, Spec};
9
10impl<S: Spec> HttpServiceFactory for Redoc<S> {
11    fn register(self, config: &mut actix_web::dev::AppService) {
12        let html = self.to_html();
13
14        async fn serve_redoc(redoc: Data<String>) -> impl Responder {
15            HttpResponse::Ok()
16                .content_type("text/html")
17                .body(redoc.to_string())
18        }
19
20        Resource::new(self.url.as_ref())
21            .guard(Get())
22            .app_data(Data::new(html))
23            .to(serve_redoc)
24            .register(config);
25    }
26}