radicle: allow for unknown fields in Project deserialization

Allow unknown fields to pass through when deserializing the `Project` payload.
This allows the deserialization to be more resilient when unknown fields are
added, e.g. from the CLI, and improves backwards-compatability when new fields
may be added in the future.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-05-06 13:09:52 +01:00 committed by cloudhead
parent 43b0b2b426
commit 9b719d0cca
No known key found for this signature in database
1 changed files with 4 additions and 0 deletions

View File

@ -47,6 +47,9 @@ impl<'de> Deserialize<'de> for Project {
Name, Name,
Description, Description,
DefaultBranch, DefaultBranch,
/// A catch-all variant to allow for unknown fields
#[allow(dead_code)]
Unknown(String),
} }
struct ProjectVisitor; struct ProjectVisitor;
@ -86,6 +89,7 @@ impl<'de> Deserialize<'de> for Project {
} }
default_branch = Some(map.next_value()?); default_branch = Some(map.next_value()?);
} }
Field::Unknown(_) => continue,
} }
} }
let name = name.ok_or_else(|| de::Error::missing_field("name"))?; let name = name.ok_or_else(|| de::Error::missing_field("name"))?;