Repository: marcosschroh/dataclasses-avroschema

Issue:
Issue with case sensitivity in enums
**Describe the bug**
python Fields that represent enums values are translated directly to UPPERCASE regardless of their original casing.
This results in duplicate fields if original values from the schema only differ in casing.

I encounted this is issue in our from standards derived avro models that use SI units that have quite some cases where this is an issue like M(ega) vs m(illi), M(onth) vs m(inute) etc.

```
{
  "name": "UnitMultiplier",
  "type": "enum",
  "symbols": [
    "p",
    "P",
     ....
  ]
}
```
results in
```
class UnitMultiplier(enum.Enum):
    P = "p"
    P = "P"
    ... 
```

Perhaps rename the non-original uppercase P field to 'P_' or something when duplicates are found.

**To Reproduce**
See above

**Expected behavior**
Support for case-sensitive uniqueness such that any valid avro schema results in a valid generated python model.


Discussion:
github-actions[bot]: [PR Preview Action](https://github.com/rossjrw/pr-preview-action) v1.4.4
:---:
:rocket: Deployed preview to https://marcosschroh.github.io/dataclasses-avroschema/pr-preview/pr-402/
on branch [`gh-pages`](https://github.com/marcosschroh/dataclasses-avroschema/tree/gh-pages) at 2023-08-30 13:22 UTC
<!-- Sticky Pull Request Commentpr-preview -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/402?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) Report
> Merging [#402](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/402?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) (311f398) into [master](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/commit/d1e856e0a7c6c610741f54061f17df2aa8d9180e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) (d1e856e) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master     #402   +/-   ##
=======================================
  Coverage   99.26%   99.26%           
=======================================
  Files          20       20           
  Lines        1491     1497    +6     
  Branches      272      274    +2     
=======================================
+ Hits         1480     1486    +6     
  Misses          3        3           
  Partials        8        8           
```


| [Files Changed](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) | Coverage Δ | |
|---|---|---|
| [...ataclasses\_avroschema/model\_generator/generator.py](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh#diff-ZGF0YWNsYXNzZXNfYXZyb3NjaGVtYS9tb2RlbF9nZW5lcmF0b3IvZ2VuZXJhdG9yLnB5) | `99.31% <100.00%> (+0.01%)` | :arrow_up: |



Patch:
diff --git a/dataclasses_avroschema/model_generator/generator.py b/dataclasses_avroschema/model_generator/generator.py
index 57290e3..acce0e1 100644
--- a/dataclasses_avroschema/model_generator/generator.py
+++ b/dataclasses_avroschema/model_generator/generator.py
@@ -424,10 +424,18 @@ class ModelGenerator:
 
         field_name: str = field["name"]
         enum_name = casefy.pascalcase(field_name)
+
+        symbols_map = {}
+        for symbol in field["symbols"]:
+            key = casefy.uppercase(symbol)
+            if key in symbols_map:
+                key = symbol
+            symbols_map[key] = symbol
+
         symbols = self.field_identation.join(
             [
-                templates.enum_symbol_template.safe_substitute(key=casefy.uppercase(symbol), value=f'"{symbol}"')
-                for symbol in field["symbols"]
+                templates.enum_symbol_template.safe_substitute(key=key, value=f'"{value}"')
+                for key, value in symbols_map.items()
             ]
         )
         docstring = self.render_docstring(docstring=field.get("doc"))
diff --git a/docs/model_generator.md b/docs/model_generator.md
index 5b2975c..351e554 100644
--- a/docs/model_generator.md
+++ b/docs/model_generator.md
@@ -411,3 +411,58 @@ class User(AvroModel):
     class Meta:
         field_order = ['has_pets', 'name', 'age', 'money']
 ```
+
+## Enums and case sensitivity
+
+Sometimes there are schemas that contains the `symbols` which are case sensivity, for example `"symbols": ["P", "p"]`.
+Having something like that is NOT reccomended at all because it is meaninless, really hard to undestand the intention of it. Avoid it!!!
+
+When the schema generator encounter this situation it can not generated the proper `enum` with `uppercases` key so it will use the `symbol` without any transformation
+
+```python
+from dataclasses_avroschema import ModelGenerator
+
+schema = {
+    "type": "record",
+    "name": "User",
+    "fields": [
+        {
+            "name": "unit_multi_player",
+            "type": {
+                "type": "enum",
+                "name": "unit_multi_player",
+                "symbols": ["Q", "q"],
+            },
+        }
+    ],
+}
+
+model_generator = ModelGenerator()
+result = model_generator.render(schema=schema)
+
+# save the result in a file
+with open("models.py", mode="+w") as f:
+    f.write(result)
+```
+
+Then the result will be:
+
+```python
+# models.py
+from dataclasses_avroschema import AvroModel
+import dataclasses
+import enum
+
+
+class UnitMultiPlayer(enum.Enum):
+    Q = "Q"
+    q = "q"
+
+
+@dataclasses.dataclass
+class User(AvroModel):
+    unit_multi_player: UnitMultiPlayer
+
+```
+
+As the example shows the second enum member `UnitMultiPlayer.p` is not in uppercase otherwise will collide with the first member `UnitMultiPlayer.P`


Test patch:
diff --git a/tests/model_generator/conftest.py b/tests/model_generator/conftest.py
index bec01d9..58873a6 100644
--- a/tests/model_generator/conftest.py
+++ b/tests/model_generator/conftest.py
@@ -212,6 +212,24 @@ def schema_with_enum_types() -> Dict:
     }
 
 
+@pytest.fixture
+def schema_with_enum_types_case_sensitivity() -> Dict:
+    return {
+        "type": "record",
+        "name": "User",
+        "fields": [
+            {
+                "name": "unit_multi_player",
+                "type": {
+                    "type": "enum",
+                    "name": "unit_multi_player",
+                    "symbols": ["Q", "q"],
+                },
+            }
+        ],
+    }
+
+
 @pytest.fixture
 def schema_one_to_one_relationship() -> JsonDict:
     return {
diff --git a/tests/model_generator/test_model_generator.py b/tests/model_generator/test_model_generator.py
index a3d3e6d..a0a9279 100644
--- a/tests/model_generator/test_model_generator.py
+++ b/tests/model_generator/test_model_generator.py
@@ -204,6 +204,28 @@ class User(AvroModel):
     assert result.strip() == expected_result.strip()
 
 
+def test_schema_with_enum_types_case_sensitivity(schema_with_enum_types_case_sensitivity: types.JsonDict) -> None:
+    expected_result = """
+from dataclasses_avroschema import AvroModel
+import dataclasses
+import enum
+
+
+class UnitMultiPlayer(enum.Enum):
+    Q = "Q"
+    q = "q"
+
+
+@dataclasses.dataclass
+class User(AvroModel):
+    unit_multi_player: UnitMultiPlayer
+
+"""
+    model_generator = ModelGenerator()
+    result = model_generator.render(schema=schema_with_enum_types_case_sensitivity)
+    assert result.strip() == expected_result.strip()
+
+
 def test_schema_one_to_one_relationship(schema_one_to_one_relationship: types.JsonDict) -> None:
     expected_result = """
 from dataclasses_avroschema import AvroModel