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