From 9a2a4d307fedb0a6326b1a146699dc658e796181 Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Mon, 1 Apr 2024 13:32:35 -0400 Subject: [PATCH] docs fixes and additions --- .../src/generator/templates/common_mod.j2 | 31 ++--------------- .generator/src/generator/templates/lib.j2 | 1 + README.md | 2 +- src/datadog/mod.rs | 33 ++----------------- src/lib.rs | 1 + 5 files changed, 7 insertions(+), 61 deletions(-) diff --git a/.generator/src/generator/templates/common_mod.j2 b/.generator/src/generator/templates/common_mod.j2 index f6252df87..8eef13b39 100644 --- a/.generator/src/generator/templates/common_mod.j2 +++ b/.generator/src/generator/templates/common_mod.j2 @@ -75,38 +75,11 @@ impl From for Error { } } -pub fn urlencode>(s: T) -> String { +pub(crate) fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } -pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { - if let serde_json::Value::Object(object) = value { - let mut params = vec![]; - - for (key, value) in object { - match value { - serde_json::Value::Object(_) => params.append(&mut parse_deep_object( - &format!("{}[{}]", prefix, key), - value, - )), - serde_json::Value::Array(array) => { - for (i, value) in array.iter().enumerate() { - params.append(&mut parse_deep_object( - &format!("{}[{}][{}]", prefix, key, i), - value, - )); - } - }, - serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), - _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), - } - } - return params; - } - unimplemented!("Only objects are supported with style=deepObject") -} - -pub struct DDFormatter; +pub(crate) struct DDFormatter; impl serde_json::ser::Formatter for DDFormatter { fn write_f64(&mut self, writer: &mut W, value: f64) -> std::io::Result<()> diff --git a/.generator/src/generator/templates/lib.j2 b/.generator/src/generator/templates/lib.j2 index da4d8c5cb..21f03adee 100644 --- a/.generator/src/generator/templates/lib.j2 +++ b/.generator/src/generator/templates/lib.j2 @@ -1,6 +1,7 @@ {% include "partial_header.j2" %} #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![doc = include_str!("../README.md")] pub mod datadog; pub mod datadogV1; diff --git a/README.md b/README.md index 4351d9277..7bdbf4454 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ datadog-api-client = "0" Please follow the [installation](#installation) instructions and try the following snippet to validate your Datadog API key: -```Rust +```rust use datadog_api_client::datadog::configuration::Configuration; use datadog_api_client::datadogV1::api::api_authentication::AuthenticationAPI; diff --git a/src/datadog/mod.rs b/src/datadog/mod.rs index a7a465771..d9316970a 100644 --- a/src/datadog/mod.rs +++ b/src/datadog/mod.rs @@ -77,40 +77,11 @@ impl From for Error { } } -pub fn urlencode>(s: T) -> String { +pub(crate) fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } -pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { - if let serde_json::Value::Object(object) = value { - let mut params = vec![]; - - for (key, value) in object { - match value { - serde_json::Value::Object(_) => params.append(&mut parse_deep_object( - &format!("{}[{}]", prefix, key), - value, - )), - serde_json::Value::Array(array) => { - for (i, value) in array.iter().enumerate() { - params.append(&mut parse_deep_object( - &format!("{}[{}][{}]", prefix, key, i), - value, - )); - } - } - serde_json::Value::String(s) => { - params.push((format!("{}[{}]", prefix, key), s.clone())) - } - _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), - } - } - return params; - } - unimplemented!("Only objects are supported with style=deepObject") -} - -pub struct DDFormatter; +pub(crate) struct DDFormatter; impl serde_json::ser::Formatter for DDFormatter { fn write_f64(&mut self, writer: &mut W, value: f64) -> std::io::Result<()> diff --git a/src/lib.rs b/src/lib.rs index 6906bdd5e..7ceb7d5aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ // Copyright 2019-Present Datadog, Inc. #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![doc = include_str!("../README.md")] pub mod datadog; pub mod datadogV1;