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.
Currently actix-web, rocket, axum
frameworks supports SwaggerUi
type.
Examples
Create new SwaggerUi
with defaults.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", ApiDoc::openapi());
Create a new SwaggerUi
with custom Config
and oauth::Config
.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", ApiDoc::openapi())
.config(Config::default().try_it_out_enabled(true).filter(true))
.oauth(oauth::Config::new());
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 separate 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())
]
);
sourcepub fn oauth(self, oauth: Config) -> Self
pub fn oauth(self, oauth: Config) -> Self
Add oauth oauth::Config
into SwaggerUi
.
Method takes one argument which exposes the oauth::Config
to the user.
Examples
Enable pkce with default client_id.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", ApiDoc::openapi())
.oauth(oauth::Config::new()
.client_id("client-id")
.scopes(vec![String::from("openid")])
.use_pkce_with_authorization_code_grant(true)
);
sourcepub fn config(self, config: Config<'static>) -> Self
pub fn config(self, config: Config<'static>) -> Self
Add custom Config
into SwaggerUi
which gives users more granular control over
Swagger UI options.
Methods takes one Config
argument which exposes Swagger UI’s configurable options
to the users.
Examples
Create a new SwaggerUi
with custom configuration.
let swagger = SwaggerUi::new("/swagger-ui/{_:.*}")
.url("/api-doc/openapi.json", ApiDoc::openapi())
.config(Config::default().try_it_out_enabled(true).filter(true));
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>
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
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