Skip to content

Commit 0cdd565

Browse files
authored
add catchall feature to resolve #1017 (#1018)
* add catchall feature to resolve #1017 Signed-off-by: Craig Disselkoen <[email protected]> * switch from HashMap to serde_json::Map Signed-off-by: Craig Disselkoen <[email protected]> * add cfg_attr for docsrs Signed-off-by: Craig Disselkoen <[email protected]> * bump lambda_events version to 0.17 Signed-off-by: Craig Disselkoen <[email protected]> * tweak comment wording Signed-off-by: Craig Disselkoen <[email protected]> --------- Signed-off-by: Craig Disselkoen <[email protected]>
1 parent ee2e0d2 commit 0cdd565

File tree

77 files changed

+3074
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3074
-7
lines changed

lambda-events/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws_lambda_events"
3-
version = "0.16.1"
3+
version = "0.17.0"
44
rust-version = "1.81.0"
55
description = "AWS Lambda event definitions"
66
authors = [
@@ -125,5 +125,7 @@ streams = []
125125
documentdb = []
126126
eventbridge = ["chrono", "serde_with"]
127127

128+
catch-all-fields = []
129+
128130
[package.metadata.docs.rs]
129-
all-features = true
131+
all-features = true

lambda-events/src/event/activemq/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use serde::{Deserialize, Serialize};
2+
#[cfg(feature = "catch-all-fields")]
3+
use serde_json::Value;
24
use std::collections::HashMap;
35

46
use crate::custom_serde::deserialize_lambda_map;
@@ -11,6 +13,13 @@ pub struct ActiveMqEvent {
1113
#[serde(default)]
1214
pub event_source_arn: Option<String>,
1315
pub messages: Vec<ActiveMqMessage>,
16+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
17+
/// Enabled with Cargo feature `catch-all-fields`.
18+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
19+
#[cfg(feature = "catch-all-fields")]
20+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
21+
#[serde(flatten)]
22+
pub other: serde_json::Map<String, Value>,
1423
}
1524

1625
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
@@ -41,13 +50,27 @@ pub struct ActiveMqMessage {
4150
#[serde(deserialize_with = "deserialize_lambda_map")]
4251
#[serde(default)]
4352
pub properties: HashMap<String, String>,
53+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
54+
/// Enabled with Cargo feature `catch-all-fields`.
55+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
56+
#[cfg(feature = "catch-all-fields")]
57+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
58+
#[serde(flatten)]
59+
pub other: serde_json::Map<String, Value>,
4460
}
4561

4662
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
4763
#[serde(rename_all = "camelCase")]
4864
pub struct ActiveMqDestination {
4965
#[serde(default)]
5066
pub physical_name: Option<String>,
67+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
68+
/// Enabled with Cargo feature `catch-all-fields`.
69+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
70+
#[cfg(feature = "catch-all-fields")]
71+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
72+
#[serde(flatten)]
73+
pub other: serde_json::Map<String, Value>,
5174
}
5275

5376
#[cfg(test)]

lambda-events/src/event/alb/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::{
77
use http::{HeaderMap, Method};
88
use query_map::QueryMap;
99
use serde::{Deserialize, Serialize};
10+
#[cfg(feature = "catch-all-fields")]
11+
use serde_json::Value;
1012

1113
/// `AlbTargetGroupRequest` contains data originating from the ALB Lambda target group integration
1214
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
@@ -30,13 +32,27 @@ pub struct AlbTargetGroupRequest {
3032
#[serde(default, deserialize_with = "deserialize_nullish_boolean")]
3133
pub is_base64_encoded: bool,
3234
pub body: Option<String>,
35+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
36+
/// Enabled with Cargo feature `catch-all-fields`.
37+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
38+
#[cfg(feature = "catch-all-fields")]
39+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
40+
#[serde(flatten)]
41+
pub other: serde_json::Map<String, Value>,
3342
}
3443

3544
/// `AlbTargetGroupRequestContext` contains the information to identify the load balancer invoking the lambda
3645
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
3746
#[serde(rename_all = "camelCase")]
3847
pub struct AlbTargetGroupRequestContext {
3948
pub elb: ElbContext,
49+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
50+
/// Enabled with Cargo feature `catch-all-fields`.
51+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
52+
#[cfg(feature = "catch-all-fields")]
53+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
54+
#[serde(flatten)]
55+
pub other: serde_json::Map<String, Value>,
4056
}
4157

4258
/// `ElbContext` contains the information to identify the ARN invoking the lambda
@@ -46,6 +62,13 @@ pub struct ElbContext {
4662
/// nolint: stylecheck
4763
#[serde(default)]
4864
pub target_group_arn: Option<String>,
65+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
66+
/// Enabled with Cargo feature `catch-all-fields`.
67+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
68+
#[cfg(feature = "catch-all-fields")]
69+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
70+
#[serde(flatten)]
71+
pub other: serde_json::Map<String, Value>,
4972
}
5073

5174
/// `AlbTargetGroupResponse` configures the response to be returned by the ALB Lambda target group for the request
@@ -65,6 +88,13 @@ pub struct AlbTargetGroupResponse {
6588
pub body: Option<Body>,
6689
#[serde(default, deserialize_with = "deserialize_nullish_boolean")]
6790
pub is_base64_encoded: bool,
91+
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
92+
/// Enabled with Cargo feature `catch-all-fields`.
93+
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
94+
#[cfg(feature = "catch-all-fields")]
95+
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
96+
#[serde(flatten)]
97+
pub other: serde_json::Map<String, Value>,
6898
}
6999

70100
#[cfg(test)]

0 commit comments

Comments
 (0)