From d8cd8db857cf423ec5c5d17ae3a9e678712088ab Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 24 May 2022 20:31:04 +0530 Subject: [PATCH] fix: dont serialize legal section if all sub-fields are none --- federate/publiccodeyml/src/schema.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/federate/publiccodeyml/src/schema.rs b/federate/publiccodeyml/src/schema.rs index 3b02e70..5aae8c0 100644 --- a/federate/publiccodeyml/src/schema.rs +++ b/federate/publiccodeyml/src/schema.rs @@ -34,8 +34,8 @@ pub struct Repository { pub is_based_on: Option, #[serde(skip_serializing_if = "HashMap::is_empty")] pub description: HashMap, - #[serde(skip_serializing_if = "Option::is_none")] - pub legal: Option, + #[serde(skip_serializing_if = "Legal::is_none")] + pub legal: Legal, } #[derive(Serialize, Deserialize)] @@ -56,6 +56,13 @@ pub struct Legal { pub license: Option, } +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(),