Commit df88b4e4 authored by Ben Boeckel's avatar Ben Boeckel

serde: add a feature for strict parsing

Useful for debugging, but should not be used in production.

Fixes #4.
parent 0575d152
......@@ -20,3 +20,6 @@ serde = "~0.9"
serde_derive = "~0.9"
serde_json = "~0.9"
url = "~1.4"
[features]
strict = []
......@@ -62,6 +62,7 @@ enum_serialize!(ProjectVisibility -> "project visibility",
Public => "public",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A hook for a project.
pub struct ProjectSystemHook {
......@@ -137,6 +138,7 @@ impl From<HumanAccessLevel> for AccessLevel {
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A project membership hook.
pub struct ProjectMemberSystemHook {
......@@ -181,6 +183,7 @@ enum_serialize!(UserEvent -> "user event",
Destroy => "user_destroy",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A user hook.
pub struct UserSystemHook {
......@@ -213,6 +216,7 @@ enum_serialize!(KeyEvent -> "key event",
Destroy => "key_destroy",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// An SSH key hook.
pub struct KeySystemHook {
......@@ -243,6 +247,7 @@ enum_serialize!(GroupEvent -> "group event",
Destroy => "group_destroy",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A group hook.
pub struct GroupSystemHook {
......@@ -277,6 +282,7 @@ enum_serialize!(GroupMemberEvent -> "group member event",
Remove => "user_remove_from_group",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A group membership hook.
pub struct GroupMemberSystemHook {
......@@ -317,6 +323,7 @@ enum_serialize!(PushEvent -> "push event",
TagPush => "tag_push",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A push hook.
pub struct PushSystemHook {
......
This diff is collapsed.
......@@ -62,6 +62,7 @@ impl AsRef<DateTime<UTC>> for HookDate {
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Project information exposed in hooks.
pub struct ProjectHookAttrs {
......@@ -87,6 +88,7 @@ pub struct ProjectHookAttrs {
pub default_branch: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Wiki project information exposed in hooks.
pub struct ProjectWikiHookAttrs {
......@@ -102,6 +104,7 @@ pub struct ProjectWikiHookAttrs {
pub default_branch: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// User information exposed in hooks.
pub struct UserHookAttrs {
......@@ -113,6 +116,7 @@ pub struct UserHookAttrs {
pub avatar_url: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// The identity of a user exposed through a hook.
pub struct HookCommitIdentity {
......@@ -122,6 +126,7 @@ pub struct HookCommitIdentity {
pub email: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Commit information exposed in hooks.
pub struct CommitHookAttrs {
......@@ -139,6 +144,7 @@ pub struct CommitHookAttrs {
pub removed: Option<Vec<String>>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A push hook.
pub struct PushHook {
......@@ -194,6 +200,7 @@ enum_serialize!(IssueAction -> "issue action",
Reopen => "reopen",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Issue information exposed in hooks.
pub struct IssueHookAttrs {
......@@ -239,6 +246,7 @@ pub struct IssueHookAttrs {
pub action: Option<IssueAction>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// An issue hook.
pub struct IssueHook {
......@@ -276,6 +284,7 @@ enum_serialize!(MergeRequestAction -> "merge request action",
Merge => "merge",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Merge parameters for a merge request.
pub struct MergeRequestParams {
......@@ -303,6 +312,7 @@ impl MergeRequestParams {
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Merge request information exposed in hooks.
pub struct MergeRequestHookAttrs {
......@@ -375,6 +385,7 @@ pub struct MergeRequestHookAttrs {
pub action: Option<MergeRequestAction>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A merge request hook.
pub struct MergeRequestHook {
......@@ -403,6 +414,7 @@ enum_serialize!(SnippetType -> "snippet type",
Personal => "PersonalSnippet",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Snippet information exposed in hooks.
pub struct SnippetHookAttrs {
......@@ -440,6 +452,7 @@ enum_serialize!(WikiPageAction -> "wiki page action",
Update => "update",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Wiki information exposed in hooks.
pub struct WikiPageHookAttrs {
......@@ -458,6 +471,7 @@ pub struct WikiPageHookAttrs {
pub action: WikiPageAction,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Diff information exposed in hooks.
pub struct DiffHookAttrs {
......@@ -480,6 +494,7 @@ pub struct DiffHookAttrs {
pub too_large: bool,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
// FIXME: This can apparently be a string sometimes.
// https://gitlab.com/gitlab-org/gitlab-ce/issues/21467
......@@ -495,6 +510,7 @@ pub struct PositionHookAttrs {
pub new_path: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Note (comment) information exposed in hooks.
pub struct NoteHookAttrs {
......@@ -566,6 +582,7 @@ impl NoteHookAttrs {
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A note hook.
pub struct NoteHook {
......@@ -589,6 +606,7 @@ pub struct NoteHook {
pub snippet: Option<SnippetHookAttrs>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Build user information exposed in hooks.
pub struct BuildUserHookAttrs {
......@@ -600,6 +618,7 @@ pub struct BuildUserHookAttrs {
pub email: Option<String>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Build commit information exposed in hooks.
pub struct BuildCommitHookAttrs {
......@@ -620,6 +639,7 @@ pub struct BuildCommitHookAttrs {
pub finished_at: Option<HookDate>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Project information exposed in build hooks.
pub struct BuildProjectHookAttrs {
......@@ -637,6 +657,7 @@ pub struct BuildProjectHookAttrs {
pub visibility_level: u64,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A build hook.
pub struct BuildHook {
......@@ -671,6 +692,7 @@ pub struct BuildHook {
pub repository: BuildProjectHookAttrs,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A wiki page hook.
pub struct WikiPageHook {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment