marcosschroh / dataclasses-avroschema

Generate avro schemas from python classes. Code generation from avro schemas. Serialize/Deserialize python instances with avro schemas
https://marcosschroh.github.io/dataclasses-avroschema/
MIT License
213 stars 64 forks source link

When creating avro schema in camel case, nested class fields are not getting converted to proper camel case. #700

Closed harikrishnan-dev closed 3 weeks ago

harikrishnan-dev commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

I am trying to use the .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.

marcosschroh commented 1 month ago

Thanks for reporting the bug @harikrishnan-dev . I will try to fix it asap.

harikrishnan-dev commented 3 weeks ago

@marcosschroh any update on the above issue?

marcosschroh commented 3 weeks ago

Tomorrow I will start working on it

marcosschroh commented 3 weeks ago

With the new release the schema will be:

{"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}]}