radicle/web: Relax deserialization of `Config`
Allow omission of `pinned` and its members.
This commit is contained in:
parent
53db994146
commit
ee9a9de36d
|
|
@ -8,11 +8,6 @@ $ rad config
|
|||
"preferredSeeds": [
|
||||
"z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@iris.radicle.network:8776"
|
||||
],
|
||||
"web": {
|
||||
"pinned": {
|
||||
"repositories": []
|
||||
}
|
||||
},
|
||||
"cli": {
|
||||
"hints": true
|
||||
},
|
||||
|
|
@ -83,12 +78,7 @@ $ rad config schema
|
|||
},
|
||||
"web": {
|
||||
"description": "Web configuration.",
|
||||
"$ref": "#/$defs/WebConfig",
|
||||
"default": {
|
||||
"pinned": {
|
||||
"repositories": []
|
||||
}
|
||||
}
|
||||
"$ref": "#/$defs/WebConfig"
|
||||
},
|
||||
"cli": {
|
||||
"description": "CLI configuration.",
|
||||
|
|
@ -154,10 +144,7 @@ $ rad config schema
|
|||
],
|
||||
"format": "uri"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"pinned"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Pinned": {
|
||||
"description": "Pinned content. This can be used to pin certain content when/nlisting, e.g. pin repositories on a web client.",
|
||||
|
|
@ -171,10 +158,7 @@ $ rad config schema
|
|||
"$ref": "#/$defs/RepoId"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"repositories"
|
||||
]
|
||||
}
|
||||
},
|
||||
"RepoId": {
|
||||
"description": "A repository identifier.",
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ pub struct Config {
|
|||
#[serde(default)]
|
||||
pub preferred_seeds: Vec<node::config::ConnectAddress>,
|
||||
/// Web configuration.
|
||||
#[serde(default)]
|
||||
#[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
|
||||
pub web: web::Config,
|
||||
/// CLI configuration.
|
||||
#[serde(default)]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::prelude::RepoId;
|
||||
|
||||
/// Web configuration.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[cfg_attr(
|
||||
feature = "schemars",
|
||||
|
|
@ -13,6 +13,7 @@ use crate::prelude::RepoId;
|
|||
)]
|
||||
pub struct Config {
|
||||
/// Pinned content.
|
||||
#[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
|
||||
pub pinned: Pinned,
|
||||
/// URL pointing to an image used in the header of a node page.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
|
|
@ -30,14 +31,36 @@ pub struct Config {
|
|||
|
||||
/// Pinned content. This can be used to pin certain content when
|
||||
/// listing, e.g. pin repositories on a web client.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub struct Pinned {
|
||||
/// Pinned repositories.
|
||||
#[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
|
||||
#[cfg_attr(
|
||||
feature = "schemars",
|
||||
schemars(with = "std::collections::HashSet<RepoId>")
|
||||
)]
|
||||
pub repositories: IndexSet<RepoId>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn description_only() {
|
||||
let value = serde_json::json!({
|
||||
"description": "A node description",
|
||||
});
|
||||
let _: Config = serde_json::from_value(value).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pinned_empty() {
|
||||
let value = serde_json::json!({
|
||||
"pinned": {},
|
||||
});
|
||||
let _: Config = serde_json::from_value(value).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue