made_api/
authoring_views.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct DefinitionDefectView {
6 pub severity: String,
8 pub locus: String,
10 pub defect: String,
12 pub blocking: bool,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21pub struct DefinitionAnalysisView {
22 pub definition_name: String,
24 pub definition_version: String,
25 pub publishable: bool,
27 pub definition_digest: Option<String>,
33 pub defects: Vec<DefinitionDefectView>,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38pub struct PublishedDefinitionView {
39 pub name: String,
40 pub version: String,
41 pub digest: String,
44 pub already_published: bool,
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn an_analysis_survives_the_wire() {
56 let analysis = DefinitionAnalysisView {
57 definition_name: "scope_discovery".to_owned(),
58 definition_version: "1.0".to_owned(),
59 publishable: false,
60 definition_digest: None,
61 defects: vec![DefinitionDefectView {
62 severity: "error".to_owned(),
63 locus: "state `ORPHAN`".to_owned(),
64 defect: "state is unreachable".to_owned(),
65 blocking: true,
66 }],
67 };
68 let bytes = serde_json::to_vec(&analysis).expect("serializes");
69 assert_eq!(
70 serde_json::from_slice::<DefinitionAnalysisView>(&bytes).expect("deserializes"),
71 analysis
72 );
73 }
74
75 #[test]
76 fn a_publication_names_what_an_instance_will_bind_to() {
77 let published = PublishedDefinitionView {
78 name: "scope_discovery".to_owned(),
79 version: "1.0".to_owned(),
80 digest: "abc123".to_owned(),
81 already_published: false,
82 };
83 assert!(
84 !published.digest.is_empty(),
85 "a publication without a digest cannot be bound to, only believed"
86 );
87 }
88}