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>,
|
||||
#[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(),
|
||||
|
|
Loading…
Reference in a new issue