From bee94d2a2e92a8061916153e4eedc4c7b02a35f7 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Mon, 2 Feb 2026 16:32:56 +0000 Subject: [PATCH] fix(api): flatten RoastWithRoaster JSON response for consistency The list-roasts API was returning nested objects with a "roast" field, which was inconsistent with other list APIs in the codebase. Added serde's #[serde(flatten)] attribute to make the response flat while maintaining the internal struct composition. --- src/domain/roasts.rs | 1 + tests/cli/roasts_cli.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domain/roasts.rs b/src/domain/roasts.rs index b2c3557..73a0d5b 100644 --- a/src/domain/roasts.rs +++ b/src/domain/roasts.rs @@ -20,6 +20,7 @@ pub struct Roast { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RoastWithRoaster { + #[serde(flatten)] pub roast: Roast, pub roaster_name: String, pub roaster_slug: String, diff --git a/tests/cli/roasts_cli.rs b/tests/cli/roasts_cli.rs index 793d129..856f9c1 100644 --- a/tests/cli/roasts_cli.rs +++ b/tests/cli/roasts_cli.rs @@ -141,10 +141,10 @@ fn test_list_roasts_shows_added_roast() { assert!(roasts.is_array()); let roasts_array = roasts.as_array().unwrap(); - // Find our roast in the list (note: list returns RoastWithRoaster which has nested structure) + // Find our roast in the list let found = roasts_array .iter() - .any(|item| item["roast"]["id"].as_i64() == Some(roast_id)); + .any(|item| item["id"].as_i64() == Some(roast_id)); assert!( found, "Should find the added roast in the list. Looking for id={}, found {} roasts",