utoipa_actix_web

Struct UtoipaApp

Source
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>
where T: ServiceFactory<ServiceRequest, Config = (), Error = Error, InitError = ()>,

Source

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());
Source

pub fn app_data<U: 'static>(self, data: U) -> Self

Passthrough implementation for actix_web::App::app_data.

Source

pub fn data_factory<F, Out, D, E>(self, data: F) -> Self
where F: Fn() -> Out + 'static, Out: Future<Output = Result<D, E>> + 'static, D: 'static, E: Debug,

Passthrough implementation for actix_web::App::data_factory.

Source

pub fn configure<F>(self, f: F) -> Self
where 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.

Source

pub fn route(self, path: &str, route: Route) -> Self

Passthrough implementation for actix_web::App::route.

Source

pub fn service<F>(self, factory: F) -> Self
where F: HttpServiceFactory + OpenApiFactory + 'static,

Extended version of actix_web::App::service method which handles schema and path collection from HttpServiceFactory.

Source

pub fn openapi_service<O, F>(self, factory: F) -> Self
where F: FnOnce(OpenApi) -> O, O: HttpServiceFactory + 'static,

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.

Source

pub fn default_service<F, U>(self, svc: F) -> Self
where F: IntoServiceFactory<U, ServiceRequest>, U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static, U::InitError: Debug,

Passthrough implementation for actix_web::App::default_service.

Source

pub fn external_resource<N, U>(self, name: N, url: U) -> Self
where N: AsRef<str>, U: AsRef<str>,

Passthrough implementation for actix_web::App::external_resource.

Source

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)
               }
           })
       });
Source

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.

Source

pub fn into_app(self) -> App<T>

Converts this UtoipaApp into the wrapped actix_web::App.

Trait Implementations§

Source§

impl<T> From<App<T>> for UtoipaApp<T>

Source§

fn from(value: App<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<UtoipaApp<T>> for App<T>

Source§

fn from(value: UtoipaApp<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for UtoipaApp<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for UtoipaApp<T>

§

impl<T> !Send for UtoipaApp<T>

§

impl<T> !Sync for UtoipaApp<T>

§

impl<T> Unpin for UtoipaApp<T>
where T: Unpin,

§

impl<T> !UnwindSafe for UtoipaApp<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T