From 41fcc3c88ca7fa4d57caadaffcad9c389f40406a Mon Sep 17 00:00:00 2001 From: Alexander Korolev Date: Thu, 1 Aug 2024 14:50:11 +0200 Subject: [PATCH] enum members serialized with SCREAMING_SNAKE_CASE (#127) --- examples/openapi.rs | 6 +++--- src/types.rs | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/openapi.rs b/examples/openapi.rs index ce2278a..e332968 100644 --- a/examples/openapi.rs +++ b/examples/openapi.rs @@ -882,9 +882,9 @@ pub struct {name} {{ fn to_rust_type_definition(&self, name: &str) -> String { match self { StringSchema::Enum(variants) => { - let is_uppercase = variants + let is_uppercase = !variants .iter() - .all(|variant| variant.chars().all(|c| c.is_uppercase())); + .any(|variant| variant.chars().any(|c| c.is_lowercase())); format!( r##"#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))]{} @@ -893,7 +893,7 @@ pub enum {name} {{ }} "##, if is_uppercase { - "\n#[serde(rename_all = \"UPPERCASE\")]" + "\n#[serde(rename_all = \"SCREAMING_SNAKE_CASE\")]" } else { "" }, diff --git a/src/types.rs b/src/types.rs index 3b545ab..9e6aa9f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -635,7 +635,7 @@ pub struct CredentialRepresentation { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum DecisionEffect { Permit, Deny, @@ -643,7 +643,7 @@ pub enum DecisionEffect { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum DecisionStrategy { Affirmative, Unanimous, @@ -652,7 +652,7 @@ pub enum DecisionStrategy { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum EnforcementMode { Permissive, Enforcing, @@ -876,7 +876,7 @@ pub struct KeyStoreConfig { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum KeyUse { Sig, Enc, @@ -892,7 +892,7 @@ pub struct KeysMetadataRepresentation { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum Logic { Positive, Negative, @@ -1059,7 +1059,7 @@ pub struct Permission { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PolicyEnforcementMode { Enforcing, Permissive, @@ -1495,7 +1495,7 @@ pub struct RolesRepresentation { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "UPPERCASE")] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum ScopeEnforcementMode { All, Any, @@ -1601,6 +1601,7 @@ pub struct UPGroup { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum UnmanagedAttributePolicy { Enabled, AdminView,