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)]
641#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
642#[cfg_attr(feature = "schemars", schemars(inline))]
643#[serde(rename_all = "snake_case")]
644pub enum DetailLevel {
645 Summary,
647 Full,
650}
651
652#[derive(
657 Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
658)]
659#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
660#[cfg_attr(feature = "schemars", schemars(inline))]
661#[serde(rename_all = "snake_case")]
662pub enum RecordVersion {
663 #[default]
665 Latest,
666 Original,
668}
669
670#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
681#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
682#[cfg_attr(feature = "schemars", schemars(inline))]
683#[serde(rename_all = "snake_case")]
684pub enum SearchMode {
685 Keyword,
687 Semantic,
692}
693
694#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
704#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
705#[cfg_attr(feature = "schemars", schemars(inline))]
706#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
707#[cfg_attr(
708 feature = "sqlx",
709 sqlx(type_name = "friendship_status", rename_all = "snake_case")
710)]
711#[serde(rename_all = "snake_case")]
712pub enum FriendshipStatus {
713 Pending,
714 Accepted,
715 Declined,
716}
717
718#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
722#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
723#[cfg_attr(feature = "schemars", schemars(inline))]
724#[serde(rename_all = "snake_case")]
725pub enum FriendshipAction {
726 Request,
728 Accept,
730 Decline,
732 Unfriend,
734}
735
736#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
743#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
744#[cfg_attr(feature = "schemars", schemars(inline))]
745#[cfg_attr(
746 feature = "sqlx",
747 derive(sqlx::Type),
748 sqlx(type_name = "message_encryption", rename_all = "snake_case")
749)]
750#[serde(rename_all = "snake_case")]
751pub enum MessageEncryption {
752 E2ee,
754 Server,
756}
757
758#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
760#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
761#[cfg_attr(feature = "schemars", schemars(inline))]
762#[serde(rename_all = "snake_case")]
763pub enum BlockAction {
764 Block,
765 Unblock,
766}
767
768impl_display_fromstr!(TargetType);
773impl_display_fromstr!(ClientPlatform);
774impl_display_fromstr!(ModerationTargetType);
775impl_display_fromstr!(ModerationActionType);
776impl_display_fromstr!(ModerationTier);
777impl_display_fromstr!(AppealStatus);
778impl_display_fromstr!(AppealOutcome);
779impl_display_fromstr!(ModelRole);
780impl_display_fromstr!(ProposalCategory);
781impl_display_fromstr!(GovernanceLogEntryType);
782impl_display_fromstr!(AmendmentKind);
783impl_display_fromstr!(Standing);
784impl_display_fromstr!(KeyStatus);
785impl_display_fromstr!(MeetingStatus);
786impl_display_fromstr!(AgendaItemStatus);
787impl_display_fromstr!(AgendaSourceType);
788impl_display_fromstr!(RoundType);
789impl_display_fromstr!(DecisionOutcome);
790impl_display_fromstr!(BatchType);
791impl_display_fromstr!(BatchStatus);
792impl_display_fromstr!(OAuthScope);
793impl_display_fromstr!(FeedSort);
794impl_display_fromstr!(ProposalSort);
795impl_display_fromstr!(DetailLevel);
796impl_display_fromstr!(RecordVersion);
797impl_display_fromstr!(SearchMode);
798impl_display_fromstr!(FriendshipStatus);
799impl_display_fromstr!(FriendshipAction);
800impl_display_fromstr!(BlockAction);
801impl_display_fromstr!(MessageEncryption);
802
803#[cfg(test)]
804mod tests {
805 use super::*;
806
807 #[test]
808 fn target_type_serde_round_trip() {
809 let val = TargetType::Post;
810 let json = serde_json::to_string(&val).unwrap();
811 assert_eq!(json, "\"post\"");
812 let deserialized: TargetType = serde_json::from_str(&json).unwrap();
813 assert_eq!(val, deserialized);
814 }
815
816 #[test]
817 fn target_type_display() {
818 assert_eq!(TargetType::Post.to_string(), "post");
819 assert_eq!(TargetType::Comment.to_string(), "comment");
820 }
821
822 #[test]
823 fn target_type_from_str() {
824 assert_eq!(TargetType::from_str("post").unwrap(), TargetType::Post);
825 assert_eq!(
826 TargetType::from_str("comment").unwrap(),
827 TargetType::Comment
828 );
829 }
830
831 #[test]
832 fn moderation_tier_serde() {
833 let tier = ModerationTier::Tier2;
834 let json = serde_json::to_string(&tier).unwrap();
835 assert_eq!(json, "\"2\"");
836 let deserialized: ModerationTier = serde_json::from_str(&json).unwrap();
837 assert_eq!(tier, deserialized);
838 }
839
840 #[test]
843 fn message_encryption_wire_values() {
844 assert_eq!(
845 serde_json::to_string(&MessageEncryption::E2ee).unwrap(),
846 "\"e2ee\""
847 );
848 assert_eq!(
849 serde_json::to_string(&MessageEncryption::Server).unwrap(),
850 "\"server\""
851 );
852 assert_eq!(MessageEncryption::E2ee.to_string(), "e2ee");
853 assert_eq!(
854 MessageEncryption::from_str("server").unwrap(),
855 MessageEncryption::Server
856 );
857 }
858
859 #[test]
860 fn search_mode_wire_values() {
861 assert_eq!(
862 serde_json::to_string(&SearchMode::Keyword).unwrap(),
863 "\"keyword\""
864 );
865 assert_eq!(
866 serde_json::to_string(&SearchMode::Semantic).unwrap(),
867 "\"semantic\""
868 );
869 assert_eq!(
870 SearchMode::from_str("semantic").unwrap(),
871 SearchMode::Semantic
872 );
873 }
874
875 #[test]
876 fn feed_sort_unpopular_round_trip() {
877 let json = serde_json::to_string(&FeedSort::Unpopular).unwrap();
878 assert_eq!(json, "\"unpopular\"");
879 let back: FeedSort = serde_json::from_str(&json).unwrap();
880 assert_eq!(back, FeedSort::Unpopular);
881 assert_eq!(FeedSort::Unpopular.to_string(), "unpopular");
882 assert_eq!(
883 FeedSort::from_str("unpopular").unwrap(),
884 FeedSort::Unpopular
885 );
886 }
887
888 #[cfg(feature = "schemars")]
892 #[test]
893 fn feed_sort_schema_is_ref_free() {
894 use schemars::JsonSchema;
895
896 assert!(<FeedSort as JsonSchema>::inline_schema());
897
898 let schema = schemars::schema_for!(FeedSort);
899 let value = serde_json::to_value(&schema).unwrap();
900 let blob = value.to_string();
901 assert!(value.get("$defs").is_none(), "no $defs: {value}");
902 assert!(!blob.contains("$ref"), "no $ref: {value}");
903
904 let variants = value["oneOf"]
910 .as_array()
911 .expect("FeedSort should have an inline `oneOf` array");
912 let mut found: Vec<&str> = variants
913 .iter()
914 .filter_map(|v| v["const"].as_str())
915 .collect();
916 for branch in variants {
917 if let Some(plain) = branch["enum"].as_array() {
918 found.extend(plain.iter().filter_map(|v| v.as_str()));
919 }
920 }
921 for expected in [
922 "date",
923 "score",
924 "active",
925 "random",
926 "controversial",
927 "diverse",
928 "unpopular",
929 ] {
930 assert!(found.contains(&expected), "{value}");
931 }
932 }
933
934 #[test]
935 fn proposal_category_round_trip() {
936 for cat in [
937 ProposalCategory::Routine,
938 ProposalCategory::Policy,
939 ProposalCategory::Constitutional,
940 ProposalCategory::Emergency,
941 ] {
942 let json = serde_json::to_string(&cat).unwrap();
943 let back: ProposalCategory = serde_json::from_str(&json).unwrap();
944 assert_eq!(cat, back);
945 }
946 }
947
948 #[test]
951 fn governance_amendment_and_key_wire_values() {
952 assert_eq!(GovernanceLogEntryType::Amendment.to_string(), "amendment");
953 assert_eq!(
954 GovernanceLogEntryType::KeyRotation.to_string(),
955 "key_rotation"
956 );
957 assert_eq!(
958 AmendmentKind::NonPrecedential.to_string(),
959 "non_precedential"
960 );
961 assert_eq!(AmendmentKind::Reattested.to_string(), "reattested");
962 assert_eq!(AmendmentKind::Revision.to_string(), "revision");
963 assert_eq!(RecordVersion::default(), RecordVersion::Latest);
964 assert_eq!(RecordVersion::Original.to_string(), "original");
965 assert_eq!(
966 "latest".parse::<RecordVersion>().unwrap(),
967 RecordVersion::Latest
968 );
969 assert_eq!(
970 "superseded".parse::<AmendmentKind>().unwrap(),
971 AmendmentKind::Superseded
972 );
973 assert_eq!(Standing::default(), Standing::InForce);
974 assert_eq!(Standing::InForce.to_string(), "in_force");
975 assert_eq!(
976 "compromised".parse::<KeyStatus>().unwrap(),
977 KeyStatus::Compromised
978 );
979 assert_eq!(KeyStatus::Retired.to_string(), "retired");
980 }
981
982 #[cfg(feature = "schemars")]
987 #[test]
988 fn enum_json_schema_is_inlined() {
989 use schemars::JsonSchema;
990
991 assert!(<TargetType as JsonSchema>::inline_schema());
992 assert!(<FeedSort as JsonSchema>::inline_schema());
993 assert!(<ProposalSort as JsonSchema>::inline_schema());
994 assert!(<DetailLevel as JsonSchema>::inline_schema());
995 assert!(<RecordVersion as JsonSchema>::inline_schema());
996 assert!(<SearchMode as JsonSchema>::inline_schema());
997 assert!(<ProposalCategory as JsonSchema>::inline_schema());
998 assert!(<GovernanceLogEntryType as JsonSchema>::inline_schema());
999 assert!(<AmendmentKind as JsonSchema>::inline_schema());
1000 assert!(<Standing as JsonSchema>::inline_schema());
1001 assert!(<KeyStatus as JsonSchema>::inline_schema());
1002 assert!(<OAuthScope as JsonSchema>::inline_schema());
1003 assert!(<ModerationTargetType as JsonSchema>::inline_schema());
1004 assert!(<ModerationTier as JsonSchema>::inline_schema());
1005
1006 #[derive(schemars::JsonSchema)]
1007 #[allow(dead_code)]
1008 struct Container {
1009 target_type: TargetType,
1010 sort: Option<FeedSort>,
1011 proposal_sort: Option<ProposalSort>,
1012 category: Option<ProposalCategory>,
1013 detail: Option<DetailLevel>,
1014 version: Option<RecordVersion>,
1015 search_mode: Option<SearchMode>,
1016 }
1017
1018 let schema = schemars::schema_for!(Container);
1019 let value = serde_json::to_value(&schema).unwrap();
1020 let blob = value.to_string();
1021
1022 assert!(
1023 value.get("$defs").is_none(),
1024 "no $defs should be emitted for enum-only container; got schema: {value}"
1025 );
1026 assert!(
1027 !blob.contains("$ref"),
1028 "enum container schema must contain no $ref anywhere; got: {value}"
1029 );
1030
1031 let target_type_enum = value["properties"]["target_type"]["enum"]
1033 .as_array()
1034 .expect("target_type should have inline `enum` array");
1035 assert!(
1036 target_type_enum
1037 .contains(&serde_json::Value::String("post".into()))
1038 );
1039 assert!(
1040 target_type_enum
1041 .contains(&serde_json::Value::String("comment".into()))
1042 );
1043 }
1044
1045 #[cfg(feature = "schemars")]
1051 #[test]
1052 fn search_mode_schema_is_ref_free() {
1053 use schemars::JsonSchema;
1054
1055 assert!(<SearchMode as JsonSchema>::inline_schema());
1056
1057 let schema = schemars::schema_for!(SearchMode);
1058 let value = serde_json::to_value(&schema).unwrap();
1059 let blob = value.to_string();
1060 assert!(value.get("$defs").is_none(), "no $defs: {value}");
1061 assert!(!blob.contains("$ref"), "no $ref: {value}");
1062
1063 let variants = value["oneOf"]
1069 .as_array()
1070 .expect("SearchMode should have an inline `oneOf` array");
1071 let consts: Vec<&str> = variants
1072 .iter()
1073 .filter_map(|v| v["const"].as_str())
1074 .collect();
1075 assert!(consts.contains(&"keyword"), "{value}");
1076 assert!(consts.contains(&"semantic"), "{value}");
1077 }
1078}