Skip to content

Commit 9b21cd0

Browse files
authored
Remove #[serde(deny_unknown_fields)] (#753)
Adding new fields to request payloads is typically not considered to be a breaking change, but using #[serde(deny_unknown_fields)] would cause all Lambda functions to start failing immediately in production if a new feature were deployed that added a new request field. Fixes #750.
1 parent d513b13 commit 9b21cd0

File tree

4 files changed

+1
-9
lines changed

4 files changed

+1
-9
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use serde::{Deserialize, Serialize};
99
/// `AlbTargetGroupRequest` contains data originating from the ALB Lambda target group integration
1010
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1111
#[serde(rename_all = "camelCase")]
12-
#[serde(deny_unknown_fields)]
1312
pub struct AlbTargetGroupRequest {
1413
#[serde(with = "http_method")]
1514
pub http_method: Method,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::collections::HashMap;
1313
/// `ApiGatewayProxyRequest` contains data coming from the API Gateway proxy
1414
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1515
#[serde(rename_all = "camelCase")]
16-
#[serde(deny_unknown_fields)]
1716
pub struct ApiGatewayProxyRequest<T1 = Value>
1817
where
1918
T1: DeserializeOwned,
@@ -120,7 +119,6 @@ where
120119
/// `ApiGatewayV2httpRequest` contains data coming from the new HTTP API Gateway
121120
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
122121
#[serde(rename_all = "camelCase")]
123-
#[serde(deny_unknown_fields)]
124122
pub struct ApiGatewayV2httpRequest {
125123
#[serde(default, rename = "type")]
126124
pub kind: Option<String>,
@@ -335,7 +333,6 @@ pub struct ApiGatewayRequestIdentity {
335333
/// `ApiGatewayWebsocketProxyRequest` contains data coming from the API Gateway proxy
336334
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
337335
#[serde(rename_all = "camelCase")]
338-
#[serde(deny_unknown_fields)]
339336
pub struct ApiGatewayWebsocketProxyRequest<T1 = Value, T2 = Value>
340337
where
341338
T1: DeserializeOwned,

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ where
1818

1919
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
2020
#[serde(rename_all = "PascalCase")]
21-
#[serde(deny_unknown_fields)]
2221
pub struct CreateRequest<P2 = Value>
2322
where
2423
P2: DeserializeOwned + Serialize,
@@ -37,7 +36,6 @@ where
3736

3837
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
3938
#[serde(rename_all = "PascalCase")]
40-
#[serde(deny_unknown_fields)]
4139
pub struct UpdateRequest<P1 = Value, P2 = Value>
4240
where
4341
P1: DeserializeOwned + Serialize,
@@ -60,7 +58,6 @@ where
6058

6159
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
6260
#[serde(rename_all = "PascalCase")]
63-
#[serde(deny_unknown_fields)]
6461
pub struct DeleteRequest<P2 = Value>
6562
where
6663
P2: DeserializeOwned + Serialize,
@@ -87,7 +84,6 @@ mod test {
8784

8885
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
8986
#[serde(rename_all = "PascalCase")]
90-
#[serde(deny_unknown_fields)]
9187
struct TestProperties {
9288
key_1: String,
9389
key_2: Vec<String>,

lambda-http/src/deserializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ mod tests {
107107

108108
#[test]
109109
fn test_deserialize_error() {
110-
let err = serde_json::from_str::<LambdaRequest>("{\"command\": \"hi\"}").unwrap_err();
110+
let err = serde_json::from_str::<LambdaRequest>("{\"body\": {}}").unwrap_err();
111111

112112
assert_eq!(ERROR_CONTEXT, err.to_string());
113113
}

0 commit comments

Comments
 (0)