Struct utoipa_swagger_ui::SwaggerUi
source · [−]#[non_exhaustive]pub struct SwaggerUi { /* private fields */ }
Expand description
Entry point for serving Swagger UI and api docs in application. It uses provides builder style chainable configuration methods for configuring api doc urls.
Implementations
sourceimpl SwaggerUi
impl SwaggerUi
sourcepub fn new<P: Into<Cow<'static, str>>>(path: P) -> Self
pub fn new<P: Into<Cow<'static, str>>>(path: P) -> Self
Create a new SwaggerUi
for given path.
Path argument will expose the Swagger UI to the user and should be something that the underlying application framework / library supports.
Examples
Exposes Swagger UI using path /swagger-ui
using actix-web supported syntax.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}");
sourcepub fn url<U: Into<Url<'static>>>(self, url: U, openapi: OpenApi) -> Self
pub fn url<U: Into<Url<'static>>>(self, url: U, openapi: OpenApi) -> Self
Add api doc Url
into SwaggerUi
.
Method takes two arguments where first one is path which exposes the OpenApi
to the user.
Second argument is the actual Rust implementation of the OpenAPI doc which is being exposed.
Calling this again will add another url to the Swagger UI.
Examples
Expose manually created OpenAPI doc.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", utoipa::openapi::OpenApi::new(
utoipa::openapi::Info::new("my application", "0.1.0"),
utoipa::openapi::Paths::new(),
));
Expose derived OpenAPI doc.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", ApiDoc::openapi());
sourcepub fn urls(self, urls: Vec<(Url<'static>, OpenApi)>) -> Self
pub fn urls(self, urls: Vec<(Url<'static>, OpenApi)>) -> Self
Add multiple Url
s to Swagger UI.
Takes one Vec
argument containing tuples of Url
and OpenApi
.
Situations where this comes handy is when there is a need or wish to seprate different parts of the api to separate api docs.
Examples
Expose multiple api docs via Swagger UI.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.urls(
vec![
(Url::with_primary("api doc 1", "/api-doc/openapi.json", true), ApiDoc::openapi()),
(Url::new("api doc 2", "/api-doc/openapi2.json"), ApiDoc2::openapi())
]
);
Trait Implementations
sourceimpl HttpServiceFactory for SwaggerUi
impl HttpServiceFactory for SwaggerUi
fn register(self, config: &mut AppService)
Auto Trait Implementations
impl RefUnwindSafe for SwaggerUi
impl Send for SwaggerUi
impl Sync for SwaggerUi
impl Unpin for SwaggerUi
impl UnwindSafe for SwaggerUi
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more