provenant/output_schema/
output.rs1use serde::{Deserialize, Serialize};
5
6use super::facet_tallies::OutputFacetTallies;
7use super::file_info::OutputFileInfo;
8use super::header::OutputHeader;
9use super::license_reference::OutputLicenseReference;
10use super::license_rule_reference::OutputLicenseRuleReference;
11use super::package::OutputPackage;
12use super::summary::OutputSummary;
13use super::tallies::OutputTallies;
14use super::top_level_dependency::OutputTopLevelDependency;
15use super::top_level_license_detection::OutputTopLevelLicenseDetection;
16
17#[derive(Serialize, Deserialize, Debug)]
18pub struct Output {
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub summary: Option<OutputSummary>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub tallies: Option<OutputTallies>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub tallies_of_key_files: Option<OutputTallies>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub tallies_by_facet: Option<Vec<OutputFacetTallies>>,
27 pub headers: Vec<OutputHeader>,
28 pub packages: Vec<OutputPackage>,
29 pub dependencies: Vec<OutputTopLevelDependency>,
30 #[serde(default)]
31 pub license_detections: Vec<OutputTopLevelLicenseDetection>,
32 pub files: Vec<OutputFileInfo>,
33 pub license_references: Vec<OutputLicenseReference>,
34 pub license_rule_references: Vec<OutputLicenseRuleReference>,
35}
36
37impl From<&crate::models::Output> for Output {
38 fn from(value: &crate::models::Output) -> Self {
39 Self::from_with_compat_mode(value, crate::cli::CompatibilityMode::Native)
40 }
41}
42
43impl Output {
44 pub fn from_with_compat_mode(
45 value: &crate::models::Output,
46 mode: crate::cli::CompatibilityMode,
47 ) -> Self {
48 Self {
49 summary: value.summary.as_ref().map(OutputSummary::from),
50 tallies: value.tallies.as_ref().map(OutputTallies::from),
51 tallies_of_key_files: value.tallies_of_key_files.as_ref().map(OutputTallies::from),
52 tallies_by_facet: value
53 .tallies_by_facet
54 .as_ref()
55 .map(|v| v.iter().map(OutputFacetTallies::from).collect()),
56 headers: value.headers.iter().map(OutputHeader::from).collect(),
57 packages: value.packages.iter().map(OutputPackage::from).collect(),
58 dependencies: value
59 .dependencies
60 .iter()
61 .map(OutputTopLevelDependency::from)
62 .collect(),
63 license_detections: value
64 .license_detections
65 .iter()
66 .map(OutputTopLevelLicenseDetection::from)
67 .collect(),
68 files: value
69 .files
70 .iter()
71 .map(|file| OutputFileInfo::from_with_compat_mode(file, mode))
72 .collect(),
73 license_references: value
74 .license_references
75 .iter()
76 .map(OutputLicenseReference::from)
77 .collect(),
78 license_rule_references: value
79 .license_rule_references
80 .iter()
81 .map(OutputLicenseRuleReference::from)
82 .collect(),
83 }
84 }
85}