From df9fc6905fedd3cb2f3dfdbc6242a6aae5ddabd0 Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Tue, 11 Jan 2022 11:52:59 -0500 Subject: [PATCH] Serialize DataSourceType as plain string --- Cargo.lock | 1 + proxy_types/Cargo.toml | 3 +++ proxy_types/src/lib.rs | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index fe56f11..b524fc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1221,6 +1221,7 @@ dependencies = [ "rmp-serde 0.15.5", "serde", "serde_bytes", + "serde_json", "thiserror", "uuid", ] diff --git a/proxy_types/Cargo.toml b/proxy_types/Cargo.toml index a45dbb2..5418cf1 100644 --- a/proxy_types/Cargo.toml +++ b/proxy_types/Cargo.toml @@ -10,3 +10,6 @@ serde = { version = "1.0", features = ["derive"] } serde_bytes = "0.11.5" thiserror = "1.0.30" uuid = { version = "0.8.2", features = ["serde", "v4"] } + +[dev-dependencies] +serde_json = "1.0.74" diff --git a/proxy_types/src/lib.rs b/proxy_types/src/lib.rs index 2215e16..899c5b8 100644 --- a/proxy_types/src/lib.rs +++ b/proxy_types/src/lib.rs @@ -95,7 +95,7 @@ impl RelayMessage { } #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] -#[serde(tag = "type", rename_all = "camelCase")] +#[serde(rename_all = "camelCase")] pub enum DataSourceType { Prometheus, } @@ -125,3 +125,10 @@ impl FromStr for DataSourceType { /// This is a map from the data source name to the data source's type pub type SetDataSourcesMessage = HashMap; + +#[test] +fn data_source_type_should_serialize_to_plain_string() { + let ty = DataSourceType::Prometheus; + let serialized = serde_json::to_string(&ty).unwrap(); + assert_eq!(serialized, "\"prometheus\""); +}