Skip to content

Commit

Permalink
enum members serialized with SCREAMING_SNAKE_CASE (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork authored Aug 1, 2024
1 parent 35d0f71 commit 41fcc3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]{}
Expand All @@ -893,7 +893,7 @@ pub enum {name} {{
}}
"##,
if is_uppercase {
"\n#[serde(rename_all = \"UPPERCASE\")]"
"\n#[serde(rename_all = \"SCREAMING_SNAKE_CASE\")]"
} else {
""
},
Expand Down
15 changes: 8 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,15 @@ 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,
}

#[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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 41fcc3c

Please sign in to comment.