Skip to content

Commit b2e1510

Browse files
committed
refactor: split openapi crate
1 parent a1da846 commit b2e1510

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ members = [
4848
"crates/db_migration",
4949
"crates/db_schema",
5050
"crates/nodeinfo",
51+
"crates/openapi",
5152
"crates/scheduler",
5253
"crates/utils",
5354
]
@@ -59,6 +60,7 @@ hatsu_apub = { path = "./crates/apub" }
5960
hatsu_db_migration = { path = "./crates/db_migration" }
6061
hatsu_db_schema = { path = "./crates/db_schema" }
6162
hatsu_nodeinfo = { path = "./crates/nodeinfo" }
63+
hatsu_openapi = { path = "./crates/openapi" }
6264
hatsu_scheduler = { path = "./crates/scheduler" }
6365
hatsu_utils = { path = "./crates/utils" }
6466
activitypub_federation = { version = "0.5", default-features = false, features = ["axum"] }
@@ -104,6 +106,7 @@ hatsu_apub = { workspace = true }
104106
hatsu_db_migration = { workspace = true }
105107
hatsu_db_schema = { workspace = true }
106108
hatsu_nodeinfo = { workspace = true }
109+
hatsu_openapi = { workspace = true }
107110
hatsu_scheduler = { workspace = true }
108111
hatsu_utils = { workspace = true }
109112
activitypub_federation = { workspace = true }
@@ -124,5 +127,3 @@ tracing-error = { workspace = true }
124127
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
125128
url = { workspace = true }
126129
utoipa = { workspace = true }
127-
# TODO: dev-dependencies
128-
utoipa-swagger-ui = { version = "4", features = ["axum"] }

crates/openapi/Cargo.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "hatsu_openapi"
3+
version.workspace = true
4+
edition.workspace = true
5+
publish.workspace = true
6+
readme.workspace = true
7+
license.workspace = true
8+
authors.workspace = true
9+
description.workspace = true
10+
documentation.workspace = true
11+
homepage.workspace = true
12+
repository.workspace = true
13+
14+
[lib]
15+
name = "hatsu_openapi"
16+
path = "src/lib.rs"
17+
18+
[dependencies]
19+
hatsu_api_admin = { workspace = true }
20+
hatsu_api_mastodon = { workspace = true }
21+
hatsu_utils = { workspace = true }
22+
axum = { workspace = true }
23+
utoipa = { workspace = true }
24+
utoipa-swagger-ui = { version = "4", features = ["axum"] }

src/routes/openapi.rs renamed to crates/openapi/src/apidoc.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
use axum::{
2-
// routing::get,
3-
// Json,
4-
Router,
5-
};
61
use utoipa::{
72
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
83
Modify,
94
OpenApi,
105
};
11-
use utoipa_swagger_ui::SwaggerUi;
126

137
#[derive(OpenApi)]
148
#[openapi(
@@ -51,9 +45,3 @@ impl Modify for SecurityAddon {
5145
}
5246
}
5347
}
54-
55-
pub fn handler() -> Router {
56-
Router::new()
57-
// .route("/openapi.json", get(|| async move { Json(ApiDoc::openapi()) }))
58-
.merge(SwaggerUi::new("/swagger-ui").url("/openapi.json", ApiDoc::openapi()))
59-
}

crates/openapi/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use axum::Router;
2+
use utoipa::OpenApi;
3+
use utoipa_swagger_ui::SwaggerUi;
4+
5+
mod apidoc;
6+
pub use apidoc::{ApiDoc, SecurityAddon};
7+
8+
pub fn routes() -> Router {
9+
Router::new()
10+
// .route("/openapi.json", get(|| async move { Json(ApiDoc::openapi()) }))
11+
.merge(SwaggerUi::new("/swagger-ui").url("/openapi.json", ApiDoc::openapi()))
12+
}

src/routes/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ mod objects;
55
mod users;
66
mod well_known;
77

8-
mod openapi;
9-
108
// ./hatsu --version
119
async fn root() -> impl IntoResponse {
1210
let version = env!("CARGO_PKG_VERSION");
@@ -20,10 +18,10 @@ pub fn handler() -> Router {
2018
.merge(hatsu_api_admin::routes())
2119
.merge(hatsu_api_mastodon::routes())
2220
.merge(hatsu_nodeinfo::routes())
21+
.merge(hatsu_openapi::routes())
2322
.merge(activities::handler())
2423
.merge(objects::handler())
2524
.merge(users::handler())
2625
.merge(well_known::handler())
27-
.merge(openapi::handler())
2826
.route("/", get(root))
2927
}

0 commit comments

Comments
 (0)