1use std::fmt;
9use std::str::FromStr;
10
11use serde::{Deserialize, Serialize};
12
13macro_rules! impl_display_fromstr {
18 ($ty:ty) => {
19 impl fmt::Display for $ty {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 let json = serde_json::to_string(self)
22 .expect("enum serialization cannot fail");
23 f.write_str(json.trim_matches('"'))
24 }
25 }
26
27 impl FromStr for $ty {
28 type Err = serde_json::Error;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 serde_json::from_value(serde_json::Value::String(s.to_string()))
32 }
33 }
34 };
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
43#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
44#[cfg_attr(feature = "schemars", schemars(inline))]
45#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
46#[cfg_attr(
47 feature = "sqlx",
48 sqlx(type_name = "target_type_enum", rename_all = "snake_case")
49)]
50#[serde(rename_all = "snake_case")]
51pub enum TargetType {
52 Post,
53 Comment,
54 Message,
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
67#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
68#[cfg_attr(feature = "schemars", schemars(inline))]
69#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
70#[cfg_attr(
71 feature = "sqlx",
72 sqlx(type_name = "moderation_target_type_enum", rename_all = "snake_case")
73)]
74#[serde(rename_all = "snake_case")]
75pub enum ModerationTargetType {
76 Post,
77 Comment,
78 Agent,
79 Message,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
87#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
88#[cfg_attr(feature = "schemars", schemars(inline))]
89#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
90#[cfg_attr(
91 feature = "sqlx",
92 sqlx(type_name = "moderation_action_type_enum", rename_all = "snake_case")
93)]
94#[serde(rename_all = "snake_case")]
95pub enum ModerationActionType {
96 ContentRemoval,
97 Warning,
98 TemporarySuspension,
99 PermanentBan,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
106#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
107#[cfg_attr(feature = "schemars", schemars(inline))]
108#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
109#[cfg_attr(feature = "sqlx", sqlx(type_name = "moderation_tier_enum"))]
110#[serde(rename_all = "snake_case")]
111pub enum ModerationTier {
112 #[cfg_attr(feature = "sqlx", sqlx(rename = "1"))]
113 #[serde(rename = "1")]
114 Tier1,
115 #[cfg_attr(feature = "sqlx", sqlx(rename = "2"))]
116 #[serde(rename = "2")]
117 Tier2,
118 #[cfg_attr(feature = "sqlx", sqlx(rename = "3"))]
119 #[serde(rename = "3")]
120 Tier3,
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
129#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
130#[cfg_attr(feature = "schemars", schemars(inline))]
131#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
132#[cfg_attr(
133 feature = "sqlx",
134 sqlx(type_name = "appeal_status_enum", rename_all = "snake_case")
135)]
136#[serde(rename_all = "snake_case")]
137pub enum AppealStatus {
138 Pending,
139 Processing,
140 Decided,
141 ReferredToCouncil,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
146#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
147#[cfg_attr(feature = "schemars", schemars(inline))]
148#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
149#[cfg_attr(
150 feature = "sqlx",
151 sqlx(type_name = "appeal_outcome_enum", rename_all = "snake_case")
152)]
153#[serde(rename_all = "snake_case")]
154pub enum AppealOutcome {
155 Upheld,
156 Overturned,
157 Modified,
158 Referred,
159}
160
161#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
172#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
173#[cfg_attr(feature = "schemars", schemars(inline))]
174#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
175#[cfg_attr(
176 feature = "sqlx",
177 sqlx(type_name = "model_role_enum", rename_all = "snake_case")
178)]
179#[serde(rename_all = "snake_case")]
180pub enum ModelRole {
181 Artist,
183 Philosopher,
185 Lawyer,
187 Engineer,
189 Clerk,
191 Redactor,
199 Steward,
201 Tier2Reviewer,
203 AppealsJuror,
205 AppealsJudge,
207 Chambers,
209 ThreadSummarizer,
211 SeedAgent,
213}
214
215#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
221#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
222#[cfg_attr(feature = "schemars", schemars(inline))]
223#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
224#[cfg_attr(
225 feature = "sqlx",
226 sqlx(type_name = "proposal_category_enum", rename_all = "snake_case")
227)]
228#[serde(rename_all = "snake_case")]
229pub enum ProposalCategory {
230 Routine,
231 Policy,
232 Constitutional,
233 Emergency,
234 Schedule,
241}
242
243#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
258#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
259#[cfg_attr(feature = "schemars", schemars(inline))]
260#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
261#[cfg_attr(
262 feature = "sqlx",
263 sqlx(type_name = "client_platform_enum", rename_all = "snake_case")
264)]
265#[serde(rename_all = "snake_case")]
266pub enum ClientPlatform {
267 Claude,
270 Chatgpt,
272 OtherClient,
275 OperatorToken,
279 Unrecorded,
281 #[serde(other)]
284 #[cfg_attr(feature = "schemars", schemars(skip))]
285 Unknown,
286}
287
288impl ClientPlatform {
289 pub fn label(self) -> &'static str {
292 match self {
293 Self::Claude => "via Claude (Anthropic)",
294 Self::Chatgpt => "via ChatGPT (OpenAI)",
295 Self::OtherClient => "via an MCP app",
296 Self::OperatorToken => "via direct token",
297 Self::Unrecorded => "via OAuth (not recorded)",
298 Self::Unknown => "via another channel",
299 }
300 }
301}
302
303#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
305#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
306#[cfg_attr(feature = "schemars", schemars(inline))]
307#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
308#[cfg_attr(
309 feature = "sqlx",
310 sqlx(
311 type_name = "governance_log_entry_type_enum",
312 rename_all = "snake_case"
313 )
314)]
315#[serde(rename_all = "snake_case")]
316pub enum GovernanceLogEntryType {
317 CouncilDecision,
318 AppealsCourtDecision,
319 EmergencyAction,
320 PolicyChange,
321 StewardVeto,
322 Amendment,
326 KeyRotation,
329 StewardRecord,
334}
335
336#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
339#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
340#[cfg_attr(feature = "schemars", schemars(inline))]
341#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
342#[cfg_attr(
343 feature = "sqlx",
344 sqlx(
345 type_name = "governance_amendment_kind_enum",
346 rename_all = "snake_case"
347 )
348)]
349#[serde(rename_all = "snake_case")]
350pub enum AmendmentKind {
351 NonPrecedential,
353 Overruled,
355 Superseded,
357 Reinstated,
359 Correction,
361 Redaction,
363 Reattested,
366 Revision,
369}
370
371#[derive(
376 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
377)]
378#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
379#[cfg_attr(feature = "schemars", schemars(inline))]
380#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
381#[cfg_attr(
382 feature = "sqlx",
383 sqlx(type_name = "governance_standing_enum", rename_all = "snake_case")
384)]
385#[serde(rename_all = "snake_case")]
386pub enum Standing {
387 #[default]
388 InForce,
389 NonPrecedential,
390 Overruled,
391 Superseded,
392}
393
394#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
397#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
398#[cfg_attr(feature = "schemars", schemars(inline))]
399#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
400#[cfg_attr(
401 feature = "sqlx",
402 sqlx(type_name = "governance_key_status_enum", rename_all = "snake_case")
403)]
404#[serde(rename_all = "snake_case")]
405pub enum KeyStatus {
406 Active,
408 Retired,
410 Compromised,
413}
414
415#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
421#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
422#[cfg_attr(feature = "schemars", schemars(inline))]
423#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
424#[cfg_attr(
425 feature = "sqlx",
426 sqlx(type_name = "meeting_status_enum", rename_all = "snake_case")
427)]
428#[serde(rename_all = "snake_case")]
429pub enum MeetingStatus {
430 Active,
431 Adjourned,
432 Cancelled,
433}
434
435#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
437#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
438#[cfg_attr(feature = "schemars", schemars(inline))]
439#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
440#[cfg_attr(
441 feature = "sqlx",
442 sqlx(type_name = "agenda_item_status_enum", rename_all = "snake_case")
443)]
444#[serde(rename_all = "snake_case")]
445pub enum AgendaItemStatus {
446 Pending,
447 Deliberating,
448 Decided,
449 Deferred,
450 CarriedOver,
451}
452
453#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
455#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
456#[cfg_attr(feature = "schemars", schemars(inline))]
457#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
458#[cfg_attr(
459 feature = "sqlx",
460 sqlx(type_name = "agenda_source_type_enum", rename_all = "snake_case")
461)]
462#[serde(rename_all = "snake_case")]
463pub enum AgendaSourceType {
464 Proposal,
465 AppealReferral,
466 StewardSubmission,
467 Internal,
468}
469
470#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
472#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
473#[cfg_attr(feature = "schemars", schemars(inline))]
474#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
475#[cfg_attr(
476 feature = "sqlx",
477 sqlx(type_name = "round_type_enum", rename_all = "snake_case")
478)]
479#[serde(rename_all = "snake_case")]
480pub enum RoundType {
481 Independent,
482 Deliberation,
483 FinalVote,
484}
485
486#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
488#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
489#[cfg_attr(feature = "schemars", schemars(inline))]
490#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
491#[cfg_attr(
492 feature = "sqlx",
493 sqlx(type_name = "decision_outcome_enum", rename_all = "snake_case")
494)]
495#[serde(rename_all = "snake_case")]
496pub enum DecisionOutcome {
497 Approved,
498 Rejected,
499 Deferred,
500 Amended,
501}
502
503#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
509#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
510#[cfg_attr(feature = "schemars", schemars(inline))]
511#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
512#[cfg_attr(
513 feature = "sqlx",
514 sqlx(type_name = "batch_type_enum", rename_all = "snake_case")
515)]
516#[serde(rename_all = "snake_case")]
517pub enum BatchType {
518 Jury,
519 Judge,
520 Tier2,
521 Redaction,
523 Chambers,
529 Precedent,
533}
534
535#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
537#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
538#[cfg_attr(feature = "schemars", schemars(inline))]
539#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
540#[cfg_attr(
541 feature = "sqlx",
542 sqlx(type_name = "batch_status_enum", rename_all = "snake_case")
543)]
544#[serde(rename_all = "snake_case")]
545pub enum BatchStatus {
546 Submitted,
547 Polling,
548 Completed,
549 Failed,
550}
551
552#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
558#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
559#[cfg_attr(feature = "schemars", schemars(inline))]
560#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
561#[cfg_attr(
562 feature = "sqlx",
563 sqlx(type_name = "oauth_scope_enum", rename_all = "snake_case")
564)]
565#[serde(rename_all = "snake_case")]
566pub enum OAuthScope {
567 Read,
568 Write,
569}
570
571#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
577#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
578#[cfg_attr(feature = "schemars", schemars(inline))]
579#[serde(rename_all = "snake_case")]
580pub enum FeedSort {
581 Date,
582 Score,
583 Active,
584 Random,
585 Controversial,
586 Diverse,
587 Unpopular,
593}
594
595#[derive(
609 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
610)]
611#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
612#[cfg_attr(feature = "schemars", schemars(inline))]
613#[serde(rename_all = "snake_case")]
614pub enum ProposalSort {
615 #[default]
618 Newest,
619 Oldest,
622 Score,
624}
625
626#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
638#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
639#[cfg_attr(feature = "schemars", schemars(inline))]
640#[serde(rename_all = "snake_case")]
641pub enum DetailLevel {
642 Summary,
644 Full,
648}
649
650#[derive(
655 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
656)]
657#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
658#[cfg_attr(feature = "schemars", schemars(inline))]
659#[serde(rename_all = "snake_case")]
660pub enum RecordVersion {
661 #[default]
663 Latest,
664 Original,
666}
667
668#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
679#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
680#[cfg_attr(feature = "schemars", schemars(inline))]
681#[serde(rename_all = "snake_case")]
682pub enum SearchMode {
683 Keyword,
685 Semantic,
690}
691
692#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
702#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
703#[cfg_attr(feature = "schemars", schemars(inline))]
704#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
705#[cfg_attr(
706 feature = "sqlx",
707 sqlx(type_name = "friendship_status", rename_all = "snake_case")
708)]
709#[serde(rename_all = "snake_case")]
710pub enum FriendshipStatus {
711 Pending,
712 Accepted,
713 Declined,
714}
715
716#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
720#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
721#[cfg_attr(feature = "schemars", schemars(inline))]
722#[serde(rename_all = "snake_case")]
723pub enum FriendshipAction {
724 Request,
726 Accept,
728 Decline,
730 Unfriend,
732}
733
734#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
741#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
742#[cfg_attr(feature = "schemars", schemars(inline))]
743#[cfg_attr(
744 feature = "sqlx",
745 derive(sqlx::Type),
746 sqlx(type_name = "message_encryption", rename_all = "snake_case")
747)]
748#[serde(rename_all = "snake_case")]
749pub enum MessageEncryption {
750 E2ee,
752 Server,
754}
755
756#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
758#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
759#[cfg_attr(feature = "schemars", schemars(inline))]
760#[serde(rename_all = "snake_case")]
761pub enum BlockAction {
762 Block,
763 Unblock,
764}
765
766impl_display_fromstr!(TargetType);
771impl_display_fromstr!(ClientPlatform);
772impl_display_fromstr!(ModerationTargetType);
773impl_display_fromstr!(ModerationActionType);
774impl_display_fromstr!(ModerationTier);
775impl_display_fromstr!(AppealStatus);
776impl_display_fromstr!(AppealOutcome);
777impl_display_fromstr!(ModelRole);
778impl_display_fromstr!(ProposalCategory);
779impl_display_fromstr!(GovernanceLogEntryType);
780impl_display_fromstr!(AmendmentKind);
781impl_display_fromstr!(Standing);
782impl_display_fromstr!(KeyStatus);
783impl_display_fromstr!(MeetingStatus);
784impl_display_fromstr!(AgendaItemStatus);
785impl_display_fromstr!(AgendaSourceType);
786impl_display_fromstr!(RoundType);
787impl_display_fromstr!(DecisionOutcome);
788impl_display_fromstr!(BatchType);
789impl_display_fromstr!(BatchStatus);
790impl_display_fromstr!(OAuthScope);
791impl_display_fromstr!(FeedSort);
792impl_display_fromstr!(ProposalSort);
793impl_display_fromstr!(DetailLevel);
794impl_display_fromstr!(RecordVersion);
795impl_display_fromstr!(SearchMode);
796impl_display_fromstr!(FriendshipStatus);
797impl_display_fromstr!(FriendshipAction);
798impl_display_fromstr!(BlockAction);
799impl_display_fromstr!(MessageEncryption);
800
801#[cfg(test)]
802mod tests {
803 use super::*;
804
805 #[test]
806 fn target_type_serde_round_trip() {
807 let val = TargetType::Post;
808 let json = serde_json::to_string(&val).unwrap();
809 assert_eq!(json, "\"post\"");
810 let deserialized: TargetType = serde_json::from_str(&json).unwrap();
811 assert_eq!(val, deserialized);
812 }
813
814 #[test]
815 fn target_type_display() {
816 assert_eq!(TargetType::Post.to_string(), "post");
817 assert_eq!(TargetType::Comment.to_string(), "comment");
818 }
819
820 #[test]
821 fn target_type_from_str() {
822 assert_eq!(TargetType::from_str("post").unwrap(), TargetType::Post);
823 assert_eq!(
824 TargetType::from_str("comment").unwrap(),
825 TargetType::Comment
826 );
827 }
828
829 #[test]
830 fn moderation_tier_serde() {
831 let tier = ModerationTier::Tier2;
832 let json = serde_json::to_string(&tier).unwrap();
833 assert_eq!(json, "\"2\"");
834 let deserialized: ModerationTier = serde_json::from_str(&json).unwrap();
835 assert_eq!(tier, deserialized);
836 }
837
838 #[test]
841 fn message_encryption_wire_values() {
842 assert_eq!(
843 serde_json::to_string(&MessageEncryption::E2ee).unwrap(),
844 "\"e2ee\""
845 );
846 assert_eq!(
847 serde_json::to_string(&MessageEncryption::Server).unwrap(),
848 "\"server\""
849 );
850 assert_eq!(MessageEncryption::E2ee.to_string(), "e2ee");
851 assert_eq!(
852 MessageEncryption::from_str("server").unwrap(),
853 MessageEncryption::Server
854 );
855 }
856
857 #[test]
858 fn search_mode_wire_values() {
859 assert_eq!(
860 serde_json::to_string(&SearchMode::Keyword).unwrap(),
861 "\"keyword\""
862 );
863 assert_eq!(
864 serde_json::to_string(&SearchMode::Semantic).unwrap(),
865 "\"semantic\""
866 );
867 assert_eq!(
868 SearchMode::from_str("semantic").unwrap(),
869 SearchMode::Semantic
870 );
871 }
872
873 #[test]
874 fn feed_sort_unpopular_round_trip() {
875 let json = serde_json::to_string(&FeedSort::Unpopular).unwrap();
876 assert_eq!(json, "\"unpopular\"");
877 let back: FeedSort = serde_json::from_str(&json).unwrap();
878 assert_eq!(back, FeedSort::Unpopular);
879 assert_eq!(FeedSort::Unpopular.to_string(), "unpopular");
880 assert_eq!(
881 FeedSort::from_str("unpopular").unwrap(),
882 FeedSort::Unpopular
883 );
884 }
885
886 #[cfg(feature = "schemars")]
890 #[test]
891 fn feed_sort_schema_is_ref_free() {
892 use schemars::JsonSchema;
893
894 assert!(<FeedSort as JsonSchema>::inline_schema());
895
896 let schema = schemars::schema_for!(FeedSort);
897 let value = serde_json::to_value(&schema).unwrap();
898 let blob = value.to_string();
899 assert!(value.get("$defs").is_none(), "no $defs: {value}");
900 assert!(!blob.contains("$ref"), "no $ref: {value}");
901
902 let variants = value["oneOf"]
908 .as_array()
909 .expect("FeedSort should have an inline `oneOf` array");
910 let mut found: Vec<&str> = variants
911 .iter()
912 .filter_map(|v| v["const"].as_str())
913 .collect();
914 for branch in variants {
915 if let Some(plain) = branch["enum"].as_array() {
916 found.extend(plain.iter().filter_map(|v| v.as_str()));
917 }
918 }
919 for expected in [
920 "date",
921 "score",
922 "active",
923 "random",
924 "controversial",
925 "diverse",
926 "unpopular",
927 ] {
928 assert!(found.contains(&expected), "{value}");
929 }
930 }
931
932 #[test]
933 fn proposal_category_round_trip() {
934 for cat in [
935 ProposalCategory::Routine,
936 ProposalCategory::Policy,
937 ProposalCategory::Constitutional,
938 ProposalCategory::Emergency,
939 ] {
940 let json = serde_json::to_string(&cat).unwrap();
941 let back: ProposalCategory = serde_json::from_str(&json).unwrap();
942 assert_eq!(cat, back);
943 }
944 }
945
946 #[test]
949 fn governance_amendment_and_key_wire_values() {
950 assert_eq!(GovernanceLogEntryType::Amendment.to_string(), "amendment");
951 assert_eq!(
952 GovernanceLogEntryType::KeyRotation.to_string(),
953 "key_rotation"
954 );
955 assert_eq!(
956 AmendmentKind::NonPrecedential.to_string(),
957 "non_precedential"
958 );
959 assert_eq!(AmendmentKind::Reattested.to_string(), "reattested");
960 assert_eq!(AmendmentKind::Revision.to_string(), "revision");
961 assert_eq!(RecordVersion::default(), RecordVersion::Latest);
962 assert_eq!(RecordVersion::Original.to_string(), "original");
963 assert_eq!(
964 "latest".parse::<RecordVersion>().unwrap(),
965 RecordVersion::Latest
966 );
967 assert_eq!(
968 "superseded".parse::<AmendmentKind>().unwrap(),
969 AmendmentKind::Superseded
970 );
971 assert_eq!(Standing::default(), Standing::InForce);
972 assert_eq!(Standing::InForce.to_string(), "in_force");
973 assert_eq!(
974 "compromised".parse::<KeyStatus>().unwrap(),
975 KeyStatus::Compromised
976 );
977 assert_eq!(KeyStatus::Retired.to_string(), "retired");
978 }
979
980 #[cfg(feature = "schemars")]
985 #[test]
986 fn enum_json_schema_is_inlined() {
987 use schemars::JsonSchema;
988
989 assert!(<TargetType as JsonSchema>::inline_schema());
990 assert!(<FeedSort as JsonSchema>::inline_schema());
991 assert!(<ProposalSort as JsonSchema>::inline_schema());
992 assert!(<DetailLevel as JsonSchema>::inline_schema());
993 assert!(<RecordVersion as JsonSchema>::inline_schema());
994 assert!(<SearchMode as JsonSchema>::inline_schema());
995 assert!(<ProposalCategory as JsonSchema>::inline_schema());
996 assert!(<GovernanceLogEntryType as JsonSchema>::inline_schema());
997 assert!(<AmendmentKind as JsonSchema>::inline_schema());
998 assert!(<Standing as JsonSchema>::inline_schema());
999 assert!(<KeyStatus as JsonSchema>::inline_schema());
1000 assert!(<OAuthScope as JsonSchema>::inline_schema());
1001 assert!(<ModerationTargetType as JsonSchema>::inline_schema());
1002 assert!(<ModerationTier as JsonSchema>::inline_schema());
1003
1004 #[derive(schemars::JsonSchema)]
1005 #[allow(dead_code)]
1006 struct Container {
1007 target_type: TargetType,
1008 sort: Option<FeedSort>,
1009 proposal_sort: Option<ProposalSort>,
1010 category: Option<ProposalCategory>,
1011 detail: Option<DetailLevel>,
1012 version: Option<RecordVersion>,
1013 search_mode: Option<SearchMode>,
1014 }
1015
1016 let schema = schemars::schema_for!(Container);
1017 let value = serde_json::to_value(&schema).unwrap();
1018 let blob = value.to_string();
1019
1020 assert!(
1021 value.get("$defs").is_none(),
1022 "no $defs should be emitted for enum-only container; got schema: {value}"
1023 );
1024 assert!(
1025 !blob.contains("$ref"),
1026 "enum container schema must contain no $ref anywhere; got: {value}"
1027 );
1028
1029 let target_type_enum = value["properties"]["target_type"]["enum"]
1031 .as_array()
1032 .expect("target_type should have inline `enum` array");
1033 assert!(
1034 target_type_enum
1035 .contains(&serde_json::Value::String("post".into()))
1036 );
1037 assert!(
1038 target_type_enum
1039 .contains(&serde_json::Value::String("comment".into()))
1040 );
1041 }
1042
1043 #[cfg(feature = "schemars")]
1049 #[test]
1050 fn search_mode_schema_is_ref_free() {
1051 use schemars::JsonSchema;
1052
1053 assert!(<SearchMode as JsonSchema>::inline_schema());
1054
1055 let schema = schemars::schema_for!(SearchMode);
1056 let value = serde_json::to_value(&schema).unwrap();
1057 let blob = value.to_string();
1058 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1059 assert!(!blob.contains("$ref"), "no $ref: {value}");
1060
1061 let variants = value["oneOf"]
1067 .as_array()
1068 .expect("SearchMode should have an inline `oneOf` array");
1069 let consts: Vec<&str> = variants
1070 .iter()
1071 .filter_map(|v| v["const"].as_str())
1072 .collect();
1073 assert!(consts.contains(&"keyword"), "{value}");
1074 assert!(consts.contains(&"semantic"), "{value}");
1075 }
1076}