Skip to content

Commit a881edb

Browse files
committed
feat: implement Default trait for all lambda events
1 parent 8e6fac2 commit a881edb

File tree

17 files changed

+83
-72
lines changed

17 files changed

+83
-72
lines changed

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/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ use std::fmt;
1212
#[cfg(test)]
1313
mod attributes;
1414

15-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
15+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
1616
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
1717
pub enum StreamViewType {
1818
NewImage,
1919
OldImage,
2020
NewAndOldImages,
21+
#[default]
2122
KeysOnly,
2223
}
2324

@@ -33,12 +34,13 @@ impl fmt::Display for StreamViewType {
3334
}
3435
}
3536

36-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
37+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
3738
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
3839
pub enum StreamStatus {
3940
Enabling,
4041
Enabled,
4142
Disabling,
43+
#[default]
4244
Disabled,
4345
}
4446

@@ -54,10 +56,11 @@ impl fmt::Display for StreamStatus {
5456
}
5557
}
5658

57-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
59+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
5860
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
5961
pub enum SharedIteratorType {
6062
TrimHorizon,
63+
#[default]
6164
Latest,
6265
AtSequenceNumber,
6366
AfterSequenceNumber,
@@ -75,9 +78,10 @@ impl fmt::Display for SharedIteratorType {
7578
}
7679
}
7780

78-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
81+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
7982
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
8083
pub enum OperationType {
84+
#[default]
8185
Insert,
8286
Modify,
8387
Remove,
@@ -94,9 +98,10 @@ impl fmt::Display for OperationType {
9498
}
9599
}
96100

97-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
101+
#[derive(Clone, Default, Debug, Deserialize, Eq, PartialEq, Serialize)]
98102
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
99103
pub enum KeyType {
104+
#[default]
100105
Hash,
101106
Range,
102107
}
@@ -128,7 +133,7 @@ pub struct Event {
128133

129134
/// `TimeWindowEvent` represents an Amazon Dynamodb event when using time windows
130135
/// ref. <https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-windows>
131-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
136+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
132137
#[serde(rename_all = "camelCase")]
133138
pub struct TimeWindowEvent {
134139
#[serde(rename = "DynamoDBEvent")]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct KinesisFirehoseEventRecord {
4949
pub other: serde_json::Map<String, Value>,
5050
}
5151

52-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
52+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
5353
#[serde(rename_all = "camelCase")]
5454
pub struct KinesisFirehoseResponse {
5555
pub records: Vec<KinesisFirehoseResponseRecord>,
@@ -62,7 +62,7 @@ pub struct KinesisFirehoseResponse {
6262
pub other: serde_json::Map<String, Value>,
6363
}
6464

65-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
65+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
6666
#[serde(rename_all = "camelCase")]
6767
pub struct KinesisFirehoseResponseRecord {
6868
#[serde(default)]
@@ -81,7 +81,7 @@ pub struct KinesisFirehoseResponseRecord {
8181
pub other: serde_json::Map<String, Value>,
8282
}
8383

84-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
84+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
8585
#[serde(rename_all = "camelCase")]
8686
pub struct KinesisFirehoseResponseRecordMetadata {
8787
#[serde(deserialize_with = "deserialize_lambda_map")]
@@ -96,7 +96,7 @@ pub struct KinesisFirehoseResponseRecordMetadata {
9696
pub other: serde_json::Map<String, Value>,
9797
}
9898

99-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
99+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
100100
#[serde(rename_all = "camelCase")]
101101
pub struct KinesisFirehoseRecordMetadata {
102102
#[serde(default)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{
88
};
99

1010
/// `IamPolicyDocument` represents an IAM policy document.
11-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
11+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
1212
#[serde(rename_all = "PascalCase")]
1313
pub struct IamPolicyDocument {
1414
#[serde(default)]

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde_json::Value;
66

77
/// `IoTCoreCustomAuthorizerRequest` represents the request to an IoT Core custom authorizer.
88
/// See <https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html>
9-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
9+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
1010
#[serde(rename_all = "camelCase")]
1111
pub struct IoTCoreCustomAuthorizerRequest {
1212
#[serde(default)]
@@ -24,7 +24,7 @@ pub struct IoTCoreCustomAuthorizerRequest {
2424
pub other: serde_json::Map<String, Value>,
2525
}
2626

27-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
27+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
2828
#[serde(rename_all = "camelCase")]
2929
pub struct IoTCoreProtocolData {
3030
pub tls: Option<IoTCoreTlsContext>,
@@ -39,7 +39,7 @@ pub struct IoTCoreProtocolData {
3939
pub other: serde_json::Map<String, Value>,
4040
}
4141

42-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
42+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
4343
#[serde(rename_all = "camelCase")]
4444
pub struct IoTCoreTlsContext {
4545
#[serde(default)]
@@ -53,7 +53,7 @@ pub struct IoTCoreTlsContext {
5353
pub other: serde_json::Map<String, Value>,
5454
}
5555

56-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
56+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
5757
#[serde(rename_all = "camelCase")]
5858
pub struct IoTCoreHttpContext {
5959
#[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
@@ -70,7 +70,7 @@ pub struct IoTCoreHttpContext {
7070
pub other: serde_json::Map<String, Value>,
7171
}
7272

73-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
73+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
7474
#[serde(rename_all = "camelCase")]
7575
pub struct IoTCoreMqttContext {
7676
#[serde(default)]
@@ -87,7 +87,7 @@ pub struct IoTCoreMqttContext {
8787
pub other: serde_json::Map<String, Value>,
8888
}
8989

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 IoTCoreConnectionMetadata {
9393
#[serde(default)]
@@ -103,7 +103,7 @@ pub struct IoTCoreConnectionMetadata {
103103

104104
/// `IoTCoreCustomAuthorizerResponse` represents the response from an IoT Core custom authorizer.
105105
/// See <https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html>
106-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
106+
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
107107
#[serde(rename_all = "camelCase")]
108108
pub struct IoTCoreCustomAuthorizerResponse {
109109
pub is_authenticated: bool,

0 commit comments

Comments
 (0)