Skip to content

Commit ec0bcb2

Browse files
committed
Refactor and format core modules, update dependencies
Refactored and reformatted code across rustapi-core modules for improved readability and consistency. Updated internal crate dependencies in Cargo.toml to disable default features for rustapi-core and rustapi-openapi. Switched GitHub Actions workflow to use dtolnay/rust-toolchain@1.75. No functional changes to logic; changes are primarily stylistic and organizational.
1 parent b26ba89 commit ec0bcb2

File tree

32 files changed

+1197
-942
lines changed

32 files changed

+1197
-942
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
- uses: actions/checkout@v4
127127

128128
- name: Install Rust 1.75
129-
uses: dtolnay/rust-action@1.75
129+
uses: dtolnay/rust-toolchain@1.75
130130

131131
- name: Cache cargo registry
132132
uses: actions/cache@v4

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ prometheus = "0.13"
7272
utoipa = { version = "4.2" }
7373

7474
# Internal crates
75-
rustapi-core = { path = "crates/rustapi-core", version = "0.1.2" }
75+
rustapi-core = { path = "crates/rustapi-core", version = "0.1.2", default-features = false }
7676
rustapi-macros = { path = "crates/rustapi-macros", version = "0.1.2" }
7777
rustapi-validate = { path = "crates/rustapi-validate", version = "0.1.2" }
78-
rustapi-openapi = { path = "crates/rustapi-openapi", version = "0.1.2" }
78+
rustapi-openapi = { path = "crates/rustapi-openapi", version = "0.1.2", default-features = false }
7979
rustapi-extras = { path = "crates/rustapi-extras", version = "0.1.2" }

crates/rustapi-core/src/app.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ impl RustApi {
360360
// Add Swagger UI endpoint
361361
let docs_handler = move || {
362362
let url = openapi_url.clone();
363-
async move {
364-
let html = rustapi_openapi::swagger_ui_html(&url);
365-
html
366-
}
363+
async move { rustapi_openapi::swagger_ui_html(&url) }
367364
};
368365

369366
self.route(&openapi_path, get(spec_handler))
@@ -453,32 +450,36 @@ impl RustApi {
453450
let expected_auth_docs = expected_auth;
454451

455452
// Create spec handler with auth check
456-
let spec_handler: crate::handler::BoxedHandler = std::sync::Arc::new(move |req: crate::Request| {
457-
let json = spec_json.clone();
458-
let expected = expected_auth_spec.clone();
459-
Box::pin(async move {
460-
if !check_basic_auth(&req, &expected) {
461-
return unauthorized_response();
462-
}
463-
http::Response::builder()
464-
.status(http::StatusCode::OK)
465-
.header(http::header::CONTENT_TYPE, "application/json")
466-
.body(http_body_util::Full::new(bytes::Bytes::from(json)))
467-
.unwrap()
468-
}) as std::pin::Pin<Box<dyn std::future::Future<Output = crate::Response> + Send>>
469-
});
453+
let spec_handler: crate::handler::BoxedHandler =
454+
std::sync::Arc::new(move |req: crate::Request| {
455+
let json = spec_json.clone();
456+
let expected = expected_auth_spec.clone();
457+
Box::pin(async move {
458+
if !check_basic_auth(&req, &expected) {
459+
return unauthorized_response();
460+
}
461+
http::Response::builder()
462+
.status(http::StatusCode::OK)
463+
.header(http::header::CONTENT_TYPE, "application/json")
464+
.body(http_body_util::Full::new(bytes::Bytes::from(json)))
465+
.unwrap()
466+
})
467+
as std::pin::Pin<Box<dyn std::future::Future<Output = crate::Response> + Send>>
468+
});
470469

471470
// Create docs handler with auth check
472-
let docs_handler: crate::handler::BoxedHandler = std::sync::Arc::new(move |req: crate::Request| {
473-
let url = openapi_url.clone();
474-
let expected = expected_auth_docs.clone();
475-
Box::pin(async move {
476-
if !check_basic_auth(&req, &expected) {
477-
return unauthorized_response();
478-
}
479-
rustapi_openapi::swagger_ui_html(&url)
480-
}) as std::pin::Pin<Box<dyn std::future::Future<Output = crate::Response> + Send>>
481-
});
471+
let docs_handler: crate::handler::BoxedHandler =
472+
std::sync::Arc::new(move |req: crate::Request| {
473+
let url = openapi_url.clone();
474+
let expected = expected_auth_docs.clone();
475+
Box::pin(async move {
476+
if !check_basic_auth(&req, &expected) {
477+
return unauthorized_response();
478+
}
479+
rustapi_openapi::swagger_ui_html(&url)
480+
})
481+
as std::pin::Pin<Box<dyn std::future::Future<Output = crate::Response> + Send>>
482+
});
482483

483484
// Create method routers with boxed handlers
484485
let mut spec_handlers = HashMap::new();
@@ -509,7 +510,7 @@ impl RustApi {
509510
// Prepend body limit layer so it's the first to process requests
510511
self.layers.prepend(Box::new(BodyLimitLayer::new(limit)));
511512
}
512-
513+
513514
let server = Server::new(self.router, self.layers);
514515
server.run(addr).await
515516
}
@@ -546,8 +547,13 @@ fn check_basic_auth(req: &crate::Request, expected: &str) -> bool {
546547
fn unauthorized_response() -> crate::Response {
547548
http::Response::builder()
548549
.status(http::StatusCode::UNAUTHORIZED)
549-
.header(http::header::WWW_AUTHENTICATE, "Basic realm=\"API Documentation\"")
550+
.header(
551+
http::header::WWW_AUTHENTICATE,
552+
"Basic realm=\"API Documentation\"",
553+
)
550554
.header(http::header::CONTENT_TYPE, "text/plain")
551-
.body(http_body_util::Full::new(bytes::Bytes::from("Unauthorized")))
555+
.body(http_body_util::Full::new(bytes::Bytes::from(
556+
"Unauthorized",
557+
)))
552558
.unwrap()
553559
}

0 commit comments

Comments
 (0)