Skip to content

Commit abd5f0e

Browse files
committed
Refactor tests and formatting; update changelog
Applied minor refactoring and formatting improvements to test code in extract.rs, layer.rs, metrics.rs, and mod.rs. Updated CHANGELOG.md for new TOON format support and related features. Improved code readability in toon-api example.
1 parent 6b8bdea commit abd5f0e

6 files changed

Lines changed: 34 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.3] - 2026-01-01
11+
12+
### Added
13+
- **New `rustapi-toon` crate**: TOON (Token-Oriented Object Notation) format support
14+
- LLM-optimized data serialization format
15+
- Content negotiation via `Accept` header (`application/toon`, `application/json`)
16+
- `Toon<T>` extractor and responder
17+
- `ToonNegotiate<T>` for automatic format selection
18+
- `LlmResponse<T>` for AI-friendly structured responses
19+
- OpenAPI integration with TOON schema support
20+
- `toon` feature flag in `rustapi-rs` for opt-in TOON support
21+
- `toon-api` example demonstrating TOON format usage
22+
- Improved cookie extraction test for duplicate cookie names
23+
24+
### Changed
25+
- Updated `rustapi-rs` to re-export toon module when feature enabled
26+
1027
## [0.1.2] - 2024-12-31
1128

1229
### Added

crates/rustapi-core/src/extract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ mod tests {
10281028
vec![]
10291029
};
10301030

1031-
let request = create_test_request_with_headers(Method::GET, "/test", headers);
1031+
let _request = create_test_request_with_headers(Method::GET, "/test", headers);
10321032

10331033
// We need to use a static string for the header name in the extractor
10341034
// So we'll test with a known header name
@@ -1357,7 +1357,7 @@ mod tests {
13571357

13581358
// Verify all expected cookies are present with correct values
13591359
for (name, expected_value) in &expected_cookies {
1360-
let cookie = extracted.get(*name)
1360+
let cookie = extracted.get(name)
13611361
.ok_or_else(|| TestCaseError::fail(format!("Cookie '{}' not found", name)))?;
13621362

13631363
prop_assert_eq!(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,12 @@ mod tests {
244244

245245
/// A middleware that modifies the response status
246246
#[derive(Clone)]
247+
#[allow(dead_code)]
247248
struct StatusModifyingMiddleware {
248249
status: StatusCode,
249250
}
250251

252+
#[allow(dead_code)]
251253
impl StatusModifyingMiddleware {
252254
fn new(status: StatusCode) -> Self {
253255
Self { status }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ mod tests {
296296
#[test]
297297
fn test_metrics_layer_creation() {
298298
let metrics = MetricsLayer::new();
299-
assert!(metrics.registry().gather().len() > 0);
299+
assert!(!metrics.registry().gather().is_empty());
300300
}
301301

302302
#[test]

crates/rustapi-extras/src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ mod tests {
619619

620620
// Define a config struct that matches our env vars
621621
#[derive(Debug, Deserialize, PartialEq)]
622+
#[allow(dead_code)]
622623
struct PropTestConfig {
623624
prop_test_str: String,
624625
prop_test_num: u32,

examples/toon-api/src/main.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,12 @@ async fn get_users_llm_toon() -> LlmResponse<UsersResponse> {
241241
/// Compare JSON vs TOON for the same data
242242
async fn compare_formats() -> Json<ComparisonResult> {
243243
let users = get_sample_users();
244-
let response = UsersResponse {
245-
users,
246-
total: 3,
247-
};
244+
let response = UsersResponse { users, total: 3 };
248245

249246
// Serialize to both formats
250247
let json_str = serde_json::to_string_pretty(&response).unwrap();
251-
let toon_str = rustapi_rs::toon::encode_default(&response).unwrap_or_else(|_| "Error".to_string());
248+
let toon_str =
249+
rustapi_rs::toon::encode_default(&response).unwrap_or_else(|_| "Error".to_string());
252250

253251
let json_bytes = json_str.len();
254252
let toon_bytes = toon_str.len();
@@ -266,7 +264,8 @@ async fn compare_formats() -> Json<ComparisonResult> {
266264
/// API info
267265
async fn index() -> Json<Message> {
268266
Json(Message {
269-
content: "TOON Format API Example - Use /compare to see JSON vs TOON comparison".to_string(),
267+
content: "TOON Format API Example - Use /compare to see JSON vs TOON comparison"
268+
.to_string(),
270269
format: "json".to_string(),
271270
})
272271
}
@@ -293,7 +292,9 @@ async fn toon_docs() -> Html<String> {
293292
<p><a href="/docs">Back to API Documentation</a></p>
294293
</body>
295294
</html>"#,
296-
TOON_FORMAT_DESCRIPTION.replace('<', "&lt;").replace('>', "&gt;")
295+
TOON_FORMAT_DESCRIPTION
296+
.replace('<', "&lt;")
297+
.replace('>', "&gt;")
297298
);
298299
Html(html)
299300
}
@@ -303,9 +304,7 @@ async fn toon_docs() -> Html<String> {
303304
#[tokio::main]
304305
async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
305306
// Initialize tracing
306-
tracing_subscriber::fmt()
307-
.with_env_filter("info")
308-
.init();
307+
tracing_subscriber::fmt().with_env_filter("info").init();
309308

310309
info!("Starting TOON API example...");
311310
info!("Server running at http://127.0.0.1:8080");
@@ -331,8 +330,8 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sy
331330
info!(" curl -H 'Accept: application/toon' http://localhost:8080/users # TOON");
332331

333332
// Build API description with TOON support notice
334-
let description = api_description_with_toon(
335-
"TOON Format API Example demonstrating LLM-optimized data serialization."
333+
let _description = api_description_with_toon(
334+
"TOON Format API Example demonstrating LLM-optimized data serialization.",
336335
);
337336

338337
RustApi::new()

0 commit comments

Comments
 (0)