Skip to content

Commit a943c4a

Browse files
authored
Merge pull request #107 from Tuntii/quick-wins
chore(quick-wins): reduce dependency surface and align native OpenAPI…
2 parents 4cd6da4 + ca238ac commit a943c4a

File tree

22 files changed

+70
-324
lines changed

22 files changed

+70
-324
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ rust-version = "1.78"
2929

3030
[workspace.dependencies]
3131
# Async runtime
32-
tokio = { version = "1.35", features = ["full"] }
32+
tokio = "1.35"
3333

3434
# HTTP
35-
hyper = { version = "1.1", features = ["full"] }
36-
hyper-util = { version = "0.1", features = ["full"] }
35+
hyper = "1.1"
36+
hyper-util = "0.1"
3737
http = "1.0"
3838
http-body-util = "0.1"
3939

@@ -42,8 +42,6 @@ serde = { version = "1.0", features = ["derive"] }
4242
serde_json = "1.0"
4343

4444
# Middleware
45-
tower = { version = "0.4", features = ["full"] }
46-
tower-http = { version = "0.5", features = ["full"] }
4745
tower-service = "0.3"
4846

4947
# Utilities
@@ -60,7 +58,6 @@ async-trait = "0.1"
6058
syn = { version = "2.0", features = ["full", "parsing", "extra-traits"] }
6159
quote = "1.0"
6260
proc-macro2 = "1.0"
63-
inventory = "0.3"
6461
linkme = "0.3"
6562

6663
# Validation
@@ -72,9 +69,6 @@ uuid = { version = "1.6", features = ["v4"] }
7269
# Metrics
7370
prometheus = "0.13"
7471

75-
# OpenAPI
76-
utoipa = { version = "4.2", features = ["uuid", "chrono"] }
77-
7872
# TOON format
7973
toon-format = { version = "0.4", default-features = false }
8074

crates/rustapi-core/Cargo.toml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@ homepage.workspace = true
1111

1212
[dependencies]
1313
# Async
14-
tokio = { workspace = true }
14+
tokio = { workspace = true, features = ["rt", "net", "time", "fs", "macros"] }
1515
futures-util = { workspace = true }
1616
pin-project-lite = { workspace = true }
1717

1818
# HTTP
19-
hyper = { workspace = true }
20-
hyper-util = { workspace = true }
19+
hyper = { workspace = true, features = ["server", "http1"] }
20+
hyper-util = { workspace = true, features = ["tokio"] }
2121
http = { workspace = true }
2222
http-body-util = { workspace = true }
2323
bytes = { workspace = true }
2424

25-
# Socket options
26-
socket2 = { version = "0.5", features = ["all"] }
27-
2825
# Router
2926
matchit = { workspace = true }
3027

@@ -38,15 +35,12 @@ simd-json = { version = "0.17", optional = true }
3835
smallvec = "1.13"
3936

4037
# Middleware
41-
tower = { workspace = true }
4238
tower-service = { workspace = true }
43-
tower-http = { workspace = true }
4439

4540
# Utilities
4641
thiserror = { workspace = true }
4742
tracing = { workspace = true }
4843
tracing-subscriber = { workspace = true }
49-
inventory = { workspace = true }
5044
linkme = { workspace = true }
5145
uuid = { workspace = true }
5246
base64 = "0.22"
@@ -59,7 +53,7 @@ brotli = { version = "6.0", optional = true }
5953
cookie = { version = "0.18", optional = true }
6054

6155
# Validation
62-
validator = { workspace = true }
56+
validator = { workspace = true, optional = true }
6357
rustapi-validate = { workspace = true }
6458

6559
# Metrics (optional)
@@ -79,7 +73,6 @@ h3-quinn = { version = "0.0.10", optional = true }
7973
rustls = { workspace = true, optional = true }
8074
rustls-pemfile = { workspace = true, optional = true }
8175
rcgen = { workspace = true, optional = true }
82-
chrono = "0.4.43"
8376

8477
# Replay (feature-gated)
8578
async-trait = { workspace = true, optional = true }
@@ -95,6 +88,7 @@ async-trait = { workspace = true }
9588
default = ["swagger-ui", "tracing"]
9689
swagger-ui = ["rustapi-openapi/swagger-ui"]
9790
test-utils = []
91+
legacy-validator = ["dep:validator"]
9892
cookies = ["dep:cookie"]
9993
sqlx = ["dep:sqlx"]
10094
metrics = ["dep:prometheus"]

