Repository: GREsau/schemars (rust)

Issue:
enums: serde rename_all_fields not respected
## Description

When using [serde's rename_all_fields](https://serde.rs/container-attrs.html#rename_all_fields) on an enum together with schemars, the fields are not properly renamed in the schema.
Only explicitly renaming each and every field renames them.

## How to reproduce

```rust
use schemars::{schema_for, JsonSchema};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, PartialEq)]
#[serde(tag = "Variant")]
#[serde(rename_all = "lowercase")]
#[serde(rename_all_fields = "PascalCase")]
pub enum Example {
    First {
        nested_attribute: String,
    },
    Second {
        #[serde(rename = "AnotherAttribute")]
        another_attribute: String,
    },
}

fn main() {
    let schema = schema_for!(Example);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
    let example1 = Example::First { nested_attribute: "foo".to_owned()};
    println!("{}", serde_json::to_string_pretty(&example1).unwrap());
    let example2 = Example::Second { another_attribute: "foo".to_owned()};
    println!("{}", serde_json::to_string_pretty(&example2).unwrap());
}
```

**Output**:

❗ comments are mine

```
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Example",
  "oneOf": [
    {
      "type": "object",
      "required": [
        "Variant",
❗       "nested_attribute"  👈 snake_case, in spite of `rename_all_fields = "PascalCase"`
      ],
      "properties": {
        "Variant": {
          "type": "string",
          "enum": [
            "first"
          ]
        },
        "nested_attribute": {
          "type": "string"
        }
      }
    },
    {
      "type": "object",
      "required": [
❗       "AnotherAttribute", 👈 PascalCase!
        "Variant"
      ],
      "properties": {
        "AnotherAttribute": {
          "type": "string"
        },
        "Variant": {
          "type": "string",
          "enum": [
            "second"
          ]
        }
      }
    }
  ]
}
❗👇 json serialization output is the same in terms of capitalization 
{
  "Variant": "first",
  "NestedAttribute": "foo"
}
{
  "Variant": "second",
  "AnotherAttribute": "foo"
}
```

Pull request:
fix: honor rename_all_fields, add tests
closes #273

Patch:
diff --git a/schemars_derive/src/attr/schemars_to_serde.rs b/schemars_derive/src/attr/schemars_to_serde.rs
index 80bcaf0..0ae213f 100644
--- a/schemars_derive/src/attr/schemars_to_serde.rs
+++ b/schemars_derive/src/attr/schemars_to_serde.rs
@@ -10,6 +10,7 @@ use super::get_meta_items;
 pub(crate) static SERDE_KEYWORDS: &[&str] = &[
     "rename",
     "rename_all",
+    "rename_all_fields",
     "deny_unknown_fields",
     "tag",
     "content",


Test patch:
diff --git a/schemars/tests/enum.rs b/schemars/tests/enum.rs
index 4c57f34..45698a7 100644
--- a/schemars/tests/enum.rs
+++ b/schemars/tests/enum.rs
@@ -146,3 +146,40 @@ enum NoVariants {}
 fn enum_no_variants() -> TestResult {
     test_default_generated_schema::<NoVariants>("no-variants")
 }
+
+#[derive(JsonSchema)]
+#[serde(rename_all_fields = "PascalCase")]
+pub enum RenameAllFields {
+    First {
+        nested_attribute: std::string::String,
+    },
+}
+
+#[derive(JsonSchema)]
+#[serde(rename_all = "snake_case")]
+pub enum RenameAll {
+    First { nested_attribute: bool },
+}
+
+#[derive(JsonSchema)]
+pub enum RenameAttribute {
+    First {
+        #[serde(rename = "RenamedAttribute")]
+        nested_attribute: std::string::String,
+    },
+}
+
+#[test]
+fn enum_unit_rename_attribute() -> TestResult {
+    test_default_generated_schema::<RenameAttribute>("enum-rename-attr")
+}
+
+#[test]
+fn enum_unit_rename_all_fields() -> TestResult {
+    test_default_generated_schema::<RenameAllFields>("enum-rename-all-fields")
+}
+
+#[test]
+fn enum_unit_rename_all() -> TestResult {
+    test_default_generated_schema::<RenameAll>("enum-rename-all")
+}
diff --git a/schemars/tests/expected/enum-rename-all-fields.json b/schemars/tests/expected/enum-rename-all-fields.json
new file mode 100644
index 0000000..422a694
--- /dev/null
+++ b/schemars/tests/expected/enum-rename-all-fields.json
@@ -0,0 +1,26 @@
+{
+  "$schema": "https://json-schema.org/draft/2020-12/schema",
+  "title": "RenameAllFields",
+  "oneOf": [
+    {
+      "type": "object",
+      "properties": {
+        "First": {
+          "type": "object",
+          "properties": {
+            "NestedAttribute": {
+              "type": "string"
+            }
+          },
+          "required": [
+            "NestedAttribute"
+          ]
+        }
+      },
+      "required": [
+        "First"
+      ],
+      "additionalProperties": false
+    }
+  ]
+}
\ No newline at end of file
diff --git a/schemars/tests/expected/enum-rename-all.json b/schemars/tests/expected/enum-rename-all.json
new file mode 100644
index 0000000..eb237be
--- /dev/null
+++ b/schemars/tests/expected/enum-rename-all.json
@@ -0,0 +1,26 @@
+{
+  "$schema": "https://json-schema.org/draft/2020-12/schema",
+  "title": "RenameAll",
+  "oneOf": [
+    {
+      "type": "object",
+      "properties": {
+        "first": {
+          "type": "object",
+          "properties": {
+            "nested_attribute": {
+              "type": "boolean"
+            }
+          },
+          "required": [
+            "nested_attribute"
+          ]
+        }
+      },
+      "required": [
+        "first"
+      ],
+      "additionalProperties": false
+    }
+  ]
+}
\ No newline at end of file
diff --git a/schemars/tests/expected/enum-rename-attr.json b/schemars/tests/expected/enum-rename-attr.json
new file mode 100644
index 0000000..a9f3706
--- /dev/null
+++ b/schemars/tests/expected/enum-rename-attr.json
@@ -0,0 +1,26 @@
+{
+  "$schema": "https://json-schema.org/draft/2020-12/schema",
+  "title": "RenameAttribute",
+  "oneOf": [
+    {
+      "type": "object",
+      "properties": {
+        "First": {
+          "type": "object",
+          "properties": {
+            "RenamedAttribute": {
+              "type": "string"
+            }
+          },
+          "required": [
+            "RenamedAttribute"
+          ]
+        }
+      },
+      "required": [
+        "First"
+      ],
+      "additionalProperties": false
+    }
+  ]
+}
\ No newline at end of file