Skip to content

Commit 441e5a7

Browse files
committed
Fix lint
1 parent 41c4ddd commit 441e5a7

8 files changed

Lines changed: 100 additions & 34 deletions

File tree

crates/vespera/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub mod openapi {
2020
pub use vespera_core::openapi::OpenApi;
2121

2222
// Re-export macros from vespera_macro
23-
pub use vespera_macro::{export_app, route, schema, schema_type, vespera, Schema};
23+
pub use vespera_macro::{Schema, export_app, route, schema, schema_type, vespera};
2424

2525
// Re-export serde_json for merge feature (runtime spec merging)
2626
pub use serde_json;

crates/vespera_macro/src/parser/schema.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,10 @@ fn substitute_type(ty: &Type, generic_params: &[String], concrete_types: &[&Type
714714
if let syn::PathArguments::None = &segment.arguments {
715715
// Direct generic parameter substitution
716716
if let Some(index) = generic_params.iter().position(|p| p == &ident_str)
717-
&& let Some(concrete_ty) = concrete_types.get(index) {
718-
return (*concrete_ty).clone();
719-
}
717+
&& let Some(concrete_ty) = concrete_types.get(index)
718+
{
719+
return (*concrete_ty).clone();
720+
}
720721
}
721722
}
722723

@@ -941,7 +942,11 @@ pub(super) fn parse_type_to_schema_ref_with_schemas(
941942
"bool" => SchemaRef::Inline(Box::new(Schema::boolean())),
942943
"String" | "str" => SchemaRef::Inline(Box::new(Schema::string())),
943944
// Date-time types from chrono crate
944-
"DateTime" | "NaiveDateTime" | "DateTimeWithTimeZone" | "DateTimeUtc" | "DateTimeLocal" => SchemaRef::Inline(Box::new(Schema {
945+
"DateTime"
946+
| "NaiveDateTime"
947+
| "DateTimeWithTimeZone"
948+
| "DateTimeUtc"
949+
| "DateTimeLocal" => SchemaRef::Inline(Box::new(Schema {
945950
format: Some("date-time".to_string()),
946951
..Schema::string()
947952
})),
@@ -1685,7 +1690,10 @@ mod tests {
16851690
) {
16861691
let ty: Type = syn::parse_str(input).unwrap();
16871692
let generic_params: Vec<String> = params.iter().map(|s| s.to_string()).collect();
1688-
let concrete_types: Vec<Type> = concrete.iter().map(|s| syn::parse_str(s).unwrap()).collect();
1693+
let concrete_types: Vec<Type> = concrete
1694+
.iter()
1695+
.map(|s| syn::parse_str(s).unwrap())
1696+
.collect();
16891697
let concrete_refs: Vec<&Type> = concrete_types.iter().collect();
16901698

16911699
let result = substitute_type(&ty, &generic_params, &concrete_refs);
@@ -1729,7 +1737,11 @@ mod tests {
17291737
let ty: Type = syn::parse_str("fn(T) -> U").unwrap();
17301738
let concrete_t: Type = syn::parse_str("String").unwrap();
17311739
let concrete_u: Type = syn::parse_str("i32").unwrap();
1732-
let result = substitute_type(&ty, &[String::from("T"), String::from("U")], &[&concrete_t, &concrete_u]);
1740+
let result = substitute_type(
1741+
&ty,
1742+
&[String::from("T"), String::from("U")],
1743+
&[&concrete_t, &concrete_u],
1744+
);
17331745
// Type::BareFn doesn't go through the Path branch, falls to _ => ty.clone()
17341746
assert_eq!(result, ty);
17351747
}
@@ -1740,7 +1752,11 @@ mod tests {
17401752
let ty: Type = syn::parse_str("dyn Fn(T) -> U").unwrap();
17411753
let concrete_t: Type = syn::parse_str("String").unwrap();
17421754
let concrete_u: Type = syn::parse_str("i32").unwrap();
1743-
let result = substitute_type(&ty, &[String::from("T"), String::from("U")], &[&concrete_t, &concrete_u]);
1755+
let result = substitute_type(
1756+
&ty,
1757+
&[String::from("T"), String::from("U")],
1758+
&[&concrete_t, &concrete_u],
1759+
);
17441760
// Type::TraitObject falls to _ => ty.clone()
17451761
assert_eq!(result, ty);
17461762
}

crates/vespera_macro/src/schema_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use quote::quote;
99
use std::collections::HashSet;
1010
use std::path::Path;
1111
use syn::punctuated::Punctuated;
12-
use syn::{bracketed, parenthesized, parse::Parse, parse::ParseStream, Ident, LitStr, Token, Type};
12+
use syn::{Ident, LitStr, Token, Type, bracketed, parenthesized, parse::Parse, parse::ParseStream};
1313

1414
use crate::metadata::StructMetadata;
1515
use crate::parser::{

examples/axum-example/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod routes;
21
mod models;
2+
mod routes;
33

44
use std::sync::Arc;
55

examples/axum-example/src/models/memo.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub struct Model {
1616
pub updated_at: DateTimeWithTimeZone,
1717
}
1818

19-
2019
// Index definitions (SeaORM uses Statement builders externally)
2120
// (unnamed) on [created_at]
2221
impl ActiveModelBehavior for ActiveModel {}

examples/axum-example/src/routes/memos.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
1010
// Import types used by the source model that we want to include in generated structs
1111
use sea_orm::entity::prelude::DateTimeWithTimeZone;
12-
use vespera::{axum::{Json, extract::Path}, schema_type};
12+
use vespera::{
13+
axum::{Json, extract::Path},
14+
schema_type,
15+
};
1316

1417
// ============================================================================
1518
// schema_type! generates request/response types from models in OTHER FILES

examples/axum-example/src/routes/users.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::collections::{BTreeMap, HashMap};
22

33
use serde::{Deserialize, Serialize};
44
use vespera::{
5-
Schema, schema_type,
5+
Schema,
66
axum::{Json, extract::Path},
7+
schema_type,
78
};
89

910
/// Full user model with all fields
@@ -112,7 +113,9 @@ pub async fn create_user(Json(user): Json<CreateUserRequest>) -> Json<UserPublic
112113
/// Create a new user with metadata (demonstrates `add` feature)
113114
/// Request body uses CreateUserWithMeta (picks name/email, adds request_id/created_at)
114115
#[vespera::route(post, path = "/with-meta")]
115-
pub async fn create_user_with_meta(Json(user): Json<CreateUserWithMeta>) -> Json<CreateUserWithMeta> {
116+
pub async fn create_user_with_meta(
117+
Json(user): Json<CreateUserWithMeta>,
118+
) -> Json<CreateUserWithMeta> {
116119
// Input: CreateUserWithMeta (auto-generated with added fields)
117120
// The struct has: name, email (from User) + request_id, created_at (added)
118121
Json(CreateUserWithMeta {

examples/axum-example/tests/integration_test.rs

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use axum_example::{create_app, create_app_with_layer};
22
use axum_test::TestServer;
3-
use serde_json::json;
43
use serde::{Deserialize, Serialize};
4+
use serde_json::json;
55
use vespera::{Schema, schema};
66

77
#[tokio::test]
@@ -476,7 +476,10 @@ fn test_schema_macro_with_omit() {
476476
let properties = user_schema.properties.unwrap();
477477
assert!(properties.contains_key("id"), "Missing 'id' property");
478478
assert!(properties.contains_key("name"), "Missing 'name' property");
479-
assert!(!properties.contains_key("email"), "'email' should be omitted");
479+
assert!(
480+
!properties.contains_key("email"),
481+
"'email' should be omitted"
482+
);
480483

481484
// Verify required fields - email should not be in required
482485
let required = user_schema.required.unwrap();
@@ -494,7 +497,10 @@ fn test_schema_macro_with_multiple_omit() {
494497
let properties = user_schema.properties.unwrap();
495498
assert!(!properties.contains_key("id"), "'id' should be omitted");
496499
assert!(properties.contains_key("name"), "Missing 'name' property");
497-
assert!(!properties.contains_key("email"), "'email' should be omitted");
500+
assert!(
501+
!properties.contains_key("email"),
502+
"'email' should be omitted"
503+
);
498504

499505
// Verify only 'name' is required
500506
let required = user_schema.required.unwrap();
@@ -511,7 +517,10 @@ fn test_schema_macro_with_pick() {
511517
let properties = user_schema.properties.unwrap();
512518
assert!(properties.contains_key("id"), "Missing 'id' property");
513519
assert!(properties.contains_key("name"), "Missing 'name' property");
514-
assert!(!properties.contains_key("email"), "'email' should not be picked");
520+
assert!(
521+
!properties.contains_key("email"),
522+
"'email' should not be picked"
523+
);
515524

516525
// Verify required fields
517526
let required = user_schema.required.unwrap();
@@ -532,8 +541,14 @@ fn test_schema_macro_with_optional_fields() {
532541
let required = user_schema.required.unwrap();
533542
assert!(required.contains(&"id".to_string()));
534543
assert!(required.contains(&"name".to_string()));
535-
assert!(!required.contains(&"email".to_string()), "'email' is Option<T>, should not be required");
536-
assert!(!required.contains(&"bio".to_string()), "'bio' has default, should not be required");
544+
assert!(
545+
!required.contains(&"email".to_string()),
546+
"'email' is Option<T>, should not be required"
547+
);
548+
assert!(
549+
!required.contains(&"bio".to_string()),
550+
"'bio' has default, should not be required"
551+
);
537552
}
538553

539554
#[test]
@@ -544,9 +559,18 @@ fn test_schema_macro_with_rename_all() {
544559
let properties = user_schema.properties.unwrap();
545560

546561
// Properties should have camelCase names
547-
assert!(properties.contains_key("userId"), "Missing 'userId' property (renamed from user_id)");
548-
assert!(properties.contains_key("userName"), "Missing 'userName' property (renamed from user_name)");
549-
assert!(properties.contains_key("emailAddress"), "Missing 'emailAddress' property (renamed from email_address)");
562+
assert!(
563+
properties.contains_key("userId"),
564+
"Missing 'userId' property (renamed from user_id)"
565+
);
566+
assert!(
567+
properties.contains_key("userName"),
568+
"Missing 'userName' property (renamed from user_name)"
569+
);
570+
assert!(
571+
properties.contains_key("emailAddress"),
572+
"Missing 'emailAddress' property (renamed from email_address)"
573+
);
550574

551575
// Should NOT have snake_case names
552576
assert!(!properties.contains_key("user_id"));
@@ -562,7 +586,10 @@ fn test_schema_macro_omit_with_renamed_field() {
562586
let properties = user_schema.properties.unwrap();
563587
assert!(properties.contains_key("userId"));
564588
assert!(properties.contains_key("userName"));
565-
assert!(!properties.contains_key("emailAddress"), "'emailAddress' should be omitted");
589+
assert!(
590+
!properties.contains_key("emailAddress"),
591+
"'emailAddress' should be omitted"
592+
);
566593
}
567594

568595
#[test]
@@ -573,7 +600,10 @@ fn test_schema_macro_omit_with_rust_field_name() {
573600
let properties = user_schema.properties.unwrap();
574601
assert!(properties.contains_key("userId"));
575602
assert!(properties.contains_key("userName"));
576-
assert!(!properties.contains_key("emailAddress"), "'email_address' (rust name) should omit 'emailAddress'");
603+
assert!(
604+
!properties.contains_key("emailAddress"),
605+
"'email_address' (rust name) should omit 'emailAddress'"
606+
);
577607
}
578608

579609
// Tests for schema_type! with rename option
@@ -591,11 +621,20 @@ async fn test_get_user_dto_with_renamed_fields() {
591621
// JSON should use original field names (id, name) due to serde(rename)
592622
// even though Rust struct uses user_id, display_name
593623
assert_eq!(user["id"], 42, "JSON should serialize 'user_id' as 'id'");
594-
assert_eq!(user["name"], "User 42", "JSON should serialize 'display_name' as 'name'");
595-
624+
assert_eq!(
625+
user["name"], "User 42",
626+
"JSON should serialize 'display_name' as 'name'"
627+
);
628+
596629
// Verify renamed field names are NOT in JSON
597-
assert!(user.get("user_id").is_none(), "'user_id' should not appear in JSON");
598-
assert!(user.get("display_name").is_none(), "'display_name' should not appear in JSON");
630+
assert!(
631+
user.get("user_id").is_none(),
632+
"'user_id' should not appear in JSON"
633+
);
634+
assert!(
635+
user.get("display_name").is_none(),
636+
"'display_name' should not appear in JSON"
637+
);
599638
}
600639

601640
// Tests for schema_type! with add option
@@ -621,7 +660,7 @@ async fn test_create_user_with_meta_add_fields() {
621660
// Verify fields from User (picked)
622661
assert_eq!(result["name"], "Test User");
623662
assert_eq!(result["email"], "test@example.com");
624-
663+
625664
// Verify added fields
626665
assert_eq!(result["request_id"], "req-12345");
627666
assert_eq!(result["created_at"], "2024-01-27T12:00:00Z"); // Server fills this in
@@ -647,10 +686,16 @@ async fn test_memo_create_with_picked_fields() {
647686

648687
assert_eq!(result["title"], "Test Memo");
649688
assert_eq!(result["content"], "This is test content");
650-
689+
651690
// These fields should NOT be in the response (not picked)
652-
assert!(result.get("id").is_none(), "id should not be in CreateMemoRequest");
653-
assert!(result.get("created_at").is_none(), "created_at should not be in CreateMemoRequest");
691+
assert!(
692+
result.get("id").is_none(),
693+
"id should not be in CreateMemoRequest"
694+
);
695+
assert!(
696+
result.get("created_at").is_none(),
697+
"created_at should not be in CreateMemoRequest"
698+
);
654699
}
655700

656701
#[tokio::test]
@@ -673,7 +718,7 @@ async fn test_memo_update_with_added_id_field() {
673718
// Verify picked fields
674719
assert_eq!(result["title"], "Updated Memo");
675720
assert_eq!(result["content"], "Updated content");
676-
721+
677722
// Verify added field
678723
assert_eq!(result["id"], 42, "id should be present (added field)");
679724
}

0 commit comments

Comments
 (0)