radicle/web: Relax deserialization of `Config`

Allow omission of `pinned` and its members.
This commit is contained in:
Lorenz Leutgeb 2026-05-06 23:37:38 +02:00 committed by Fintan Halpenny
parent 53db994146
commit ee9a9de36d
3 changed files with 29 additions and 22 deletions

View File

@ -8,11 +8,6 @@ $ rad config
"preferredSeeds": [ "preferredSeeds": [
"z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@iris.radicle.network:8776" "z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@iris.radicle.network:8776"
], ],
"web": {
"pinned": {
"repositories": []
}
},
"cli": { "cli": {
"hints": true "hints": true
}, },
@ -83,12 +78,7 @@ $ rad config schema
}, },
"web": { "web": {
"description": "Web configuration.", "description": "Web configuration.",
"$ref": "#/$defs/WebConfig", "$ref": "#/$defs/WebConfig"
"default": {
"pinned": {
"repositories": []
}
}
}, },
"cli": { "cli": {
"description": "CLI configuration.", "description": "CLI configuration.",
@ -154,10 +144,7 @@ $ rad config schema
], ],
"format": "uri" "format": "uri"
} }
}, }
"required": [
"pinned"
]
}, },
"Pinned": { "Pinned": {
"description": "Pinned content. This can be used to pin certain content when/nlisting, e.g. pin repositories on a web client.", "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" "$ref": "#/$defs/RepoId"
} }
} }
}, }
"required": [
"repositories"
]
}, },
"RepoId": { "RepoId": {
"description": "A repository identifier.", "description": "A repository identifier.",

View File

@ -141,7 +141,7 @@ pub struct Config {
#[serde(default)] #[serde(default)]
pub preferred_seeds: Vec<node::config::ConnectAddress>, pub preferred_seeds: Vec<node::config::ConnectAddress>,
/// Web configuration. /// Web configuration.
#[serde(default)] #[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
pub web: web::Config, pub web: web::Config,
/// CLI configuration. /// CLI configuration.
#[serde(default)] #[serde(default)]

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::prelude::RepoId; use crate::prelude::RepoId;
/// Web configuration. /// Web configuration.
#[derive(Clone, Debug, Default, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[cfg_attr( #[cfg_attr(
feature = "schemars", feature = "schemars",
@ -13,6 +13,7 @@ use crate::prelude::RepoId;
)] )]
pub struct Config { pub struct Config {
/// Pinned content. /// Pinned content.
#[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
pub pinned: Pinned, pub pinned: Pinned,
/// URL pointing to an image used in the header of a node page. /// URL pointing to an image used in the header of a node page.
#[serde(default, skip_serializing_if = "Option::is_none")] #[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 /// Pinned content. This can be used to pin certain content when
/// listing, e.g. pin repositories on a web client. /// 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")] #[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Pinned { pub struct Pinned {
/// Pinned repositories. /// Pinned repositories.
#[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
#[cfg_attr( #[cfg_attr(
feature = "schemars", feature = "schemars",
schemars(with = "std::collections::HashSet<RepoId>") schemars(with = "std::collections::HashSet<RepoId>")
)] )]
pub repositories: IndexSet<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();
}
}