Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum members serialized with SCREAMING_SNAKE_CASE #127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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