Skip to content

Commit 41913ae

Browse files
committed
fix(config): Fix some config serialization issues
1 parent 16262bc commit 41913ae

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn run(opts: Opts) -> color_eyre::eyre::Result<()> {
3333

3434
// Dump configuration if this was asked
3535
if opts.dump_config {
36-
serde_json::to_writer(&mut std::io::stdout(), &config)?;
36+
serde_json::to_writer_pretty(&mut std::io::stdout(), &config)?;
3737
return Ok(());
3838
}
3939

src/models.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ fn default_false() -> bool {
3333
}
3434

3535
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Validate)]
36+
#[serde(rename_all = "camelCase")]
3637
pub struct Instance {
38+
#[serde(skip)]
3739
pub id: i32,
3840
#[serde(default = "String::new")]
3941
pub friendly_name: String,
@@ -1136,6 +1138,7 @@ pub enum MetaError {
11361138
}
11371139

11381140
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1141+
#[serde(rename_all = "camelCase")]
11391142
pub struct Meta {
11401143
pub uuid: uuid::Uuid,
11411144
pub created_at: chrono::DateTime<chrono::Utc>,
@@ -1168,6 +1171,7 @@ fn default_none<T>() -> Option<T> {
11681171
}
11691172

11701173
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1174+
#[serde(rename_all = "camelCase")]
11711175
pub struct User {
11721176
pub name: String,
11731177
#[serde(
@@ -1215,12 +1219,13 @@ impl TryFrom<db_models::DbUser> for User {
12151219
}
12161220

12171221
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Validate)]
1218-
#[serde(default)]
1222+
#[serde(default, rename_all = "camelCase")]
12191223
pub struct GlobalConfig {
12201224
pub flatbuffers_server: FlatbuffersServer,
12211225
pub forwarder: Forwarder,
12221226
pub framegrabber: Framegrabber,
12231227
pub general: General,
1228+
#[serde(rename = "grabberV4L2")]
12241229
pub grabber_v4l2: GrabberV4L2,
12251230
pub json_server: JsonServer,
12261231
pub logger: Logger,
@@ -1261,6 +1266,7 @@ struct GlobalConfigCreator {
12611266
}
12621267

12631268
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Validate)]
1269+
#[serde(rename_all = "camelCase")]
12641270
pub struct InstanceConfig {
12651271
#[validate]
12661272
pub instance: Instance,
@@ -1616,7 +1622,14 @@ impl Config {
16161622
let mut full = String::new();
16171623
file.read_to_string(&mut full).await?;
16181624

1619-
Ok(serde_json::from_str(&full)?)
1625+
let mut config: Self = serde_json::from_str(&full)?;
1626+
1627+
// Restore instance IDs from map keys
1628+
for (&k, mut v) in config.instances.iter_mut() {
1629+
v.instance.id = k;
1630+
}
1631+
1632+
Ok(config)
16201633
}
16211634

16221635
pub fn uuid(&self) -> uuid::Uuid {

0 commit comments

Comments
 (0)