Open AzHicham opened 2 weeks ago
Hi,
For the config function, do you use it before calling document
or after ? Is the Scope
coming from actix web or apistos ?
Sorry for the late reply
Scope is coming from apistos
and the config fn
is called after document
Here is my setup :
let server = HttpServer::new(move || {
actix_web::App::new()
.document(spec())
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, add_error_header))
.wrap(actix_logger())
.app_data(json_payload_config())
.wrap(no_cache_headers())
.wrap_fn(|mut req, srv| {
lowercase_path(&mut req);
srv.call(req)
})
.app_data(backend_v0.clone())
.app_data(backend_v1.clone())
.configure(|cfg| {
cfg.service(v0::config::<BackendV0>())
.service(v1::config::<BackendV1>())
.service(status::config::<BackendV0, BackendV1>());
})
.build_with(
"/openapi.json",
BuildConfig::default()
.with(SwaggerUIConfig::new(&"/swagger"))
.with(RedocConfig::new(&"/redoc")),
)
})
.bind((host, port))?
.workers(nb_workers as usize)
.run();
I make it work by duplicating wrap ... that's really weird. I cannot attach attach the auth with wrap to the scope, only inside fn service()
#[must_use]
fn public<T: Backend + StatusService + AnalysisService + GetAnalysisResult>() -> Scope
where
AppError: From<<T as AnalysisService>::Err>,
AppError: From<<T as GetAnalysisResult>::Err>,
{
let auth = HttpAuthentication::with_fn(validator::<T>);
scope("/public")
.service(status::config::<T>())
.service(analysis::config::<T>().wrap(auth.clone()))
.service(result::config::<T>().wrap(auth.clone()))
}
Hello,
I'm trying to use the middleware HttpAuthentication (from actix-web-httpauth), but I'm facing a compile issue since I'm using the wrap function from apistos and not directly actix.
Is this expected ?
my code :
Thanks you for your help