Skip to content

Commit

Permalink
feat: Replace serde_with usages using serde_as macro (#214)
Browse files Browse the repository at this point in the history
Signed-off-by: Natsuki Ikeguchi <[email protected]>
  • Loading branch information
siketyan authored Oct 23, 2023
1 parent 406676e commit afacf28
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/api/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use rsb_derive::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use serde_with::{serde_as, skip_serializing_none};
use url::Url;

use crate::*;
Expand Down Expand Up @@ -124,13 +124,14 @@ pub struct SlackApiAppsConnectionOpenResponse {
pub url: SlackWebSocketsUrl,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackApiAppsManifestCreateRequest {
pub app_id: SlackAppId,

// This API requires a "json-encoded" string in a JSON object.
#[serde(with = "serde_with::json::nested")]
#[serde_as(as = "serde_with::json::JsonString")]
pub manifest: SlackAppManifest,
}

Expand Down Expand Up @@ -160,13 +161,14 @@ pub struct SlackApiAppsManifestExportResponse {
pub manifest: SlackAppManifest,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackApiAppsManifestUpdateRequest {
pub app_id: SlackAppId,

// This API requires a "json-encoded" string in a JSON object.
#[serde(with = "serde_with::json::nested")]
#[serde_as(as = "serde_with::json::JsonString")]
pub manifest: SlackAppManifest,
}

Expand All @@ -177,11 +179,12 @@ pub struct SlackApiAppsManifestUpdateResponse {
pub permissions_updated: bool,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackApiAppsManifestValidateRequest {
// This API requires a "json-encoded" string in a JSON object.
#[serde(with = "serde_with::json::nested")]
#[serde_as(as = "serde_with::json::JsonString")]
pub manifest: SlackAppManifest,

pub app_id: Option<SlackAppId>,
Expand Down
16 changes: 9 additions & 7 deletions src/models/blocks/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::SlackCallbackId;
use crate::*;
use rsb_derive::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use serde_with::{serde_as, skip_serializing_none};
use std::collections::HashMap;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
Expand All @@ -16,21 +16,23 @@ pub enum SlackView {
Modal(SlackModalView),
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackHomeView {
pub blocks: Vec<SlackBlock>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub private_metadata: Option<String>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub callback_id: Option<SlackCallbackId>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub external_id: Option<String>,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackModalView {
Expand All @@ -39,16 +41,16 @@ pub struct SlackModalView {
pub close: Option<SlackBlockPlainTextOnly>,
pub submit: Option<SlackBlockPlainTextOnly>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub private_metadata: Option<String>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub callback_id: Option<SlackCallbackId>,
pub clear_on_close: Option<bool>,
pub notify_on_close: Option<bool>,
pub hash: Option<String>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub external_id: Option<String>,
}

Expand Down
5 changes: 3 additions & 2 deletions src/models/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chrono::{DateTime, TimeZone, Utc};
use rsb_derive::Builder;
use rvstruct::ValueStruct;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use serde_with::{serde_as, skip_serializing_none};
use std::hash::Hash;
use std::*;
use url::Url;
Expand Down Expand Up @@ -166,11 +166,12 @@ impl fmt::Debug for SlackSigningSecret {
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct EmailAddress(pub String);

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackResponseMetadata {
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub next_cursor: Option<SlackCursorId>,
}

Expand Down
5 changes: 3 additions & 2 deletions src/models/events/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rsb_derive::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use serde_with::{serde_as, skip_serializing_none};

use crate::blocks::*;
use crate::models::messages::*;
Expand Down Expand Up @@ -77,14 +77,15 @@ pub struct SlackInteractionActionInfo {
pub action_ts: Option<SlackTs>,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackInteractionDialogueSubmissionEvent {
pub team: SlackBasicTeamInfo,
pub user: SlackBasicUserInfo,
pub channel: Option<SlackBasicChannelInfo>,
#[serde(default)]
#[serde(with = "serde_with::rust::string_empty_as_none")]
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub callback_id: Option<SlackCallbackId>,
pub state: Option<String>,
pub submission: HashMap<String, String>,
Expand Down

0 comments on commit afacf28

Please sign in to comment.