pub struct UtoipaApp<T>(/* private fields */);
Expand description
Wrapper type for actix_web::App
and utoipa::openapi::OpenApi
.
UtoipaApp
behaves exactly same way as actix_web::App
but allows automatic schema
and
path
collection from service(...)
calls directly or via ServiceConfig::service
.
It exposes typical methods from actix_web::App
and provides custom UtoipaApp::map
method to add additional configuration options to wrapper actix_web::App
.
This struct need be instantiated from actix_web::App
by calling .into_utoipa_app()
because we do not have access to actix_web::App<T>
generic argument and the App
does
not provide any default implementation.
§Examples
Create new UtoipaApp
instance.
let utoipa_app = App::new().into_utoipa_app();
Convert actix_web::App<T>
to UtoipaApp<T>
.
let a: UtoipaApp<_> = actix_web::App::new().into();
Implementations§
Source§impl<T> UtoipaApp<T>
impl<T> UtoipaApp<T>
Sourcepub fn openapi(self, openapi: OpenApi) -> Self
pub fn openapi(self, openapi: OpenApi) -> Self
Replace the wrapped utoipa::openapi::OpenApi
with given openapi
.
This is useful to prepend OpenAPI doc generated with UtoipaApp
with content that cannot be provided directly via UtoipaApp
.
§Examples
Replace wrapped utoipa::openapi::OpenApi
with custom one.
#[derive(OpenApi)]
#[openapi(info(title = "Api title"))]
struct Api;
let _ = actix_web::App::new().into_utoipa_app().openapi(Api::openapi());
Sourcepub fn app_data<U: 'static>(self, data: U) -> Self
pub fn app_data<U: 'static>(self, data: U) -> Self
Passthrough implementation for actix_web::App::app_data
.
Sourcepub fn data_factory<F, Out, D, E>(self, data: F) -> Self
pub fn data_factory<F, Out, D, E>(self, data: F) -> Self
Passthrough implementation for actix_web::App::data_factory
.
Sourcepub fn configure<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut ServiceConfig<'_>),
pub fn configure<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut ServiceConfig<'_>),
Extended version of actix_web::App::configure
which handles schema
and path
collection from ServiceConfig
into the wrapped utoipa::openapi::OpenApi
instance.
Sourcepub fn route(self, path: &str, route: Route) -> Self
pub fn route(self, path: &str, route: Route) -> Self
Passthrough implementation for actix_web::App::route
.
Sourcepub fn service<F>(self, factory: F) -> Selfwhere
F: HttpServiceFactory + OpenApiFactory + 'static,
pub fn service<F>(self, factory: F) -> Selfwhere
F: HttpServiceFactory + OpenApiFactory + 'static,
Extended version of actix_web::App::service
method which handles schema
and path
collection from HttpServiceFactory
.
Sourcepub fn openapi_service<O, F>(self, factory: F) -> Self
pub fn openapi_service<O, F>(self, factory: F) -> Self
Helper method to serve wrapped utoipa::openapi::OpenApi
via HttpServiceFactory
.
This method functions as a convenience to serve the wrapped OpenAPI spec alternatively to
first call UtoipaApp::split_for_parts
and then calling actix_web::App::service
.
Sourcepub fn default_service<F, U>(self, svc: F) -> Selfwhere
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,
U::InitError: Debug,
pub fn default_service<F, U>(self, svc: F) -> Selfwhere
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,
U::InitError: Debug,
Passthrough implementation for actix_web::App::default_service
.
Sourcepub fn external_resource<N, U>(self, name: N, url: U) -> Self
pub fn external_resource<N, U>(self, name: N, url: U) -> Self
Passthrough implementation for actix_web::App::external_resource
.
Sourcepub fn map<F: FnOnce(App<T>) -> App<NF>, NF: ServiceFactory<ServiceRequest, Config = (), Error = Error, InitError = ()>>(
self,
op: F,
) -> UtoipaApp<NF>
pub fn map<F: FnOnce(App<T>) -> App<NF>, NF: ServiceFactory<ServiceRequest, Config = (), Error = Error, InitError = ()>>( self, op: F, ) -> UtoipaApp<NF>
Convenience method to add custom configuration to actix_web::App
that is not directly
exposed via UtoipaApp
. This could for example be adding middlewares.
§Examples
Add middleware via map
method.
let _ = App::new()
.into_utoipa_app()
.map(|app| {
app.wrap_fn(|req, srv| {
let fut = srv.call(req);
async {
let mut res = fut.await?;
res.headers_mut()
.insert(CONTENT_TYPE, HeaderValue::from_static("text/plain"));
Ok(res)
}
})
});
Sourcepub fn split_for_parts(self) -> (App<T>, OpenApi)
pub fn split_for_parts(self) -> (App<T>, OpenApi)
Split this UtoipaApp
into parts returning tuple of actix_web::App
and
utoipa::openapi::OpenApi
of this instance.
Sourcepub fn into_app(self) -> App<T>
pub fn into_app(self) -> App<T>
Converts this UtoipaApp
into the wrapped actix_web::App
.