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

Name of Enum type should be in PascalCase #221

Closed
linuxidefix opened this issue Dec 10, 2022 · 1 comment · Fixed by #231
Closed

Name of Enum type should be in PascalCase #221

linuxidefix opened this issue Dec 10, 2022 · 1 comment · Fixed by #231
Assignees

Comments

@linuxidefix
Copy link

Describe the bug

Sometimes we use avro schemas with different sources (some written in Scala, some in Python, etc). With the case you can generate your schemas according to your programming language convention.
But in Java or Scala, the names of fields are in camelCase and types like Class/Enum are in PascalCase

Enum type's name, like Record name should be always in PascalCase ( I think this is the standard case in Python too )

So today in our case when converting avro to java, generator will not generate a class in PascalCase.

To Reproduce
Example from the doc: https://marcosschroh.github.io/dataclasses-avroschema/case/

import typing
import dataclasses
import enum

from dataclasses_avroschema import AvroModel, case, types


# New enum!!
class FavoriteColor(enum.Enum):
    BLUE = "BLUE"
    YELLOW = "YELLOW"
    GREEN = "GREEN"


@dataclasses.dataclass
class UserAdvance(AvroModel):
    name: str
    age: int
    pets: typing.List[str]
    accounts: typing.Dict[str, int]
    favorite_colors: FavoriteColor
    has_car: bool = False
    country: str = "Argentina"
    address: str = None
    md5: types.Fixed = types.Fixed(16)

    class Meta:
        schema_doc = False


print(UserAdvance.avro_schema(case_type=case.CAMELCASE))

{"type": "record", "name": "UserAdvance", "fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "long"}, {"name": "pets", "type": {"type": "array", "items": "string", "name": "pet"}}, {"name": "accounts", "type": {"type": "map", "values": "long", "name": "account"}}, {"name": "favoriteColors", "type": {"type": "enum", "name": "favoriteColor", "symbols": ["BLUE", "YELLOW", "GREEN"]}}, {"name": "hasCar", "type": "boolean", "default": false}, {"name": "country", "type": "string", "default": "Argentina"}, {"name": "address", "type": ["null", "string"], "default": null}, {"name": "md5", "type": {"type": "fixed", "name": "md5", "size": 16}}]}

Expected behavior

I would expect that name of the type Enum should be "type": "enum", "name": "FavoriteColor", like the RecordName on which case rules do no apply.

Maybe there is a trick to do that, but I did not find it in the documentation

@marcosschroh
Copy link
Owner

Hi,

It makes sense. I will work on it.

@marcosschroh marcosschroh self-assigned this Dec 16, 2022
marcosschroh pushed a commit that referenced this issue Jan 6, 2023
marcosschroh pushed a commit that referenced this issue Jan 6, 2023
marcosschroh added a commit that referenced this issue Jan 6, 2023
…ases should not apply to enum names. Closes #221 (#231)

Co-authored-by: Marcos Schroh <marcos.schroh@kpn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants