Skip to content

Commit 58fc8ae

Browse files
committed
Use utoipa-swagger-ui to serve OpenAPI viewer
1 parent 6710b1d commit 58fc8ae

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

Cargo.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ url = "=2.5.4"
127127
unicode-xid = "=0.2.6"
128128
utoipa = "=5.2.0"
129129
utoipa-axum = "=0.1.2"
130+
utoipa-swagger-ui = { version = "=8.0.3", features = ["axum", "vendored"] }
130131

131132
[dev-dependencies]
132133
bytes = "=1.9.0"

src/router.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use axum::extract::DefaultBodyLimit;
22
use axum::response::IntoResponse;
33
use axum::routing::{delete, get, post, put};
4-
use axum::{Json, Router};
4+
use axum::Router;
55
use http::{Method, StatusCode};
6+
use utoipa_swagger_ui::SwaggerUi;
67

78
use crate::app::AppState;
89
use crate::controllers::user::update_user;
@@ -177,7 +178,7 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
177178
}
178179

179180
router
180-
.route("/api/openapi.json", get(|| async { Json(openapi) }))
181+
.merge(SwaggerUi::new("/api/openapi").url("/api/openapi.json", openapi))
181182
.fallback(|method: Method| async move {
182183
match method {
183184
Method::HEAD => StatusCode::NOT_FOUND.into_response(),

0 commit comments

Comments
 (0)