Skip to main content

provenant/output_schema/
license_reference.rs

1// SPDX-FileCopyrightText: Provenant contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct OutputLicenseReference {
8    #[serde(default, skip_serializing_if = "Option::is_none")]
9    pub key: Option<String>,
10    #[serde(default, skip_serializing_if = "Option::is_none")]
11    pub language: Option<String>,
12    pub name: String,
13    pub short_name: String,
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    pub owner: Option<String>,
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub homepage_url: Option<String>,
18    pub spdx_license_key: String,
19    #[serde(default, skip_serializing_if = "Vec::is_empty")]
20    pub other_spdx_license_keys: Vec<String>,
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub osi_license_key: Option<String>,
23    #[serde(default, skip_serializing_if = "Vec::is_empty")]
24    pub text_urls: Vec<String>,
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub osi_url: Option<String>,
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub faq_url: Option<String>,
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub other_urls: Vec<String>,
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub category: Option<String>,
33    #[serde(default)]
34    pub is_exception: bool,
35    #[serde(default)]
36    pub is_unknown: bool,
37    #[serde(default)]
38    pub is_generic: bool,
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub notes: Option<String>,
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub minimum_coverage: Option<u8>,
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub standard_notice: Option<String>,
45    #[serde(default, skip_serializing_if = "Vec::is_empty")]
46    pub ignorable_copyrights: Vec<String>,
47    #[serde(default, skip_serializing_if = "Vec::is_empty")]
48    pub ignorable_holders: Vec<String>,
49    #[serde(default, skip_serializing_if = "Vec::is_empty")]
50    pub ignorable_authors: Vec<String>,
51    #[serde(default, skip_serializing_if = "Vec::is_empty")]
52    pub ignorable_urls: Vec<String>,
53    #[serde(default, skip_serializing_if = "Vec::is_empty")]
54    pub ignorable_emails: Vec<String>,
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub scancode_url: Option<String>,
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub licensedb_url: Option<String>,
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub spdx_url: Option<String>,
61    pub text: String,
62}
63
64impl From<&crate::models::LicenseReference> for OutputLicenseReference {
65    fn from(value: &crate::models::LicenseReference) -> Self {
66        Self {
67            key: value.key.clone(),
68            language: value.language.clone(),
69            name: value.name.clone(),
70            short_name: value.short_name.clone(),
71            owner: value.owner.clone(),
72            homepage_url: value.homepage_url.clone(),
73            spdx_license_key: value.spdx_license_key.clone(),
74            other_spdx_license_keys: value.other_spdx_license_keys.clone(),
75            osi_license_key: value.osi_license_key.clone(),
76            text_urls: value.text_urls.clone(),
77            osi_url: value.osi_url.clone(),
78            faq_url: value.faq_url.clone(),
79            other_urls: value.other_urls.clone(),
80            category: value.category.clone(),
81            is_exception: value.is_exception,
82            is_unknown: value.is_unknown,
83            is_generic: value.is_generic,
84            notes: value.notes.clone(),
85            minimum_coverage: value.minimum_coverage,
86            standard_notice: value.standard_notice.clone(),
87            ignorable_copyrights: value.ignorable_copyrights.clone(),
88            ignorable_holders: value.ignorable_holders.clone(),
89            ignorable_authors: value.ignorable_authors.clone(),
90            ignorable_urls: value.ignorable_urls.clone(),
91            ignorable_emails: value.ignorable_emails.clone(),
92            scancode_url: value.scancode_url.clone(),
93            licensedb_url: value.licensedb_url.clone(),
94            spdx_url: value.spdx_url.clone(),
95            text: value.text.clone(),
96        }
97    }
98}
99
100impl TryFrom<&OutputLicenseReference> for crate::models::LicenseReference {
101    type Error = String;
102    fn try_from(value: &OutputLicenseReference) -> Result<Self, Self::Error> {
103        Ok(Self {
104            key: value.key.clone(),
105            language: value.language.clone(),
106            name: value.name.clone(),
107            short_name: value.short_name.clone(),
108            owner: value.owner.clone(),
109            homepage_url: value.homepage_url.clone(),
110            spdx_license_key: value.spdx_license_key.clone(),
111            other_spdx_license_keys: value.other_spdx_license_keys.clone(),
112            osi_license_key: value.osi_license_key.clone(),
113            text_urls: value.text_urls.clone(),
114            osi_url: value.osi_url.clone(),
115            faq_url: value.faq_url.clone(),
116            other_urls: value.other_urls.clone(),
117            category: value.category.clone(),
118            is_exception: value.is_exception,
119            is_unknown: value.is_unknown,
120            is_generic: value.is_generic,
121            notes: value.notes.clone(),
122            minimum_coverage: value.minimum_coverage,
123            standard_notice: value.standard_notice.clone(),
124            ignorable_copyrights: value.ignorable_copyrights.clone(),
125            ignorable_holders: value.ignorable_holders.clone(),
126            ignorable_authors: value.ignorable_authors.clone(),
127            ignorable_urls: value.ignorable_urls.clone(),
128            ignorable_emails: value.ignorable_emails.clone(),
129            scancode_url: value.scancode_url.clone(),
130            licensedb_url: value.licensedb_url.clone(),
131            spdx_url: value.spdx_url.clone(),
132            text: value.text.clone(),
133        })
134    }
135}