Skip to content

Commit

Permalink
[server] Update utoipa-rapidoc to 5.0.1 #1468 (#1470)
Browse files Browse the repository at this point in the history
* Update api.rs

* Update app.rs
  • Loading branch information
michaelvlach authored Jan 8, 2025
1 parent 10a7544 commit 6d7000a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
16 changes: 0 additions & 16 deletions agdb_server/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use crate::routes;
use axum::response::IntoResponse;
use reqwest::header::CONTENT_TYPE;
use reqwest::StatusCode;
use utoipa::openapi::security::Http;
use utoipa::openapi::security::HttpAuthScheme;
use utoipa::openapi::security::SecurityScheme;
use utoipa::Modify;
use utoipa::OpenApi;
use utoipa_rapidoc::RapiDoc;

#[derive(OpenApi)]
#[openapi(
Expand Down Expand Up @@ -142,18 +138,6 @@ impl Modify for BearerToken {
}
}

pub(crate) async fn openapi_json() -> String {
Api::openapi().to_json().unwrap_or_default()
}

pub(crate) async fn rapidoc() -> impl IntoResponse {
(
StatusCode::OK,
[(CONTENT_TYPE, "text/html")],
RapiDoc::with_url("/api/v1", "/api/v1/openapi.json", Api::openapi()).to_html(),
)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
9 changes: 5 additions & 4 deletions agdb_server/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::api;
use crate::api::Api;
use crate::cluster::Cluster;
use crate::config::Config;
use crate::db_pool::DbPool;
Expand All @@ -13,6 +13,8 @@ use axum::Router;
use reqwest::Method;
use tokio::sync::broadcast::Sender;
use tower_http::cors::CorsLayer;
use utoipa::OpenApi;
use utoipa_rapidoc::RapiDoc;

pub(crate) fn app(
cluster: Cluster,
Expand Down Expand Up @@ -178,8 +180,7 @@ pub(crate) fn app(
"/user/change_password",
routing::put(routes::user::change_password),
)
.route("/user/status", routing::get(routes::user::status))
.route("/openapi.json", routing::get(api::openapi_json));
.route("/user/status", routing::get(routes::user::status));

let cors = CorsLayer::new()
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE])
Expand All @@ -188,7 +189,7 @@ pub(crate) fn app(

let router = Router::new()
.nest("/api/v1", api_v1)
.route("/api/v1", routing::get(api::rapidoc))
.merge(RapiDoc::with_openapi("/api/v1/openapi.json", Api::openapi()).path("/api/v1"))
.layer(middleware::from_fn_with_state(
state.clone(),
forward::forward_to_leader,
Expand Down

0 comments on commit 6d7000a

Please sign in to comment.