fix: dont serialize legal section if all sub-fields are none
This commit is contained in:
parent
10f33d8ea6
commit
d8cd8db857
1 changed files with 10 additions and 3 deletions
|
@ -34,8 +34,8 @@ pub struct Repository {
|
||||||
pub is_based_on: Option<String>,
|
pub is_based_on: Option<String>,
|
||||||
#[serde(skip_serializing_if = "HashMap::is_empty")]
|
#[serde(skip_serializing_if = "HashMap::is_empty")]
|
||||||
pub description: HashMap<String, Description>,
|
pub description: HashMap<String, Description>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Legal::is_none")]
|
||||||
pub legal: Option<Legal>,
|
pub legal: Legal,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -56,6 +56,13 @@ pub struct Legal {
|
||||||
pub license: Option<String>,
|
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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Maintenance {
|
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 {
|
Self {
|
||||||
publiccode_yml_version: PUBLIC_CODE_VERSION.into(),
|
publiccode_yml_version: PUBLIC_CODE_VERSION.into(),
|
||||||
|
|
Loading…
Reference in a new issue