Skip to main content

provenant/output_schema/
summary.rs

1use serde::{Deserialize, Serialize};
2
3use super::license_clarity_score::OutputLicenseClarityScore;
4use super::tally_entry::OutputTallyEntry;
5
6#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
7pub struct OutputSummary {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub declared_license_expression: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub license_clarity_score: Option<OutputLicenseClarityScore>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub declared_holder: Option<String>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub primary_language: Option<String>,
16    #[serde(default, skip_serializing_if = "Vec::is_empty")]
17    pub other_license_expressions: Vec<OutputTallyEntry>,
18    #[serde(default, skip_serializing_if = "Vec::is_empty")]
19    pub other_holders: Vec<OutputTallyEntry>,
20    #[serde(default, skip_serializing_if = "Vec::is_empty")]
21    pub other_languages: Vec<OutputTallyEntry>,
22}
23
24impl From<&crate::models::Summary> for OutputSummary {
25    fn from(value: &crate::models::Summary) -> Self {
26        Self {
27            declared_license_expression: value.declared_license_expression.clone(),
28            license_clarity_score: value
29                .license_clarity_score
30                .as_ref()
31                .map(OutputLicenseClarityScore::from),
32            declared_holder: value.declared_holder.clone(),
33            primary_language: value.primary_language.clone(),
34            other_license_expressions: value
35                .other_license_expressions
36                .iter()
37                .map(OutputTallyEntry::from)
38                .collect(),
39            other_holders: value
40                .other_holders
41                .iter()
42                .map(OutputTallyEntry::from)
43                .collect(),
44            other_languages: value
45                .other_languages
46                .iter()
47                .map(OutputTallyEntry::from)
48                .collect(),
49        }
50    }
51}