Skip to content

Commit

Permalink
fix(components): allow unset component categories in registry manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
krypt0nn committed Jan 2, 2025
1 parent dd07ec8 commit 01d7017
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/components/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,48 @@ impl AsJson for Manifest {
.and_then(LocalizableString::from_json)?,

translation_components: components.get("translation")
.ok_or_else(|| AsJsonError::FieldNotFound("components.translation"))?
.as_array()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.translation"))?
.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.translation[]"))?,
.and_then(Json::as_array)
.map(|translation| {
translation.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.translation[]"))
})
.transpose()?
.unwrap_or_default(),

virtualisation_components: components.get("virtualisation")
.ok_or_else(|| AsJsonError::FieldNotFound("components.virtualisation"))?
.as_array()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.virtualisation"))?
.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.virtualisation[]"))?,
.and_then(Json::as_array)
.map(|virtualisation| {
virtualisation.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.virtualisation[]"))
})
.transpose()?
.unwrap_or_default(),

runtime_components: components.get("runtime")
.ok_or_else(|| AsJsonError::FieldNotFound("components.runtime"))?
.as_array()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.runtime"))?
.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.runtime[]"))?,
.and_then(Json::as_array)
.map(|runtime| {
runtime.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.runtime[]"))
})
.transpose()?
.unwrap_or_default(),

general_components: components.get("general")
.ok_or_else(|| AsJsonError::FieldNotFound("components.general"))?
.as_array()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.general"))?
.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.general[]"))?
.and_then(Json::as_array)
.map(|general| {
general.iter()
.map(|url| url.as_str().map(String::from))
.collect::<Option<Vec<String>>>()
.ok_or_else(|| AsJsonError::InvalidFieldValue("components.general[]"))
})
.transpose()?
.unwrap_or_default()
})
}
}
Expand Down

0 comments on commit 01d7017

Please sign in to comment.