Skip to content

Commit 3491347

Browse files
committed
fix: allow numeric keys in Auspice coloring scale
The Auspice v2 JSON schema specifies that scale entries are two-element arrays where the first item can be either string (categorical) or numeric (continuous).¹ The previous type did not allow numeric keys and would fail to deserialize Auspice JSONs with continuous colorings. ¹ https://nextstrain.org/schemas/auspice/config/v2#/properties/colorings/items/properties/scale
1 parent ed665e1 commit 3491347

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/nextclade/src/tree/tree.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ impl AuspiceMetaExtensions {
608608
}
609609
}
610610

611+
#[derive(Clone, Debug, Serialize, Deserialize, schemars::JsonSchema)]
612+
#[serde(untagged)]
613+
pub enum ScaleKey {
614+
Num(f64),
615+
Str(String),
616+
}
617+
611618
#[derive(Clone, Debug, Default, Serialize, Deserialize, schemars::JsonSchema, Validate)]
612619
pub struct AuspiceColoring {
613620
#[serde(rename = "type")]
@@ -619,7 +626,7 @@ pub struct AuspiceColoring {
619626

620627
#[serde(skip_serializing_if = "Vec::is_empty")]
621628
#[serde(default)]
622-
pub scale: Vec<[String; 2]>,
629+
pub scale: Vec<(ScaleKey, String)>,
623630

624631
#[serde(flatten)]
625632
pub other: serde_json::Value,

0 commit comments

Comments
 (0)