@@ -27,7 +27,7 @@ const DEFAULT_RUNTIME: &str = "provided.al2023";
2727) ]
2828pub struct Deploy {
2929 #[ command( flatten) ]
30- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
30+ #[ serde( default , flatten , skip_serializing_if = "Option::is_none" ) ]
3131 pub remote_config : Option < RemoteConfig > ,
3232
3333 #[ command( flatten) ]
@@ -222,7 +222,7 @@ impl Serialize for Deploy {
222222 + self . include . is_some ( ) as usize
223223 + self . dry as usize
224224 + self . name . is_some ( ) as usize
225- + self . remote_config . is_some ( ) as usize
225+ + self . remote_config . as_ref ( ) . map_or ( 0 , |r| r . count_fields ( ) )
226226 + self . function_config . count_fields ( ) ;
227227
228228 let mut state = serializer. serialize_struct ( "Deploy" , len) ?;
@@ -270,7 +270,7 @@ impl Serialize for Deploy {
270270 state. serialize_field ( "name" , name) ?;
271271 }
272272 if let Some ( ref remote_config) = self . remote_config {
273- state . serialize_field ( "remote_config" , remote_config ) ?;
273+ remote_config . serialize_fields :: < S > ( & mut state ) ?;
274274 }
275275 self . function_config . serialize_fields :: < S > ( & mut state) ?;
276276
@@ -665,4 +665,66 @@ mod tests {
665665
666666 assert_eq ! ( config. deploy. function_config. log_retention, Some ( 14 ) ) ;
667667 }
668+
669+ #[ test]
670+ fn test_load_region_from_package_metadata ( ) {
671+ let metadata = load_metadata ( fixture_metadata ( "single-binary-package" ) ) . unwrap ( ) ;
672+
673+ let options = ConfigOptions {
674+ names : FunctionNames :: from_package ( "basic-lambda" ) ,
675+ ..Default :: default ( )
676+ } ;
677+
678+ let config = load_config_without_cli_flags ( & metadata, & options) . unwrap ( ) ;
679+
680+ // Region and profile should be loaded from package.metadata.lambda.deploy
681+ let remote_config = config
682+ . deploy
683+ . remote_config
684+ . expect ( "remote_config should be Some" ) ;
685+ assert_eq ! (
686+ remote_config. region,
687+ Some ( "eu-central-1" . to_string( ) ) ,
688+ "region should be loaded from Cargo.toml"
689+ ) ;
690+ assert_eq ! (
691+ remote_config. profile,
692+ Some ( "test-profile" . to_string( ) ) ,
693+ "profile should be loaded from Cargo.toml"
694+ ) ;
695+ }
696+
697+ #[ test]
698+ fn test_deploy_serialization_with_remote_config ( ) {
699+ use cargo_lambda_remote:: RemoteConfig ;
700+
701+ let deploy = Deploy {
702+ remote_config : Some ( RemoteConfig {
703+ region : Some ( "us-west-2" . to_string ( ) ) ,
704+ profile : Some ( "production" . to_string ( ) ) ,
705+ ..Default :: default ( )
706+ } ) ,
707+ ..Default :: default ( )
708+ } ;
709+
710+ // Serialize to JSON
711+ let serialized = serde_json:: to_value ( & deploy) . unwrap ( ) ;
712+
713+ // Should serialize as flat fields at top level
714+ assert_eq ! ( serialized[ "region" ] , "us-west-2" ) ;
715+ assert_eq ! ( serialized[ "profile" ] , "production" ) ;
716+ assert ! (
717+ !serialized
718+ . as_object( )
719+ . unwrap( )
720+ . contains_key( "remote_config" ) ,
721+ "remote_config should be flattened, not nested"
722+ ) ;
723+
724+ // Deserialize back
725+ let deserialized: Deploy = serde_json:: from_value ( serialized) . unwrap ( ) ;
726+ let rc = deserialized. remote_config . unwrap ( ) ;
727+ assert_eq ! ( rc. region, Some ( "us-west-2" . to_string( ) ) ) ;
728+ assert_eq ! ( rc. profile, Some ( "production" . to_string( ) ) ) ;
729+ }
668730}
0 commit comments