fix: dont serialize legal section if all sub-fields are none

This commit is contained in:
Aravinth Manivannan 2022-05-24 20:31:04 +05:30
parent 10f33d8ea6
commit d8cd8db857
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88

View file

@ -34,8 +34,8 @@ pub struct Repository {
pub is_based_on: Option<String>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub description: HashMap<String, Description>,
#[serde(skip_serializing_if = "Option::is_none")]
pub legal: Option<Legal>,
#[serde(skip_serializing_if = "Legal::is_none")]
pub legal: Legal,
}
#[derive(Serialize, Deserialize)]
@ -56,6 +56,13 @@ pub struct Legal {
pub license: Option<String>,
}
impl Legal {
/// global is_none, to skip_serializing_if
pub fn is_none(&self) -> bool {
self.license.is_none()
}
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Maintenance {
@ -85,7 +92,7 @@ impl From<&db_core::AddRepository<'_>> for Repository {
},
);
let legal = Some(Legal { license: None });
let legal = Legal { license: None };
Self {
publiccode_yml_version: PUBLIC_CODE_VERSION.into(),