#[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§

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/{_:.*}");

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

Add multiple Urls 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())
    ]
);

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

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Converts self into a collection.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more