-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Convert homogeneously typed Literals into ENUMs #596
Comments
It makes sense that |
II have added a new option called convert_literal_to_enum to convert Literal strings to avro enum. |
Great! I'll give it a try and let you know. |
Is your feature request related to a problem? Please describe.
I am translating a large corpus of Avro schemas into Pydantic V2 models and our convention is to encode simple string enums as Literal types in those models. Currently, the
dataclasses-avroschema
translates homogeneously typed Literals into a field of that type.e.g.
yields this schema:
Describe the solution you'd like
The current behavior is backward compatible, since it widens the range of valid values. But it also means that the constraint on values is lost for other users of these schemas unless using them mediated via our Pydantic models. It would be great if we could add an config value or annotation that changes this behavior locally or globally to generate Avro ENUMs for such Literals.
Describe alternatives you've considered
We could, in theory, switch from using
Literal
to usingStrEnum
, but would require updating a huge amount of related code to do so. Our data governance team would probably recommend switching to another Avro/Pydantic mapping library instead.The text was updated successfully, but these errors were encountered: