Skip to content

Commit 4c4e5fa

Browse files
authored
feat(lambda-events): add Default implementations for all event (#1037)
* feat: implement Default trait for all lambda events
1 parent 8e6fac2 commit 4c4e5fa

File tree

21 files changed

+109
-98
lines changed

21 files changed

+109
-98
lines changed

lambda-events/src/encodings/http.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,39 +264,39 @@ mod tests {
264264
fn from_str() {
265265
match Body::from(String::from("foo").as_str()) {
266266
Body::Text(_) => (),
267-
not => panic!("expected Body::Text(...) got {:?}", not),
267+
not => panic!("expected Body::Text(...) got {not:?}"),
268268
}
269269
}
270270

271271
#[test]
272272
fn from_string() {
273273
match Body::from(String::from("foo")) {
274274
Body::Text(_) => (),
275-
not => panic!("expected Body::Text(...) got {:?}", not),
275+
not => panic!("expected Body::Text(...) got {not:?}"),
276276
}
277277
}
278278

279279
#[test]
280280
fn from_cow_str() {
281281
match Body::from(Cow::from("foo")) {
282282
Body::Text(_) => (),
283-
not => panic!("expected Body::Text(...) got {:?}", not),
283+
not => panic!("expected Body::Text(...) got {not:?}"),
284284
}
285285
}
286286

287287
#[test]
288288
fn from_cow_bytes() {
289289
match Body::from(Cow::from("foo".as_bytes())) {
290290
Body::Binary(_) => (),
291-
not => panic!("expected Body::Binary(...) got {:?}", not),
291+
not => panic!("expected Body::Binary(...) got {not:?}"),
292292
}
293293
}
294294

295295
#[test]
296296
fn from_bytes() {
297297
match Body::from("foo".as_bytes()) {
298298
Body::Binary(_) => (),
299-
not => panic!("expected Body::Binary(...) got {:?}", not),
299+
not => panic!("expected Body::Binary(...) got {not:?}"),
300300
}
301301
}
302302

@@ -325,12 +325,12 @@ mod tests {
325325
fn serialize_from_maybe_encoded() {
326326
match Body::from_maybe_encoded(false, "foo") {
327327
Body::Text(_) => (),
328-
not => panic!("expected Body::Text(...) got {:?}", not),
328+
not => panic!("expected Body::Text(...) got {not:?}"),
329329
}
330330

331331
match Body::from_maybe_encoded(true, "Zm9v") {
332332
Body::Binary(b) => assert_eq!(&[102, 111, 111], b.as_slice()),
333-
not => panic!("expected Body::Text(...) got {:?}", not),
333+
not => panic!("expected Body::Text(...) got {not:?}"),
334334
}
335335
}
336336
}

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::HashMap;
55
use crate::custom_serde::deserialize_lambda_map;
66

77
/// Deprecated: `AppSyncResolverTemplate` does not represent resolver events sent by AppSync. Instead directly model your input schema, or use `map[string]string`, `json.RawMessage`,` interface{}`, etc..
8-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
8+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
99
#[serde(rename_all = "camelCase")]
1010
pub struct AppSyncResolverTemplate<T1 = Value>
1111
where
@@ -27,7 +27,7 @@ where
2727
}
2828

2929
/// `AppSyncIamIdentity` contains information about the caller authed via IAM.
30-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
30+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
3131
#[serde(rename_all = "camelCase")]
3232
pub struct AppSyncIamIdentity {
3333
#[serde(default)]
@@ -55,7 +55,7 @@ pub struct AppSyncIamIdentity {
5555
}
5656

5757
/// `AppSyncCognitoIdentity` contains information about the caller authed via Cognito.
58-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
58+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
5959
#[serde(rename_all = "camelCase")]
6060
pub struct AppSyncCognitoIdentity<T1 = Value>
6161
where
@@ -87,7 +87,7 @@ where
8787
pub type AppSyncOperation = String;
8888

8989
/// `AppSyncLambdaAuthorizerRequest` contains an authorization request from AppSync.
90-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
90+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
9191
#[serde(rename_all = "camelCase")]
9292
pub struct AppSyncLambdaAuthorizerRequest {
9393
#[serde(default)]
@@ -104,7 +104,7 @@ pub struct AppSyncLambdaAuthorizerRequest {
104104

105105
/// `AppSyncLambdaAuthorizerRequestContext` contains the parameters of the AppSync invocation which triggered
106106
/// this authorization request.
107-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
107+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
108108
#[serde(rename_all = "camelCase")]
109109
pub struct AppSyncLambdaAuthorizerRequestContext<T1 = Value>
110110
where
@@ -136,7 +136,7 @@ where
136136
}
137137

138138
/// `AppSyncLambdaAuthorizerResponse` represents the expected format of an authorization response to AppSync.
139-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
139+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
140140
#[serde(rename_all = "camelCase")]
141141
pub struct AppSyncLambdaAuthorizerResponse<T1 = Value>
142142
where
@@ -171,7 +171,7 @@ where
171171
///
172172
/// See also:
173173
/// - [AppSync resolver mapping template context reference](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html)
174-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
174+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
175175
pub struct AppSyncDirectResolverEvent<TArguments = Value, TSource = Value, TStash = Value>
176176
where
177177
TArguments: Serialize + DeserializeOwned,
@@ -200,7 +200,7 @@ where
200200

201201
/// `AppSyncRequest` contains request-related metadata for a resolver invocation,
202202
/// including client-sent headers and optional custom domain name.
203-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
203+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
204204
#[serde(rename_all = "camelCase")]
205205
pub struct AppSyncRequest {
206206
#[serde(deserialize_with = "deserialize_lambda_map")]
@@ -219,7 +219,7 @@ pub struct AppSyncRequest {
219219
}
220220

221221
/// `AppSyncInfo` contains metadata about the current GraphQL field being resolved.
222-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
222+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
223223
#[serde(rename_all = "camelCase")]
224224
pub struct AppSyncInfo<T = Value>
225225
where
@@ -243,7 +243,7 @@ where
243243
}
244244

245245
/// `AppSyncPrevResult` contains the result of the previous step in a pipeline resolver.
246-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
246+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
247247
pub struct AppSyncPrevResult<T = Value>
248248
where
249249
T: Serialize + DeserializeOwned,
@@ -270,8 +270,14 @@ pub enum AppSyncIdentity {
270270
Lambda(AppSyncIdentityLambda),
271271
}
272272

273+
impl Default for AppSyncIdentity {
274+
fn default() -> Self {
275+
AppSyncIdentity::IAM(AppSyncIamIdentity::default())
276+
}
277+
}
278+
273279
/// `AppSyncIdentityOIDC` represents identity information when using OIDC-based authorization.
274-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
280+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
275281
pub struct AppSyncIdentityOIDC<T = Value>
276282
where
277283
T: Serialize + DeserializeOwned,
@@ -290,7 +296,7 @@ where
290296
}
291297

292298
/// `AppSyncIdentityLambda` represents identity information when using AWS Lambda
293-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
299+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
294300
#[serde(rename_all = "camelCase")]
295301
pub struct AppSyncIdentityLambda<T = Value>
296302
where

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22
#[cfg(feature = "catch-all-fields")]
33
use serde_json::Value;
44

5-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
5+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
66
#[serde(rename_all = "camelCase")]
77
pub struct ClientVpnConnectionHandlerRequest {
88
#[serde(default)]
@@ -40,7 +40,7 @@ pub struct ClientVpnConnectionHandlerRequest {
4040
pub other: serde_json::Map<String, Value>,
4141
}
4242

43-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
43+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
4444
#[serde(rename_all = "camelCase")]
4545
pub struct ClientVpnConnectionHandlerResponse {
4646
pub allow: bool,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
pub other: serde_json::Map<String, Value>,
5151
}
5252

53-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
53+
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
5454
#[serde(rename_all = "PascalCase")]
5555
pub struct UpdateRequest<P1 = Value, P2 = Value>
5656
where
@@ -79,7 +79,7 @@ where
7979
pub other: serde_json::Map<String, Value>,
8080
}
8181

82-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
82+
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
8383
#[serde(rename_all = "PascalCase")]
8484
pub struct DeleteRequest<P2 = Value>
8585
where

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
// No `other` catch-all here; any additional fields will be caught in `common.other` instead
4040
}
4141

42-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
42+
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
4343
#[serde(rename_all = "PascalCase")]
4444
pub struct UpdateRequest<P1 = Value, P2 = Value>
4545
where
@@ -56,7 +56,7 @@ where
5656
// No `other` catch-all here; any additional fields will be caught in `common.other` instead
5757
}
5858

59-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
59+
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
6060
#[serde(rename_all = "PascalCase")]
6161
pub struct DeleteRequest<P2 = Value>
6262
where

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct CodeCommitEvent {
2323
pub type CodeCommitEventTime = DateTime<Utc>;
2424

2525
/// `CodeCommitRecord` represents a CodeCommit record
26-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
26+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
2727
#[serde(rename_all = "camelCase")]
2828
pub struct CodeCommitRecord {
2929
#[serde(default)]
@@ -63,7 +63,7 @@ pub struct CodeCommitRecord {
6363
}
6464

6565
/// `CodeCommitCodeCommit` represents a CodeCommit object in a record
66-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
66+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
6767
#[serde(rename_all = "camelCase")]
6868
pub struct CodeCommitCodeCommit {
6969
pub references: Vec<CodeCommitReference>,
@@ -80,7 +80,7 @@ pub struct CodeCommitCodeCommit {
8080
}
8181

8282
/// `CodeCommitReference` represents a Reference object in a CodeCommit object
83-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
83+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
8484
#[serde(rename_all = "camelCase")]
8585
pub struct CodeCommitReference {
8686
#[serde(default)]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub struct CodeBuildEnvironment {
178178
}
179179

180180
/// `CodeBuildEnvironmentVariable` encapsulate environment variables for the code build
181-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
181+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
182182
#[serde(rename_all = "camelCase")]
183183
pub struct CodeBuildEnvironmentVariable {
184184
/// Name is the name of the environment variable.
@@ -239,7 +239,7 @@ pub struct CodeBuildLogs {
239239
}
240240

241241
/// `CodeBuildPhase` represents the phase of a build and its details
242-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
242+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
243243
#[serde(rename_all = "camelCase")]
244244
pub struct CodeBuildPhase<T1 = Value>
245245
where

lambda-events/src/event/dynamodb/attributes.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod test {
1515
let attr: AttributeValue = serde_json::from_value(value.clone()).unwrap();
1616
match attr {
1717
AttributeValue::Null(true) => {}
18-
other => panic!("unexpected value {:?}", other),
18+
other => panic!("unexpected value {other:?}"),
1919
}
2020

2121
let reparsed = serde_json::to_value(attr).unwrap();
@@ -31,7 +31,7 @@ mod test {
3131
let attr: AttributeValue = serde_json::from_value(value.clone()).unwrap();
3232
match attr {
3333
AttributeValue::S(ref s) => assert_eq!("value", s.as_str()),
34-
other => panic!("unexpected value {:?}", other),
34+
other => panic!("unexpected value {other:?}"),
3535
}
3636

3737
let reparsed = serde_json::to_value(attr).unwrap();
@@ -47,7 +47,7 @@ mod test {
4747
let attr: AttributeValue = serde_json::from_value(value.clone()).unwrap();
4848
match attr {
4949
AttributeValue::N(ref n) => assert_eq!("123.45", n.as_str()),
50-
other => panic!("unexpected value {:?}", other),
50+
other => panic!("unexpected value {other:?}"),
5151
}
5252

5353
let reparsed = serde_json::to_value(attr).unwrap();
@@ -68,7 +68,7 @@ mod test {
6868
.unwrap();
6969
assert_eq!(&expected, b)
7070
}
71-
other => panic!("unexpected value {:?}", other),
71+
other => panic!("unexpected value {other:?}"),
7272
}
7373

7474
let reparsed = serde_json::to_value(attr).unwrap();
@@ -84,7 +84,7 @@ mod test {
8484
let attr: AttributeValue = serde_json::from_value(value.clone()).unwrap();
8585
match attr {
8686
AttributeValue::Bool(b) => assert!(b),
87-
other => panic!("unexpected value {:?}", other),
87+
other => panic!("unexpected value {other:?}"),
8888
}
8989

9090
let reparsed = serde_json::to_value(attr).unwrap();
@@ -103,7 +103,7 @@ mod test {
103103
let expected = vec!["Giraffe", "Hippo", "Zebra"];
104104
assert_eq!(expected, s.iter().collect::<Vec<_>>());
105105
}
106-
other => panic!("unexpected value {:?}", other),
106+
other => panic!("unexpected value {other:?}"),
107107
}
108108

109109
let reparsed = serde_json::to_value(attr).unwrap();
@@ -122,7 +122,7 @@ mod test {
122122
let expected = vec!["42.2", "-19", "7.5", "3.14"];
123123
assert_eq!(expected, s.iter().collect::<Vec<_>>());
124124
}
125-
other => panic!("unexpected value {:?}", other),
125+
other => panic!("unexpected value {other:?}"),
126126
}
127127

128128
let reparsed = serde_json::to_value(attr).unwrap();
@@ -144,7 +144,7 @@ mod test {
144144
.collect::<Vec<_>>();
145145
assert_eq!(&expected, s);
146146
}
147-
other => panic!("unexpected value {:?}", other),
147+
other => panic!("unexpected value {other:?}"),
148148
}
149149

150150
let reparsed = serde_json::to_value(attr).unwrap();
@@ -167,7 +167,7 @@ mod test {
167167
];
168168
assert_eq!(&expected, s);
169169
}
170-
other => panic!("unexpected value {:?}", other),
170+
other => panic!("unexpected value {other:?}"),
171171
}
172172

173173
let reparsed = serde_json::to_value(attr).unwrap();
@@ -188,7 +188,7 @@ mod test {
188188
expected.insert("Age".into(), AttributeValue::N("35".into()));
189189
assert_eq!(expected, s);
190190
}
191-
other => panic!("unexpected value {:?}", other),
191+
other => panic!("unexpected value {other:?}"),
192192
}
193193
}
194194
}

0 commit comments

Comments
 (0)