From aaa75eadb846f07b95663d84930993bf9e9d2386 Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Sun, 6 Oct 2024 16:14:56 +0200 Subject: [PATCH] fix(model): consumed is optional This patch also removes makes sure that the optional fields are not serialized if they are none. --- twilight-model/src/application/interaction/mod.rs | 13 +++---------- .../src/application/monetization/entitlement.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/twilight-model/src/application/interaction/mod.rs b/twilight-model/src/application/interaction/mod.rs index 69d0385c003..67ac3dbb6c8 100644 --- a/twilight-model/src/application/interaction/mod.rs +++ b/twilight-model/src/application/interaction/mod.rs @@ -556,7 +556,7 @@ mod tests { }))), entitlements: vec![Entitlement { application_id: Id::new(100), - consumed: false, + consumed: Some(false), deleted: false, ends_at: None, guild_id: None, @@ -738,19 +738,16 @@ mod tests { Token::Seq { len: Some(1) }, Token::Struct { name: "Entitlement", - len: 10, + len: 6, }, Token::Str("application_id"), Token::NewtypeStruct { name: "Id" }, Token::Str("100"), Token::Str("consumed"), + Token::Some, Token::Bool(false), Token::Str("deleted"), Token::Bool(false), - Token::Str("ends_at"), - Token::None, - Token::Str("guild_id"), - Token::None, Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("200"), @@ -759,10 +756,6 @@ mod tests { Token::Str("sku_id"), Token::NewtypeStruct { name: "Id" }, Token::Str("300"), - Token::Str("starts_at"), - Token::None, - Token::Str("user_id"), - Token::None, Token::StructEnd, Token::SeqEnd, Token::Str("guild_id"), diff --git a/twilight-model/src/application/monetization/entitlement.rs b/twilight-model/src/application/monetization/entitlement.rs index 6c2be6b706f..6a23bd519d2 100644 --- a/twilight-model/src/application/monetization/entitlement.rs +++ b/twilight-model/src/application/monetization/entitlement.rs @@ -16,12 +16,15 @@ pub struct Entitlement { /// ID of the parent application. pub application_id: Id, /// Not applicable for App Subscriptions. Subscriptions are not consumed and will be `false` - pub consumed: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub consumed: Option, /// Entitlement was deleted. pub deleted: bool, /// Date at which the entitlement is no longer valid. Not present when using test entitlements. + #[serde(skip_serializing_if = "Option::is_none")] pub ends_at: Option, /// ID of the guild that is granted access to the entitlement's sku. + #[serde(skip_serializing_if = "Option::is_none")] pub guild_id: Option>, /// ID of the entitlement. pub id: Id, @@ -31,8 +34,10 @@ pub struct Entitlement { /// ID of the SKU. pub sku_id: Id, /// Start date at which the entitlement is valid. Not present when using test entitlements. + #[serde(skip_serializing_if = "Option::is_none")] pub starts_at: Option, /// ID of the user that is granted access to the entitlement's sku. + #[serde(skip_serializing_if = "Option::is_none")] pub user_id: Option>, } @@ -56,7 +61,7 @@ mod tests { let value = Entitlement { application_id: Id::new(1), - consumed: false, + consumed: Some(false), deleted: false, ends_at: ends_at.into(), guild_id: Some(Id::new(10)), @@ -78,6 +83,7 @@ mod tests { Token::NewtypeStruct { name: "Id" }, Token::Str("1"), Token::Str("consumed"), + Token::Some, Token::Bool(false), Token::Str("deleted"), Token::Bool(false),