crates/rustapi-core/src/middleware/layer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::future::Future;
99
use std::pin::Pin;
1010
use std::sync::Arc;
1111
use std::task::{Context, Poll};
12-
use tower::Service;
12+
use tower_service::Service;
1313

1414
/// A boxed middleware function type
1515
#[allow(dead_code)]

crates/rustapi-core/src/status.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::HashMap;
44
use std::future::Future;
55
use std::pin::Pin;
66
use std::sync::{Arc, RwLock};
7-
use std::time::{Duration, Instant};
7+
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
88

99
/// Configuration for the Status Page
1010
#[derive(Clone, Debug)]
@@ -97,8 +97,7 @@ impl StatusMonitor {
9797
}
9898
entry.total_latency_ms += duration.as_millis();
9999

100-
let now = chrono::Utc::now().to_rfc3339();
101-
entry.last_access = Some(now);
100+
entry.last_access = Some(format_unix_timestamp());
102101
}
103102

104103
pub fn get_uptime(&self) -> Duration {
@@ -274,3 +273,10 @@ fn format_duration(d: Duration) -> String {
274273
format!("{}m {}s", minutes, secs)
275274
}
276275
}
276+
277+
fn format_unix_timestamp() -> String {
278+
let now = SystemTime::now()
279+
.duration_since(UNIX_EPOCH)
280+
.unwrap_or_else(|_| Duration::from_secs(0));
281+
format!("unix:{}", now.as_secs())
282+
}

crates/rustapi-core/src/validation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub trait Validatable {
1010
}
1111

1212
// Blanket implementation for types implementing the external validator::Validate trait
13+
#[cfg(feature = "legacy-validator")]
1314
impl<T: validator::Validate> Validatable for T {
1415
fn do_validate(&self) -> Result<(), ApiError> {
1516
match validator::Validate::validate(self) {
@@ -20,6 +21,7 @@ impl<T: validator::Validate> Validatable for T {
2021
}
2122

2223
/// Helper to convert validator::ValidationErrors to rustapi_core::error::ApiError
24+
#[cfg(feature = "legacy-validator")]
2325
pub fn convert_validator_errors(errors: validator::ValidationErrors) -> ApiError {
2426
let field_errors =
2527
errors

crates/rustapi-extras/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rustapi-core = { workspace = true }
1515
rustapi-openapi = { workspace = true }
1616

1717
# Async
18-
tokio = { workspace = true }
18+
tokio = { workspace = true, features = ["rt", "sync", "time"] }
1919
futures-util = { workspace = true }
2020
async-trait = { workspace = true }
2121

crates/rustapi-macros/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Enrich your auto-generated documentation.
3131

3232
### `#[derive(Schema)]`
3333
Generates a JSON Schema for the struct, used by `rustapi-openapi`.
34-
*Wraps `utoipa::ToSchema` via `rustapi-openapi` integration.*
34+
*Uses RustAPI's native OpenAPI schema integration.*
3535

3636
### `#[derive(Validate)]`
3737
Generates validation logic.
38-
*Wraps `validator::Validate` via `rustapi-validate` integration.*
38+
*Implements RustAPI v2 validation traits via `rustapi-validate` integration.*

crates/rustapi-macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn derive_schema(input: TokenStream) -> TokenStream {
4343

4444
/// Auto-register a schema type for zero-config OpenAPI.
4545
///
46-
/// Attach this to a `struct` or `enum` that also derives `Schema` (utoipa::ToSchema).
46+
/// Attach this to a `struct` or `enum` that also derives `Schema`.
4747
/// This ensures the type is registered into RustAPI's OpenAPI components even if it is
4848
/// only referenced indirectly (e.g. as a nested field type).
4949
///

crates/rustapi-openapi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Automated API specifications and Swagger UI integration for RustAPI.
1010
## How It Works
1111

1212
1. **Reflection**: RustAPI macros collect metadata about your routes (path, method, input types, output types) at compile time
13-
2. **Schema Gen**: Uses `utoipa` to generate JSON Schemas for your Rust structs
13+
2. **Schema Gen**: Uses RustAPI's native schema engine to generate OpenAPI-compatible JSON Schemas
1414
3. **Spec Build**: At runtime, assembles the full OpenAPI 3.0 JSON specification
1515
4. **UI Serve**: Embeds the Swagger UI assets and serves them at your specified path
1616

0 commit comments

Comments
 (0)