Skip to main content

mantra_schema/report/
annotations.rs

1use relative_path::RelativePathBuf;
2
3use crate::{
4    FmtHash, Line, LineSpan, Properties,
5    annotations::{CoverageExclude, ElementKind, TraceKind, TraceRelatedCodeVariant},
6    product::ProductId,
7    report::{Aggregated, requirement::RequirementReference},
8    requirements::ReqId,
9};
10
11#[derive(
12    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
13)]
14#[serde(rename_all = "snake_case")]
15pub struct TraceReference {
16    #[schemars(with = "String")]
17    pub filepath: RelativePathBuf,
18    pub file_hash: FmtHash,
19    pub line: Line,
20    pub kind: TraceKind,
21}
22
23#[derive(
24    Debug,
25    Clone,
26    Copy,
27    Default,
28    PartialEq,
29    serde::Serialize,
30    serde::Deserialize,
31    schemars::JsonSchema,
32)]
33pub struct TracesSummary {
34    pub total: i64,
35    pub satisfies: Aggregated,
36    pub verifies: Aggregated,
37    pub clarifies: Aggregated,
38    pub links: Aggregated,
39}
40
41impl TracesSummary {
42    pub fn add(&mut self, other: &Self) {
43        self.total += other.total;
44
45        self.satisfies.cnt += other.satisfies.cnt;
46        self.verifies.cnt += other.verifies.cnt;
47        self.clarifies.cnt += other.clarifies.cnt;
48        self.links.cnt += other.links.cnt;
49
50        self.update_percentages();
51    }
52
53    pub fn update_percentages(&mut self) {
54        self.satisfies.update_percentage(self.total);
55        self.verifies.update_percentage(self.total);
56        self.clarifies.update_percentage(self.total);
57        self.links.update_percentage(self.total);
58    }
59}
60
61#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
62#[serde(rename_all = "snake_case")]
63pub struct ResolvedAnnotations {
64    pub traces: Option<Vec<ResolvedTrace>>,
65    pub elements: Option<Vec<ResolvedElement>>,
66    pub coverage_excludes: Option<Vec<CoverageExclude>>,
67}
68
69#[derive(
70    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
71)]
72#[serde(rename_all = "snake_case")]
73pub struct ResolvedTrace {
74    /// The requirement IDs that are referenced by the trace.
75    /// [req("trace.id", "trace.mult_reqs")]
76    pub resolved_ids: Vec<RequirementReference>,
77    pub unknown_ids: Vec<ReqId>,
78    /// The line the trace is defined at.
79    /// [req("trace.origin")]
80    pub line: Line,
81    /// Optional related code block or element that is linked to the trace.
82    /// [req("trace.code_block", "trace.element")]
83    pub related_code: Option<TraceRelatedCodeVariant>,
84    /// Trace kind.
85    /// [req("trace.kind`")]
86    pub kind: TraceKind,
87    /// List of custom properties that may be set on a trace.
88    /// [req("trace.properties")]
89    pub properties: Option<Properties>,
90}
91
92#[derive(
93    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
94)]
95#[serde(rename_all = "snake_case")]
96pub struct ResolvedElement {
97    /// The fully qualified identifier of the element.
98    /// [req("trace.element.ident")]
99    pub idents: Option<Vec<ResolvedElementIdent>>,
100    /// The element name.
101    ///
102    /// **Note:** This is not the fully qualified identifier.
103    pub name: String,
104    /// The line the element is defined at.
105    ///
106    /// **Note:** This might differ from `span.start`,
107    /// because in Rust for example, attributes & doc-comments are part of the span,
108    /// but the definition of an element starts below them.
109    ///
110    /// TODO: trace req
111    pub definition_line: Line,
112    /// The line span of the element.
113    /// [req("trace.element.span")]
114    pub span: LineSpan,
115    /// The kind of the element.
116    /// [req("trace.element.kind")]
117    pub kind: ElementKind,
118}
119
120#[derive(
121    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
122)]
123#[serde(rename_all = "snake_case")]
124pub struct ResolvedElementIdent {
125    pub ident: String,
126    pub product_ids: Vec<ProductId>,
127}