Repository: marcosschroh/dataclasses-avroschema

Issue:
When creating avro schema in camel case, nested class fields are not getting converted to proper camel case.
**Describe the bug**
A clear and concise description of what the bug is.

I am trying to use the <ClassName>.avro_schema(case_type=case.CAMELCASE) to generate my schema in camelcase. But the function was not able to convert nested structures into Camel case.

**To Reproduce**
```
from dataclasses_avroschema.pydantic import AvroBaseModel
from dataclasses_avroschema import case

class Cat(AvroBaseModel):
    name: str
    created_by: str

class Fish(AvroBaseModel):
    name: str
    fins_count: int

class Animal(AvroBaseModel):
    tiger_animal: Cat | None = None
    whale_fish: Fish | None = None
    lion_animal : Cat | None = None


if __name__ =='__main__':
    print(Animal.avro_schema(case_type=case.CAMELCASE))
```

Steps to reproduce the behavior

**Expected behavior**

For the above code the result produced was 


`{"type": "record", "name": "Animal", "fields": [{"name": "tigerAnimal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created_by", "type": "string"}]}], "default": null}, {"name": "whaleFish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins_count", "type": "long"}]}], "default": null}, {"name": "lionAnimal", "type": ["null", "Cat"], "default": null}]} 
`


A clear and concise description of what you expected to happen.

The actual result should be where the fields created_by and fins_count should also be converted into `createdBy` and `finsCount`.



Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/723?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.48%. Comparing base [(`6541274`)](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/commit/6541274beed1c77426ce21fd538a29b23bfd7e87?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) to head [(`5567841`)](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/commit/5567841b8df7341194a24c519a2aba78d2b68540?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #723   +/-   ##
=======================================
  Coverage   99.48%   99.48%           
=======================================
  Files          34       34           
  Lines        1943     1945    +2     
=======================================
+ Hits         1933     1935    +2     
  Misses         10       10           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/723?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).


Patch:
diff --git a/dataclasses_avroschema/case.py b/dataclasses_avroschema/case.py
index 8c99ea3..02632e6 100644
--- a/dataclasses_avroschema/case.py
+++ b/dataclasses_avroschema/case.py
@@ -58,6 +58,10 @@ def case_item(item: typing.Dict, case_type: str) -> typing.Dict:
             # means that it is a complex type with a record
             new_record = case_record(value, case_type=case_type)
             new_field[key] = new_record
+        elif isinstance(value, list):
+            new_field[key] = [
+                case_record(element, case_type=case_type) if isinstance(element, dict) else element for element in value
+            ]
         else:
             new_field[key] = value
 


Test patch:
diff --git a/tests/case/test_case_records.py b/tests/case/test_case_records.py
index 3886373..f5e5115 100644
--- a/tests/case/test_case_records.py
+++ b/tests/case/test_case_records.py
@@ -227,6 +227,58 @@ CASE_TO_DATA_COMPLEX_FIELDS_NESTED = [
 ]
 
 
+CASE_TO_DATA_WITH_UNION = [
+    (
+        case.CAMELCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tigerAnimal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "createdBy", "type": "string"}]}], "default": null}, {"name": "whaleFish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "finsCount", "type": "long"}]}], "default": null}, {"name": "lionAnimal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.CAPITALCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "Tiger_animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "Name", "type": "string"}, {"name": "Created_by", "type": "string"}]}], "default": null}, {"name": "Whale_fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "Name", "type": "string"}, {"name": "Fins_count", "type": "long"}]}], "default": null}, {"name": "Lion_animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.CONSTCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "TIGER_ANIMAL", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "NAME", "type": "string"}, {"name": "CREATED_BY", "type": "string"}]}], "default": null}, {"name": "WHALE_FISH", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "NAME", "type": "string"}, {"name": "FINS_COUNT", "type": "long"}]}], "default": null}, {"name": "LION_ANIMAL", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.LOWERCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tiger_animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created_by", "type": "string"}]}], "default": null}, {"name": "whale_fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins_count", "type": "long"}]}], "default": null}, {"name": "lion_animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.PASCALCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "TigerAnimal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "Name", "type": "string"}, {"name": "CreatedBy", "type": "string"}]}], "default": null}, {"name": "WhaleFish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "Name", "type": "string"}, {"name": "FinsCount", "type": "long"}]}], "default": null}, {"name": "LionAnimal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.PATHCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tiger/animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created/by", "type": "string"}]}], "default": null}, {"name": "whale/fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins/count", "type": "long"}]}], "default": null}, {"name": "lion/animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.SNAKECASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tiger_animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created_by", "type": "string"}]}], "default": null}, {"name": "whale_fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins_count", "type": "long"}]}], "default": null}, {"name": "lion_animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.SPINALCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tiger-animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created-by", "type": "string"}]}], "default": null}, {"name": "whale-fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins-count", "type": "long"}]}], "default": null}, {"name": "lion-animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.UPPERSPINALCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "TIGER-ANIMAL", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "NAME", "type": "string"}, {"name": "CREATED-BY", "type": "string"}]}], "default": null}, {"name": "WHALE-FISH", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "NAME", "type": "string"}, {"name": "FINS-COUNT", "type": "long"}]}], "default": null}, {"name": "LION-ANIMAL", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.TRIMCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tiger_animal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "created_by", "type": "string"}]}], "default": null}, {"name": "whale_fish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "fins_count", "type": "long"}]}], "default": null}, {"name": "lion_animal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.UPPERCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "TIGER_ANIMAL", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "NAME", "type": "string"}, {"name": "CREATED_BY", "type": "string"}]}], "default": null}, {"name": "WHALE_FISH", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "NAME", "type": "string"}, {"name": "FINS_COUNT", "type": "long"}]}], "default": null}, {"name": "LION_ANIMAL", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+    (
+        case.ALPHANUMCASE,
+        '{"type": "record", "name": "Animal", "fields": [{"name": "tigeranimal", "type": ["null", {"type": "record", "name": "Cat", "fields": [{"name": "name", "type": "string"}, {"name": "createdby", "type": "string"}]}], "default": null}, {"name": "whalefish", "type": ["null", {"type": "record", "name": "Fish", "fields": [{"name": "name", "type": "string"}, {"name": "finscount", "type": "long"}]}], "default": null}, {"name": "lionanimal", "type": ["null", "Cat"], "default": null}]}',  # noqa
+    ),
+]
+
+
 @pytest.mark.parametrize("case_type, schema", CASE_TO_DATA)
 def test_case_record(case_type, schema):
     class Event(AvroModel):
@@ -301,3 +353,31 @@ def test_case_complex_fields_nested(case_type, schema):
 
     assert schema == UserAdvance.avro_schema(case_type=case_type)
     assert json.loads(schema) == UserAdvance.avro_schema_to_python(case_type=case_type)
+
+
+@pytest.mark.parametrize("case_type, schema", CASE_TO_DATA_WITH_UNION)
+def test_case_with_union(case_type, schema):
+    class Cat(AvroModel):
+        name: str
+        created_by: str
+
+        class Meta:
+            schema_doc = False
+
+    class Fish(AvroModel):
+        name: str
+        fins_count: int
+
+        class Meta:
+            schema_doc = False
+
+    class Animal(AvroModel):
+        tiger_animal: typing.Optional[Cat] = None
+        whale_fish: typing.Optional[Fish] = None
+        lion_animal: typing.Optional[Cat] = None
+
+        class Meta:
+            schema_doc = False
+
+    assert schema == Animal.avro_schema(case_type=case_type)
+    assert json.loads(schema) == Animal.avro_schema_to_python(case_type=case_type)