Skip to content

Commit

Permalink
update swagger config
Browse files Browse the repository at this point in the history
  • Loading branch information
j-chad committed Sep 30, 2023
1 parent d77d0b9 commit a778edf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 13 additions & 0 deletions backend/src/api/api_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::auth::models as auth_models;
use super::error;
use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme};
use utoipa::{Modify, OpenApi};
use utoipa_swagger_ui::SwaggerUi;

#[derive(OpenApi)]
#[openapi(
Expand Down Expand Up @@ -50,3 +51,15 @@ impl Modify for SecurityAddon {
);
}
}

pub fn get_swagger_ui() -> SwaggerUi {
SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", ApiDocs::openapi())
.config(
utoipa_swagger_ui::Config::from("/api-docs/openapi.json")
.display_request_duration(true)
.filter(true)
.request_snippets_enabled(true)
.persist_authorization(true),
)
}
7 changes: 1 addition & 6 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use tower_http::LatencyUnit;
use tracing::Level;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;

pub struct AppStateInternal {
pub database_pool: database::ConnectionPool,
Expand Down Expand Up @@ -55,10 +53,7 @@ async fn main() {
let state = Arc::new(AppStateInternal::new(config.clone()));

let app = Router::new()
.merge(
SwaggerUi::new("/swagger-ui")
.url("/api-docs/openapi.json", api_docs::ApiDocs::openapi()),
)
.merge(api_docs::get_swagger_ui())
.nest("/v1", api::get_router(state.clone()))
.fallback(fallback)
.layer(
Expand Down

0 comments on commit a778edf

Please sign in to comment.