provenant/output_schema/
top_level_license_detection.rs1use serde::{Deserialize, Serialize};
2
3use super::license_match::OutputMatch;
4
5#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
6pub struct OutputTopLevelLicenseDetection {
7 pub identifier: String,
8 pub license_expression: String,
9 pub license_expression_spdx: String,
10 pub detection_count: usize,
11 #[serde(skip_serializing_if = "Vec::is_empty", default)]
12 pub detection_log: Vec<String>,
13 pub reference_matches: Vec<OutputMatch>,
14}
15
16impl From<&crate::models::TopLevelLicenseDetection> for OutputTopLevelLicenseDetection {
17 fn from(value: &crate::models::TopLevelLicenseDetection) -> Self {
18 Self {
19 identifier: value.identifier.clone(),
20 license_expression: value.license_expression.clone(),
21 license_expression_spdx: value.license_expression_spdx.clone(),
22 detection_count: value.detection_count,
23 detection_log: value.detection_log.clone(),
24 reference_matches: value
25 .reference_matches
26 .iter()
27 .map(OutputMatch::from)
28 .collect(),
29 }
30 }
31}
32
33impl TryFrom<&OutputTopLevelLicenseDetection> for crate::models::TopLevelLicenseDetection {
34 type Error = String;
35 fn try_from(value: &OutputTopLevelLicenseDetection) -> Result<Self, Self::Error> {
36 let mut reference_matches = Vec::with_capacity(value.reference_matches.len());
37 for m in &value.reference_matches {
38 reference_matches.push(crate::models::Match::try_from(m)?);
39 }
40 Ok(Self {
41 identifier: value.identifier.clone(),
42 license_expression: value.license_expression.clone(),
43 license_expression_spdx: value.license_expression_spdx.clone(),
44 detection_count: value.detection_count,
45 detection_log: value.detection_log.clone(),
46 reference_matches,
47 })
48 }
49}