Is your feature request related to a problem? Please describe.
Currently datamodel-code-generator
has an option to parse enums as python's string literal (e.g. Literal["A", "B"]), this is great and I'm using it a lot, but the problem is if I want to pass these literal around in my code, I have to define their type once again. e.g:
MyLiterals: TypeAlias = Literal["A", "B"]
def my_func(l: MyLiterals): ...
This is in contrast with all other types and structures generated by datamodel-code-generator
. For example if had chosen to use python enums, I would have a MyLiteral
enum in the generated code and could have use it in the function's type hint.
Describe the solution you'd like
I like to have an additional option in the CLI to tell datamodel-code-generator
to create these literal definitions automatically.
Describe alternatives you've considered
Currently I just copy and paste the literals generated by datamodel-code-generator
into a separate file and re-define them, which can be a little non-DRY.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too