cronback_api_model/
action.rs1#[cfg(feature = "dto")]
2use dto::{FromProto, IntoProto};
3use monostate::MustBe;
4use serde::{Deserialize, Serialize};
5use serde_with::{serde_as, skip_serializing_none};
6
7use super::Webhook;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10#[cfg_attr(feature = "client", non_exhaustive)]
11#[cfg_attr(
13 feature = "dto",
14 derive(IntoProto, FromProto),
15 proto(target = "proto::common::Action", non_exhaustive)
16)]
17#[serde(rename_all = "snake_case")]
18#[serde(untagged)]
19pub enum Action {
20 #[cfg_attr(feature = "dto", proto(skip))]
21 Event(Event),
22 Webhook(Webhook),
23}
24
25#[serde_as]
26#[skip_serializing_none]
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
28#[cfg_attr(feature = "server", serde(deny_unknown_fields))]
29pub struct Event {
30 #[serde(rename = "type")]
31 _kind: MustBe!("event"),
32 event: String,
33}
34
35#[cfg(feature = "validation")]
36use validator::Validate;
37#[cfg(feature = "validation")]
38impl Validate for Action {
40 fn validate(&self) -> Result<(), validator::ValidationErrors> {
41 match self {
42 | Action::Webhook(webhook) => webhook.validate(),
43 | Action::Event(_) => Ok(()),
44 }
45 }
46}